Skip to content

Commit 728197d

Browse files
authored
Remove some completions logic specific to old TS versions (microsoft#182894)
Removes workarounds added for TS versions that are many years old at this point
1 parent c2e40c8 commit 728197d

File tree

1 file changed

+14
-54
lines changed
  • extensions/typescript-language-features/src/languageFeatures

1 file changed

+14
-54
lines changed

extensions/typescript-language-features/src/languageFeatures/completions.ts

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ interface DotAccessorContext {
3131
interface CompletionContext {
3232
readonly isNewIdentifierLocation: boolean;
3333
readonly isMemberCompletion: boolean;
34-
readonly isInValidCommitCharacterContext: boolean;
3534

3635
readonly dotAccessorContext?: DotAccessorContext;
3736

@@ -40,8 +39,6 @@ interface CompletionContext {
4039

4140
readonly wordRange: vscode.Range | undefined;
4241
readonly line: string;
43-
44-
readonly useFuzzyWordRangeLogic: boolean;
4542
}
4643

4744
type ResolvedCompletionItem = {
@@ -102,7 +99,7 @@ class MyCompletionItem extends vscode.CompletionItem {
10299
if (completionContext.isMemberCompletion && completionContext.dotAccessorContext && !(this.insertText instanceof vscode.SnippetString)) {
103100
this.filterText = completionContext.dotAccessorContext.text + (this.insertText || this.textLabel);
104101
if (!this.range) {
105-
const replacementRange = this.getFuzzyWordRange();
102+
const replacementRange = this.completionContext.wordRange;
106103
if (replacementRange) {
107104
this.range = {
108105
inserting: completionContext.dotAccessorContext.range,
@@ -423,7 +420,7 @@ class MyCompletionItem extends vscode.CompletionItem {
423420
return;
424421
}
425422

426-
const replaceRange = this.getFuzzyWordRange();
423+
const replaceRange = this.completionContext.wordRange;
427424
if (replaceRange) {
428425
this.range = {
429426
inserting: new vscode.Range(replaceRange.start, this.position),
@@ -432,23 +429,6 @@ class MyCompletionItem extends vscode.CompletionItem {
432429
}
433430
}
434431

435-
private getFuzzyWordRange() {
436-
if (this.completionContext.useFuzzyWordRangeLogic) {
437-
// Try getting longer, prefix based range for completions that span words
438-
const text = this.completionContext.line.slice(Math.max(0, this.position.character - this.textLabel.length), this.position.character).toLowerCase();
439-
const entryName = this.textLabel.toLowerCase();
440-
for (let i = entryName.length; i >= 0; --i) {
441-
if (text.endsWith(entryName.substr(0, i)) && (!this.completionContext.wordRange || this.completionContext.wordRange.start.character > this.position.character - i)) {
442-
return new vscode.Range(
443-
new vscode.Position(this.position.line, Math.max(0, this.position.character - i)),
444-
this.position);
445-
}
446-
}
447-
}
448-
449-
return this.completionContext.wordRange;
450-
}
451-
452432
private static convertKind(kind: string): vscode.CompletionItemKind {
453433
switch (kind) {
454434
case PConst.Kind.primitiveType:
@@ -517,7 +497,7 @@ class MyCompletionItem extends vscode.CompletionItem {
517497
return undefined;
518498
}
519499

520-
if (context.isNewIdentifierLocation || !context.isInValidCommitCharacterContext) {
500+
if (context.isNewIdentifierLocation) {
521501
return undefined;
522502
}
523503

@@ -790,16 +770,14 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<
790770
metadata = response.metadata;
791771
}
792772

793-
const completionContext = {
773+
const completionContext: CompletionContext = {
794774
isNewIdentifierLocation,
795775
isMemberCompletion,
796776
dotAccessorContext,
797-
isInValidCommitCharacterContext: this.isInValidCommitCharacterContext(document, position),
798777
enableCallCompletions: !completionConfiguration.completeFunctionCalls,
799778
wordRange,
800779
line: line.text,
801780
completeFunctionCalls: completionConfiguration.completeFunctionCalls,
802-
useFuzzyWordRangeLogic: this.client.apiVersion.lt(API.v390),
803781
};
804782

805783
let includesPackageJsonImport = false;
@@ -864,26 +842,27 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<
864842

865843
private getTsTriggerCharacter(context: vscode.CompletionContext): Proto.CompletionsTriggerCharacter | undefined {
866844
switch (context.triggerCharacter) {
867-
case '@': // Workaround for https://github.com/microsoft/TypeScript/issues/27321
845+
case '@': { // Workaround for https://github.com/microsoft/TypeScript/issues/27321
868846
return this.client.apiVersion.gte(API.v310) && this.client.apiVersion.lt(API.v320) ? undefined : '@';
869-
870-
case '#': // Workaround for https://github.com/microsoft/TypeScript/issues/36367
847+
}
848+
case '#': { // Workaround for https://github.com/microsoft/TypeScript/issues/36367
871849
return this.client.apiVersion.lt(API.v381) ? undefined : '#';
872-
850+
}
873851
case ' ': {
874-
const space: Proto.CompletionsTriggerCharacter = ' ';
875-
return this.client.apiVersion.gte(API.v430) ? space : undefined;
852+
return this.client.apiVersion.gte(API.v430) ? ' ' : undefined;
876853
}
877854
case '.':
878855
case '"':
879856
case '\'':
880857
case '`':
881858
case '/':
882-
case '<':
859+
case '<': {
883860
return context.triggerCharacter;
861+
}
862+
default: {
863+
return undefined;
864+
}
884865
}
885-
886-
return undefined;
887866
}
888867

889868
public async resolveCompletionItem(
@@ -894,25 +873,6 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<
894873
return item;
895874
}
896875

897-
private isInValidCommitCharacterContext(
898-
document: vscode.TextDocument,
899-
position: vscode.Position
900-
): boolean {
901-
if (this.client.apiVersion.lt(API.v320)) {
902-
// Workaround for https://github.com/microsoft/TypeScript/issues/27742
903-
// Only enable dot completions when previous character not a dot preceded by whitespace.
904-
// Prevents incorrectly completing while typing spread operators.
905-
if (position.character > 1) {
906-
const preText = document.getText(new vscode.Range(
907-
position.line, 0,
908-
position.line, position.character));
909-
return preText.match(/(\s|^)\.$/ig) === null;
910-
}
911-
}
912-
913-
return true;
914-
}
915-
916876
private shouldTrigger(
917877
context: vscode.CompletionContext,
918878
line: vscode.TextLine,

0 commit comments

Comments
 (0)