@@ -682,6 +682,14 @@ function resolvingModuleSpecifiers<TReturn>(
682
682
}
683
683
}
684
684
685
+ /** @internal */
686
+ export function getDefaultCommitCharacters ( isNewIdentifierLocation : boolean ) : string [ ] {
687
+ if ( isNewIdentifierLocation ) {
688
+ return [ ] ;
689
+ }
690
+ return [ "." , "," , ";" ] ;
691
+ }
692
+
685
693
/** @internal */
686
694
export function getCompletionsAtPosition (
687
695
host : LanguageServiceHost ,
@@ -704,7 +712,14 @@ export function getCompletionsAtPosition(
704
712
if ( triggerCharacter === " " ) {
705
713
// `isValidTrigger` ensures we are at `import |`
706
714
if ( preferences . includeCompletionsForImportStatements && preferences . includeCompletionsWithInsertText ) {
707
- return { isGlobalCompletion : true , isMemberCompletion : false , isNewIdentifierLocation : true , isIncomplete : true , entries : [ ] } ;
715
+ return {
716
+ isGlobalCompletion : true ,
717
+ isMemberCompletion : false ,
718
+ isNewIdentifierLocation : true ,
719
+ isIncomplete : true ,
720
+ entries : [ ] ,
721
+ defaultCommitCharacters : getDefaultCommitCharacters ( /*isNewIdentifierLocation*/ true ) ,
722
+ } ;
708
723
}
709
724
return undefined ;
710
725
}
@@ -887,7 +902,13 @@ function continuePreviousIncompleteResponse(
887
902
}
888
903
889
904
function jsdocCompletionInfo ( entries : CompletionEntry [ ] ) : CompletionInfo {
890
- return { isGlobalCompletion : false , isMemberCompletion : false , isNewIdentifierLocation : false , entries } ;
905
+ return {
906
+ isGlobalCompletion : false ,
907
+ isMemberCompletion : false ,
908
+ isNewIdentifierLocation : false ,
909
+ entries,
910
+ defaultCommitCharacters : getDefaultCommitCharacters ( /*isNewIdentifierLocation*/ false ) ,
911
+ } ;
891
912
}
892
913
893
914
function getJSDocParameterCompletions (
@@ -1212,6 +1233,7 @@ function specificKeywordCompletionInfo(entries: readonly CompletionEntry[], isNe
1212
1233
isMemberCompletion : false ,
1213
1234
isNewIdentifierLocation,
1214
1235
entries : entries . slice ( ) ,
1236
+ defaultCommitCharacters : getDefaultCommitCharacters ( isNewIdentifierLocation ) ,
1215
1237
} ;
1216
1238
}
1217
1239
@@ -1387,6 +1409,7 @@ function completionInfoFromData(
1387
1409
isNewIdentifierLocation,
1388
1410
optionalReplacementSpan : getOptionalReplacementSpan ( location ) ,
1389
1411
entries,
1412
+ defaultCommitCharacters : getDefaultCommitCharacters ( isNewIdentifierLocation ) ,
1390
1413
} ;
1391
1414
}
1392
1415
@@ -1596,7 +1619,14 @@ function getJsxClosingTagCompletion(location: Node | undefined, sourceFile: Sour
1596
1619
kindModifiers : undefined ,
1597
1620
sortText : SortText . LocationPriority ,
1598
1621
} ;
1599
- return { isGlobalCompletion : false , isMemberCompletion : true , isNewIdentifierLocation : false , optionalReplacementSpan : replacementSpan , entries : [ entry ] } ;
1622
+ return {
1623
+ isGlobalCompletion : false ,
1624
+ isMemberCompletion : true ,
1625
+ isNewIdentifierLocation : false ,
1626
+ optionalReplacementSpan : replacementSpan ,
1627
+ entries : [ entry ] ,
1628
+ defaultCommitCharacters : getDefaultCommitCharacters ( /*isNewIdentifierLocation*/ false ) ,
1629
+ } ;
1600
1630
}
1601
1631
return ;
1602
1632
}
@@ -1622,6 +1652,7 @@ function getJSCompletionEntries(
1622
1652
kindModifiers : "" ,
1623
1653
sortText : SortText . JavascriptIdentifiers ,
1624
1654
isFromUncheckedFile : true ,
1655
+ commitCharacters : [ ] ,
1625
1656
} , compareCompletionEntries ) ;
1626
1657
}
1627
1658
} ) ;
@@ -1633,7 +1664,13 @@ function completionNameForLiteral(sourceFile: SourceFile, preferences: UserPrefe
1633
1664
}
1634
1665
1635
1666
function createCompletionEntryForLiteral ( sourceFile : SourceFile , preferences : UserPreferences , literal : string | number | PseudoBigInt ) : CompletionEntry {
1636
- return { name : completionNameForLiteral ( sourceFile , preferences , literal ) , kind : ScriptElementKind . string , kindModifiers : ScriptElementKindModifier . none , sortText : SortText . LocationPriority } ;
1667
+ return {
1668
+ name : completionNameForLiteral ( sourceFile , preferences , literal ) ,
1669
+ kind : ScriptElementKind . string ,
1670
+ kindModifiers : ScriptElementKindModifier . none ,
1671
+ sortText : SortText . LocationPriority ,
1672
+ commitCharacters : [ ] ,
1673
+ } ;
1637
1674
}
1638
1675
1639
1676
function createCompletionEntry (
@@ -1863,9 +1900,11 @@ function createCompletionEntry(
1863
1900
1864
1901
// Use a 'sortText' of 0' so that all symbol completion entries come before any other
1865
1902
// entries (like JavaScript identifier entries).
1903
+ const kind = SymbolDisplay . getSymbolKind ( typeChecker , symbol , location ) ;
1904
+ const commitCharacters = ( kind === ScriptElementKind . warning || kind === ScriptElementKind . string ) ? [ ] : undefined ;
1866
1905
return {
1867
1906
name,
1868
- kind : SymbolDisplay . getSymbolKind ( typeChecker , symbol , location ) ,
1907
+ kind,
1869
1908
kindModifiers : SymbolDisplay . getSymbolModifiers ( typeChecker , symbol ) ,
1870
1909
sortText,
1871
1910
source,
@@ -1880,6 +1919,7 @@ function createCompletionEntry(
1880
1919
isPackageJsonImport : originIsPackageJsonImport ( origin ) || undefined ,
1881
1920
isImportStatementCompletion : ! ! importStatementCompletion || undefined ,
1882
1921
data,
1922
+ commitCharacters,
1883
1923
...includeSymbol ? { symbol } : undefined ,
1884
1924
} ;
1885
1925
}
@@ -2754,7 +2794,13 @@ export function getCompletionEntriesFromSymbols(
2754
2794
function getLabelCompletionAtPosition ( node : BreakOrContinueStatement ) : CompletionInfo | undefined {
2755
2795
const entries = getLabelStatementCompletions ( node ) ;
2756
2796
if ( entries . length ) {
2757
- return { isGlobalCompletion : false , isMemberCompletion : false , isNewIdentifierLocation : false , entries } ;
2797
+ return {
2798
+ isGlobalCompletion : false ,
2799
+ isMemberCompletion : false ,
2800
+ isNewIdentifierLocation : false ,
2801
+ entries,
2802
+ defaultCommitCharacters : getDefaultCommitCharacters ( /*isNewIdentifierLocation*/ false ) ,
2803
+ } ;
2758
2804
}
2759
2805
}
2760
2806
0 commit comments