mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Move version check into provideCompletionItems
Handle TS version changes
This commit is contained in:
parent
990363f194
commit
f20250c965
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue