@@ -857,15 +857,14 @@ namespace ts.Completions {
857857 const importAdder = codefix . createImportAdder ( sourceFile , program , preferences , host ) ;
858858
859859 let body ;
860- let tabstopStart = 1 ;
861860 if ( preferences . includeCompletionsWithSnippetText ) {
862861 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.
864864 // 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 ) ;
869868 }
870869 else {
871870 body = factory . createBlock ( [ ] , /* multiline */ true ) ;
@@ -923,9 +922,6 @@ namespace ts.Completions {
923922 isAbstract ) ;
924923
925924 if ( completionNodes . length ) {
926- if ( preferences . includeCompletionsWithSnippetText ) {
927- addSnippets ( completionNodes , tabstopStart ) ;
928- }
929925 insertText = printer . printSnippetList ( ListFormat . MultiLine , factory . createNodeArray ( completionNodes ) , sourceFile ) ;
930926 }
931927
@@ -973,35 +969,6 @@ namespace ts.Completions {
973969 return undefined ;
974970 }
975971
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-
1005972 function createSnippetPrinter (
1006973 printerOptions : PrinterOptions ,
1007974 ) {
0 commit comments