@@ -44,23 +44,38 @@ struct Detail {
4444}
4545
4646// Autocomplete for function parameters `os.write_bytes(**path string, bytes []u8***)` etc
47- pub fn (mut c Checker) autocomplete_for_fn_call_expr () {
48- mut fn_name := if c.pref.linfo.expr. ends_with ( '(' ) {
49- c.pref.linfo.expr[..c.pref.linfo.expr.len - 1 ]. trim_space ()
50- } else {
51- c.pref.linfo.expr. replace ( '()' , '' ). trim_space ()
47+ pub fn (mut c Checker) autocomplete_for_fn_call_expr (node ast.CallExpr ) {
48+ // Make sure this ident is on the same line and same file as request
49+ same_line := c.pref.linfo.line_nr + 1 == node.pos.line_nr
50+ if ! same_line {
51+ return
5252 }
53- mod_name := fn_name.all_before_last ('.' )
54- resolved_mod_name := c.try_resolve_to_import_mod_name (mod_name)
55- if resolved_mod_name.len > 0 {
56- fn_name = resolved_mod_name + '.' + fn_name.all_after_last ('.' )
53+ if node.pos.file_idx < 0 {
54+ return
55+ }
56+ if c.pref.linfo.path != c.table.filelist[node.pos.file_idx] {
57+ return
5758 }
58- f := c.table. find_fn (fn_name) or {
59- println ( 'failed to find fn "${ fn_name }"' )
59+ col := c.pref.linfo.expr. all_after_last ( '^' ). int ()
60+ if node.name_pos.col + node.name_pos.len + 1 != col {
6061 return
6162 }
63+ fn_name := node.name
64+ f := if node.is_method {
65+ left_sym := c.table.sym (c.unwrap_generic (node.left_type))
66+ c.table.find_method (left_sym, fn_name) or {
67+ println ('failed to find method "${fn_name }"' )
68+ return
69+ }
70+ } else {
71+ c.table.find_fn (fn_name) or {
72+ println ('failed to find fn "${fn_name }"' )
73+ return
74+ }
75+ }
6276 res := c.build_fn_summary (f)
6377 println (res)
78+ exit (0 )
6479}
6580
6681fn (mut c Checker) ident_gotodef () {
@@ -139,6 +154,7 @@ fn (mut c Checker) ident_autocomplete(node ast.Ident) {
139154 mut details := []Detail{cap: 10 }
140155 c.vls_gen_type_details (mut details, sym)
141156 c.vls_write_details (details)
157+ exit (0 )
142158}
143159
144160fn (mut c Checker) module_autocomplete (mod string ) {
@@ -150,26 +166,39 @@ fn (mut c Checker) module_autocomplete(mod string) {
150166 c.vls_write_details (details)
151167}
152168
153- fn (c &Checker) build_fn_summary (method ast.Fn) string {
154- mut sb := strings.new_builder (64 )
155- sb.write_string (method.name.all_after_last ('.' ))
156- sb.write_string ('(' )
157- for i, param in method.params {
158- if method.is_method && i == 0 {
169+ fn (c &Checker) build_fn_summary (func ast.Fn) string {
170+ mut sb := strings.new_builder (128 )
171+ fn_name := func.name.all_after_last ('.' )
172+ sb.writeln ('{\n "signatures":[{' )
173+ sb.write_string ('\t "label":"${fn_name }(' )
174+ mut params := []string {cap: func.params.len}
175+ for i, param in func.params {
176+ if func.is_method && i == 0 {
159177 // skip receiver
160178 continue
161179 }
162- sb.write_string (param.name)
163- sb.write_string (' ' )
164- sb.write_string (c.table.type_to_str (param.typ))
165- if i < method.params.len - 1 {
166- sb.write_string (', ' )
167- }
180+ params << '${param .name } ${c .table .type_to_str (param .typ )}'
168181 }
182+ sb.write_string (params.join (', ' ))
169183 sb.write_string (')' )
170- if method.return_type != ast.void_type {
171- sb.write_string (c.table.type_to_str (method.return_type))
184+ if func.return_type != ast.void_type {
185+ sb.write_string (' ' )
186+ sb.write_string (c.table.type_to_str (func.return_type))
187+ }
188+ sb.writeln ('",\n\t "parameters":[{' )
189+ for i, p in params {
190+ sb.write_string ('\t\t "label":"${p }"' )
191+ if i < params.len - 1 {
192+ sb.write_string (',' )
193+ }
194+ sb.writeln ('' )
172195 }
196+ sb.writeln ('\t }]' )
197+ sb.writeln ('}],' )
198+ sb.writeln ('"activeSignature":0,' )
199+ sb.writeln ('"activeParameter":0,' )
200+ sb.writeln ('"_type":"SignatureHelp"' )
201+ sb.writeln ('}' )
173202 return sb.str ()
174203}
175204
0 commit comments