Added completion entry for @ts-expect-error directive (#92093)
* Added completion entry for @ts-expect-error directive * Limited to relevant TS versions * You know what, it's more complicated, I'll just go with everything vs 3.9
This commit is contained in:
parent
5551d73be9
commit
72c700cf54
3 changed files with 20 additions and 3 deletions
|
@ -6,6 +6,7 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||||
|
import API from '../utils/api';
|
||||||
|
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
|
@ -33,11 +34,26 @@ const directives: Directive[] = [
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const directives390: Directive[] = [
|
||||||
|
...directives,
|
||||||
|
{
|
||||||
|
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.")
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
class DirectiveCommentCompletionProvider implements vscode.CompletionItemProvider {
|
class DirectiveCommentCompletionProvider implements vscode.CompletionItemProvider {
|
||||||
|
private readonly directives: Directive[];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly client: ITypeScriptServiceClient,
|
private readonly client: ITypeScriptServiceClient,
|
||||||
) { }
|
) {
|
||||||
|
this.directives = client.apiVersion.gte(API.v390)
|
||||||
|
? directives390
|
||||||
|
: directives;
|
||||||
|
}
|
||||||
|
|
||||||
public provideCompletionItems(
|
public provideCompletionItems(
|
||||||
document: vscode.TextDocument,
|
document: vscode.TextDocument,
|
||||||
|
@ -53,7 +69,7 @@ class DirectiveCommentCompletionProvider implements vscode.CompletionItemProvide
|
||||||
const prefix = line.slice(0, position.character);
|
const prefix = line.slice(0, position.character);
|
||||||
const match = prefix.match(/^\s*\/\/+\s?(@[a-zA-Z\-]*)?$/);
|
const match = prefix.match(/^\s*\/\/+\s?(@[a-zA-Z\-]*)?$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
return directives.map(directive => {
|
return this.directives.map(directive => {
|
||||||
const item = new vscode.CompletionItem(directive.value, vscode.CompletionItemKind.Snippet);
|
const item = new vscode.CompletionItem(directive.value, vscode.CompletionItemKind.Snippet);
|
||||||
item.detail = directive.description;
|
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);
|
item.range = new vscode.Range(position.line, Math.max(0, position.character - (match[1] ? match[1].length : 0)), position.line, position.character);
|
||||||
|
|
|
@ -33,6 +33,7 @@ export default class API {
|
||||||
public static readonly v350 = API.fromSimpleString('3.5.0');
|
public static readonly v350 = API.fromSimpleString('3.5.0');
|
||||||
public static readonly v380 = API.fromSimpleString('3.8.0');
|
public static readonly v380 = API.fromSimpleString('3.8.0');
|
||||||
public static readonly v381 = API.fromSimpleString('3.8.1');
|
public static readonly v381 = API.fromSimpleString('3.8.1');
|
||||||
|
public static readonly v390 = API.fromSimpleString('3.9.0');
|
||||||
|
|
||||||
public static fromVersionString(versionString: string): API {
|
public static fromVersionString(versionString: string): API {
|
||||||
let version = semver.valid(versionString);
|
let version = semver.valid(versionString);
|
||||||
|
|
|
@ -174,7 +174,7 @@ let easy = true;
|
||||||
easy = 42;
|
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!
|
## Thanks!
|
||||||
|
|
Loading…
Reference in a new issue