11local utils = require " tests.utils"
22local lsp_assert = require " tests.lsp_asserts"
33local mocks = require " tests.mocks"
4+ local plugin_config = require " typescript-tools.config"
45local c = require " typescript-tools.protocol.constants"
56local methods = c .LspMethods
67local custom_methods = c .CustomMethods
@@ -134,10 +135,11 @@ describe("Lsp request", function()
134135 utils .open_file " src/completion.ts"
135136 utils .wait_for_lsp_initialization ()
136137
137- local ret = vim . lsp . buf_request_sync ( 0 , methods . Completion , {
138+ local req = {
138139 textDocument = utils .get_text_document (),
139140 position = utils .make_position (0 , 8 ),
140- })
141+ }
142+ local ret = vim .lsp .buf_request_sync (0 , methods .Completion , req )
141143
142144 local result = lsp_assert .response (ret )
143145
@@ -147,36 +149,47 @@ describe("Lsp request", function()
147149 assert .is .True (# items >= 20 )
148150
149151 local completions = vim .tbl_map (function (it )
150- if it .label == " assert~ " or it .label == " warn~ " then
151- assert .are .same (it .insertTextFormat , c .InsertTextFormat .Snippet )
152+ if it .kind == c . CompletionItemKind . Method or it .kind == c . CompletionItemKind . Function then
153+ assert .are .same (it .insertTextFormat , c .InsertTextFormat .PlainText )
152154 end
153155 return it .label
154156 end , items )
155157 table.sort (completions )
156158
157- assert .are .same (completions [1 ], " assert~ " )
158- assert .are .same (completions [# completions ], " warn~ " )
159+ assert .are .same (completions [1 ], " assert" )
160+ assert .are .same (completions [# completions ], " warn" )
159161
160- ret = vim .lsp .buf_request_sync (0 , methods .Completion , {
161- textDocument = utils .get_text_document (),
162- position = utils .make_position (0 , 6 ),
163- })
162+ -- same test as above but with function snippets enabled
163+ local prev_config =
164+ plugin_config .vscode_configuration [" typescript.suggest.completeFunctionCalls" ]
165+ plugin_config .vscode_configuration [" typescript.suggest.completeFunctionCalls" ] = true
166+
167+ ret = vim .lsp .buf_request_sync (0 , methods .Completion , req )
164168 result = lsp_assert .response (ret )
165- local can_complete_as_console = false
166- for _ , item in ipairs (result .items ) do
167- if item .label == " console" then
168- assert .are .same (item .insertTextFormat , c .InsertTextFormat .PlainText )
169- can_complete_as_console = true
169+ assert .is .table (result .items )
170+
171+ items = result .items
172+ assert .is .True (# items >= 20 )
173+
174+ completions = vim .tbl_map (function (it )
175+ if it .kind == c .CompletionItemKind .Method or it .kind == c .CompletionItemKind .Function then
176+ assert .are .same (it .insertTextFormat , c .InsertTextFormat .Snippet )
170177 end
171- end
172- assert (can_complete_as_console )
178+ return it .label
179+ end , items )
180+ table.sort (completions )
181+
182+ assert .are .same (completions [1 ], " assert(...)" )
183+ assert .are .same (completions [# completions ], " warn(...)" )
184+
185+ plugin_config .vscode_configuration [" typescript.suggest.completeFunctionCalls" ] = prev_config
173186 end )
174187
175188 it (" should return correct response for " .. methods .CompletionResolve , function ()
176189 utils .open_file " src/completion.ts"
177190 utils .wait_for_lsp_initialization ()
178191
179- local ret = vim . lsp . buf_request_sync ( 0 , methods . CompletionResolve , {
192+ local req = {
180193 commitCharacters = { " (" },
181194 data = {
182195 character = 8 ,
@@ -186,37 +199,33 @@ describe("Lsp request", function()
186199 },
187200 filterText = " warn" ,
188201 insertText = " warn" ,
189- insertTextFormat = c .InsertTextFormat .Snippet ,
202+ insertTextFormat = c .InsertTextFormat .PlainText ,
190203 kind = c .CompletionItemKind .Function ,
191204 label = " warn" ,
192205 sortText = " 11" ,
193- })
206+ }
207+ local ret = vim .lsp .buf_request_sync (0 , methods .CompletionResolve , req )
194208
195209 local result = lsp_assert .response (ret )
196210 assert .is .table (result )
197- assert .are .same (result .insertText , " warn($1)$0 " )
211+ assert .are .same (result .insertText , " warn" )
198212 assert .are .same (result .detail , " (method) Console.warn(...data: any[]): void" )
199213
200- ret = vim .lsp .buf_request_sync (0 , methods .CompletionResolve , {
201- commitCharacters = { " ." , " ?" },
202- data = {
203- character = 6 ,
204- entryNames = { " console" },
205- file = vim .fs .dirname (vim .api .nvim_buf_get_name (0 )) .. " /completion.ts" ,
206- line = 0 ,
207- },
208- filterText = " console" ,
209- insertText = " console" ,
210- insertTextFormat = c .InsertTextFormat .PlainText ,
211- kind = c .CompletionItemKind .Variable ,
212- label = " console" ,
213- sortText = " 15" ,
214- })
214+ -- same test as above but with function snippets enabled
215+ local prev_config =
216+ plugin_config .vscode_configuration [" typescript.suggest.completeFunctionCalls" ]
217+ plugin_config .vscode_configuration [" typescript.suggest.completeFunctionCalls" ] = true
215218
219+ req .label = " warn(...)"
220+ req .insertTextFormat = c .InsertTextFormat .Snippet
221+ ret = vim .lsp .buf_request_sync (0 , methods .CompletionResolve , req )
216222 result = lsp_assert .response (ret )
223+
217224 assert .is .table (result )
218- assert .are .same (result .insertText , " console" )
219- assert .are .same (result .detail , " var console: Console" )
225+ assert .are .same (result .insertText , " warn($1)$0" )
226+ assert .are .same (result .detail , " (method) Console.warn(...data: any[]): void" )
227+
228+ plugin_config .vscode_configuration [" typescript.suggest.completeFunctionCalls" ] = prev_config
220229 end )
221230
222231 it (" should return correct response for " .. methods .SignatureHelp , function ()
0 commit comments