From 65d72e09c25be1d17b26919521627f938c968b36 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 5 Mar 2020 11:04:23 -0500 Subject: [PATCH 1/3] Added completion entry for @ts-expect-error directive --- .../src/features/directiveCommentCompletions.ts | 5 +++++ .../walkThrough/browser/editor/vs_code_editor_walkthrough.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts b/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts index c0a222e47df63..17035eee93a28 100644 --- a/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts +++ b/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts @@ -30,6 +30,11 @@ const directives: Directive[] = [ description: localize( 'ts-ignore', "Suppresses @ts-check errors on the next line of a file.") + }, { + value: '@ts-expect-error', + description: localize( + 'ts-expect-error', + "Suppresses @ts-check errors on the next line of a file, expecting at least one to exist.") } ]; diff --git a/src/vs/workbench/contrib/welcome/walkThrough/browser/editor/vs_code_editor_walkthrough.ts b/src/vs/workbench/contrib/welcome/walkThrough/browser/editor/vs_code_editor_walkthrough.ts index 252b682d8b82c..6f7b6c61db30e 100644 --- a/src/vs/workbench/contrib/welcome/walkThrough/browser/editor/vs_code_editor_walkthrough.ts +++ b/src/vs/workbench/contrib/welcome/walkThrough/browser/editor/vs_code_editor_walkthrough.ts @@ -174,7 +174,7 @@ let easy = true; easy = 42; ||| ->**Tip:** You can also enable the checks workspace or application wide by adding |"javascript.implicitProjectConfig.checkJs": true| to your workspace or user settings and explicitly ignoring files or lines using |// @ts-nocheck| and |// @ts-ignore|. Check out the docs on [JavaScript in VS Code](https://code.visualstudio.com/docs/languages/javascript) to learn more. +>**Tip:** You can also enable the checks workspace or application wide by adding |"javascript.implicitProjectConfig.checkJs": true| to your workspace or user settings and explicitly ignoring files or lines using |// @ts-nocheck| and |// @ts-expect-error|. Check out the docs on [JavaScript in VS Code](https://code.visualstudio.com/docs/languages/javascript) to learn more. ## Thanks! From 42ab58246516b5c20e89a6767eefe526e22bfa51 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sat, 7 Mar 2020 15:24:26 -0500 Subject: [PATCH 2/3] Limited to relevant TS versions --- .../features/directiveCommentCompletions.ts | 21 +++++++++++++++---- .../src/utils/api.ts | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts b/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts index 17035eee93a28..4561e16ca4a66 100644 --- a/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts +++ b/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts @@ -6,6 +6,7 @@ import * as vscode from 'vscode'; import * as nls from 'vscode-nls'; import { ITypeScriptServiceClient } from '../typescriptService'; +import API from '../utils/api'; const localize = nls.loadMessageBundle(); @@ -14,7 +15,7 @@ interface Directive { readonly description: string; } -const directives: Directive[] = [ +const directives260: Directive[] = [ { value: '@ts-check', description: localize( @@ -30,7 +31,12 @@ const directives: Directive[] = [ description: localize( 'ts-ignore', "Suppresses @ts-check errors on the next line of a file.") - }, { + } +]; + +const directives390: Directive[] = [ + ...directives260, + { value: '@ts-expect-error', description: localize( 'ts-expect-error', @@ -39,10 +45,17 @@ const directives: Directive[] = [ ]; class DirectiveCommentCompletionProvider implements vscode.CompletionItemProvider { + private readonly directives: Directive[]; constructor( private readonly client: ITypeScriptServiceClient, - ) { } + ) { + this.directives = client.apiVersion.gte(API.v390) + ? directives390 + : client.apiVersion.gte(API.v260) + ? directives260 + : []; + } public provideCompletionItems( document: vscode.TextDocument, @@ -58,7 +71,7 @@ class DirectiveCommentCompletionProvider implements vscode.CompletionItemProvide const prefix = line.slice(0, position.character); const match = prefix.match(/^\s*\/\/+\s?(@[a-zA-Z\-]*)?$/); if (match) { - return directives.map(directive => { + return this.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); diff --git a/extensions/typescript-language-features/src/utils/api.ts b/extensions/typescript-language-features/src/utils/api.ts index 25be4b5e5161c..1845285caa459 100644 --- a/extensions/typescript-language-features/src/utils/api.ts +++ b/extensions/typescript-language-features/src/utils/api.ts @@ -33,6 +33,7 @@ export default class API { public static readonly v350 = API.fromSimpleString('3.5.0'); public static readonly v380 = API.fromSimpleString('3.8.0'); public static readonly v381 = API.fromSimpleString('3.8.1'); + public static readonly v390 = API.fromSimpleString('3.9.0'); public static fromVersionString(versionString: string): API { let version = semver.valid(versionString); From 05ed591cf21079f86a392731f4ee7078297cc7f8 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sat, 7 Mar 2020 15:31:17 -0500 Subject: [PATCH 3/3] You know what, it's more complicated, I'll just go with everything vs 3.9 --- .../src/features/directiveCommentCompletions.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts b/extensions/typescript-language-features/src/features/directiveCommentCompletions.ts index 4561e16ca4a66..8a33a76a5a891 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 directives260: Directive[] = [ +const directives: Directive[] = [ { value: '@ts-check', description: localize( @@ -35,7 +35,7 @@ const directives260: Directive[] = [ ]; const directives390: Directive[] = [ - ...directives260, + ...directives, { value: '@ts-expect-error', description: localize( @@ -52,9 +52,7 @@ class DirectiveCommentCompletionProvider implements vscode.CompletionItemProvide ) { this.directives = client.apiVersion.gte(API.v390) ? directives390 - : client.apiVersion.gte(API.v260) - ? directives260 - : []; + : directives; } public provideCompletionItems(