@@ -857,15 +857,14 @@ namespace ts.Completions {
857
857
const importAdder = codefix . createImportAdder ( sourceFile , program , preferences , host ) ;
858
858
859
859
let body ;
860
- let tabstopStart = 1 ;
861
860
if ( preferences . includeCompletionsWithSnippetText ) {
862
861
isSnippet = true ;
863
- // We are adding a final tabstop (i.e. $0) in the body of the suggested member, if it has one.
862
+ // We are adding a tabstop (i.e. `$0`) in the body of the suggested member,
863
+ // if it has one, so that the cursor ends up in the body once the completion is inserted.
864
864
// Note: this assumes we won't have more than one body in the completion nodes, which should be the case.
865
- const emptyStatement1 = factory . createExpressionStatement ( factory . createIdentifier ( "" ) ) ;
866
- setSnippetElement ( emptyStatement1 , { kind : SnippetKind . TabStop , order : 1 } ) ;
867
- tabstopStart = 2 ;
868
- body = factory . createBlock ( [ emptyStatement1 ] , /* multiline */ true ) ;
865
+ const emptyStatement = factory . createExpressionStatement ( factory . createIdentifier ( "" ) ) ;
866
+ setSnippetElement ( emptyStatement , { kind : SnippetKind . TabStop , order : 0 } ) ;
867
+ body = factory . createBlock ( [ emptyStatement ] , /* multiline */ true ) ;
869
868
}
870
869
else {
871
870
body = factory . createBlock ( [ ] , /* multiline */ true ) ;
@@ -923,9 +922,6 @@ namespace ts.Completions {
923
922
isAbstract ) ;
924
923
925
924
if ( completionNodes . length ) {
926
- if ( preferences . includeCompletionsWithSnippetText ) {
927
- addSnippets ( completionNodes , tabstopStart ) ;
928
- }
929
925
insertText = printer . printSnippetList ( ListFormat . MultiLine , factory . createNodeArray ( completionNodes ) , sourceFile ) ;
930
926
}
931
927
@@ -973,35 +969,6 @@ namespace ts.Completions {
973
969
return undefined ;
974
970
}
975
971
976
- function addSnippets ( nodes : Node [ ] , orderStart : number ) : void {
977
- let order = orderStart ;
978
- for ( const node of nodes ) {
979
- addSnippetsWorker ( node , /*parent*/ undefined ) ;
980
- }
981
-
982
- function addSnippetsWorker ( node : Node , parent : Node | undefined ) {
983
- if ( isVariableLike ( node ) && node . kind === SyntaxKind . Parameter ) {
984
- // Placeholder
985
- setSnippetElement ( node . name , { kind : SnippetKind . Placeholder , order } ) ;
986
- order += 1 ;
987
- if ( node . type ) {
988
- setSnippetElement ( node . type , { kind : SnippetKind . Placeholder , order } ) ;
989
- order += 1 ;
990
- }
991
- }
992
- else if ( isTypeNode ( node ) && parent && isFunctionLikeDeclaration ( parent ) ) {
993
- setSnippetElement ( node , { kind : SnippetKind . Placeholder , order } ) ;
994
- order += 1 ;
995
- }
996
- else if ( isTypeParameterDeclaration ( node ) && parent && isFunctionLikeDeclaration ( parent ) ) {
997
- setSnippetElement ( node , { kind : SnippetKind . Placeholder , order } ) ;
998
- order += 1 ;
999
- }
1000
-
1001
- forEachChild ( node , child => addSnippetsWorker ( child , node ) ) ;
1002
- }
1003
- }
1004
-
1005
972
function createSnippetPrinter (
1006
973
printerOptions : PrinterOptions ,
1007
974
) {
0 commit comments