From f20250c965233df0478f0a9b08750a41a8cc3ced Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 9 Mar 2020 13:57:49 -0700 Subject: [PATCH] Move version check into provideCompletionItems Handle TS version changes --- .../features/directiveCommentCompletions.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts b/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts index 8a33a76a5a8..cfa35571d1d 100644 --- a/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts +++ b/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts @@ -15,7 +15,7 @@ interface Directive { readonly description: string; } -const directives: Directive[] = [ +const tsDirectives: Directive[] = [ { value: '@ts-check', description: localize( @@ -34,8 +34,8 @@ const directives: Directive[] = [ } ]; -const directives390: Directive[] = [ - ...directives, +const tsDirectives390: Directive[] = [ + ...tsDirectives, { value: '@ts-expect-error', description: localize( @@ -45,15 +45,10 @@ const directives390: Directive[] = [ ]; class DirectiveCommentCompletionProvider implements vscode.CompletionItemProvider { - private readonly directives: Directive[]; constructor( private readonly client: ITypeScriptServiceClient, - ) { - this.directives = client.apiVersion.gte(API.v390) - ? directives390 - : directives; - } + ) { } public provideCompletionItems( document: vscode.TextDocument, @@ -69,7 +64,11 @@ class DirectiveCommentCompletionProvider implements vscode.CompletionItemProvide const prefix = line.slice(0, position.character); const match = prefix.match(/^\s*\/\/+\s?(@[a-zA-Z\-]*)?$/); if (match) { - return this.directives.map(directive => { + const directives = this.client.apiVersion.gte(API.v390) + ? tsDirectives390 + : tsDirectives; + + return directives.map(directive => { const item = new vscode.CompletionItem(directive.value, vscode.CompletionItemKind.Snippet); item.detail = directive.description; item.range = new vscode.Range(position.line, Math.max(0, position.character - (match[1] ? match[1].length : 0)), position.line, position.character);