@@ -53,6 +53,17 @@ class MyCompletionItem extends CompletionItem {
53
53
this . range = tsTextSpanToVsRange ( tsEntry . replacementSpan ) ;
54
54
}
55
55
56
+ if ( typeof ( tsEntry as any ) . insertText === 'string' ) {
57
+ this . insertText = ( tsEntry as any ) . insertText as string ;
58
+
59
+ if ( tsEntry . replacementSpan ) {
60
+ this . range = tsTextSpanToVsRange ( tsEntry . replacementSpan ) ;
61
+ if ( this . insertText [ 0 ] === '[' ) { // o.x -> o['x']
62
+ this . filterText = '.' + this . label ;
63
+ }
64
+ }
65
+ }
66
+
56
67
if ( tsEntry . kindModifiers . match ( / \b o p t i o n a l \b / ) ) {
57
68
this . insertText = this . label ;
58
69
this . filterText = this . label ;
@@ -275,8 +286,9 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
275
286
try {
276
287
const args : Proto . CompletionsRequestArgs = {
277
288
...vsPositionToTsFileLocation ( file , position ) ,
278
- includeExternalModuleExports : config . autoImportSuggestions
279
- } ;
289
+ includeExternalModuleExports : config . autoImportSuggestions ,
290
+ includeInsertTextCompletions : true
291
+ } as Proto . CompletionsRequestArgs ;
280
292
const msg = await this . client . execute ( 'completions' , args , token ) ;
281
293
// This info has to come from the tsserver. See https://github.com/Microsoft/TypeScript/issues/2831
282
294
// let isMemberCompletion = false;
@@ -402,7 +414,7 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
402
414
if ( detail && item . useCodeSnippet ) {
403
415
const shouldCompleteFunction = await this . isValidFunctionCompletionContext ( filepath , item . position ) ;
404
416
if ( shouldCompleteFunction ) {
405
- item . insertText = this . snippetForFunctionCall ( detail ) ;
417
+ item . insertText = this . snippetForFunctionCall ( item , detail ) ;
406
418
}
407
419
return item ;
408
420
}
@@ -430,12 +442,15 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
430
442
}
431
443
}
432
444
433
- private snippetForFunctionCall ( detail : Proto . CompletionEntryDetails ) : SnippetString {
445
+ private snippetForFunctionCall (
446
+ item : CompletionItem ,
447
+ detail : Proto . CompletionEntryDetails
448
+ ) : SnippetString {
434
449
let hasOptionalParameters = false ;
435
450
let hasAddedParameters = false ;
436
451
437
452
const snippet = new SnippetString ( ) ;
438
- snippet . appendText ( detail . name ) ;
453
+ snippet . appendText ( item . label || item . insertText as string ) ;
439
454
snippet . appendText ( '(' ) ;
440
455
441
456
let parenCount = 0 ;
0 commit comments