support @ts-expect-error directive on tsserver v390

This commit is contained in:
Qiming Zhao 2020-04-17 16:00:08 +08:00
parent ef22359a1b
commit 92891a3096
2 changed files with 67 additions and 53 deletions

View file

@ -2,18 +2,18 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CancellationToken, CompletionContext, CompletionItem, CompletionItemKind, CompletionList, Position, Range } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { workspace } from 'coc.nvim'
import { ITypeScriptServiceClient } from '../typescriptService'
import API from '../utils/api'
interface Directive {
readonly value: string
readonly description: string
}
const directives: Directive[] = [
const tsDirectives: Directive[] = [
{
value: '@ts-check',
description: 'Enables semantic checking in a JavaScript file. Must be at the top of a file.'
@ -28,6 +28,14 @@ const directives: Directive[] = [
}
]
const tsDirectives390: Directive[] = [
...tsDirectives,
{
value: '@ts-expect-error',
description: 'Suppresses @ts-check errors on the next line of a file, expecting at least one to exist.'
}
]
export default class DirectiveCommentCompletionProvider {
constructor(private readonly client: ITypeScriptServiceClient) { }
@ -50,6 +58,9 @@ export default class DirectiveCommentCompletionProvider {
const prefix = line.slice(0, position.character)
const match = prefix.match(/^\s*\/\/+\s?(@[a-zA-Z\-]*)?$/)
if (match) {
const directives = this.client.apiVersion.gte(API.v390)
? tsDirectives390
: tsDirectives
let items = directives.map(directive => {
const item = CompletionItem.create(directive.value)
item.kind = CompletionItemKind.Snippet

View file

@ -5,61 +5,64 @@
import * as semver from 'semver'
export default class API {
private static fromSimpleString(value: string): API {
return new API(value, value)
}
private static fromSimpleString(value: string): API {
return new API(value, value)
}
public static readonly defaultVersion = API.fromSimpleString('1.0.0')
public static readonly v203 = API.fromSimpleString('2.0.3')
public static readonly v206 = API.fromSimpleString('2.0.6')
public static readonly v208 = API.fromSimpleString('2.0.8')
public static readonly v213 = API.fromSimpleString('2.1.3')
public static readonly v220 = API.fromSimpleString('2.2.0')
public static readonly v222 = API.fromSimpleString('2.2.2')
public static readonly v230 = API.fromSimpleString('2.3.0')
public static readonly v234 = API.fromSimpleString('2.3.4')
public static readonly v240 = API.fromSimpleString('2.4.0')
public static readonly v250 = API.fromSimpleString('2.5.0')
public static readonly v260 = API.fromSimpleString('2.6.0')
public static readonly v270 = API.fromSimpleString('2.7.0')
public static readonly v280 = API.fromSimpleString('2.8.0')
public static readonly v290 = API.fromSimpleString('2.9.0')
public static readonly v291 = API.fromSimpleString('2.9.1')
public static readonly v292 = API.fromSimpleString('2.9.2')
public static readonly v300 = API.fromSimpleString('3.0.0')
public static readonly v310 = API.fromSimpleString('3.1.0')
public static readonly v314 = API.fromSimpleString('3.1.4')
public static readonly v320 = API.fromSimpleString('3.2.0')
public static readonly v330 = API.fromSimpleString('3.3.0')
public static readonly v333 = API.fromSimpleString('3.3.3')
public static readonly v340 = API.fromSimpleString('3.4.0')
public static readonly v345 = API.fromSimpleString('3.4.5')
public static readonly v350 = API.fromSimpleString('3.5.0')
public static readonly defaultVersion = API.fromSimpleString('1.0.0')
public static readonly v203 = API.fromSimpleString('2.0.3')
public static readonly v206 = API.fromSimpleString('2.0.6')
public static readonly v208 = API.fromSimpleString('2.0.8')
public static readonly v213 = API.fromSimpleString('2.1.3')
public static readonly v220 = API.fromSimpleString('2.2.0')
public static readonly v222 = API.fromSimpleString('2.2.2')
public static readonly v230 = API.fromSimpleString('2.3.0')
public static readonly v234 = API.fromSimpleString('2.3.4')
public static readonly v240 = API.fromSimpleString('2.4.0')
public static readonly v250 = API.fromSimpleString('2.5.0')
public static readonly v260 = API.fromSimpleString('2.6.0')
public static readonly v270 = API.fromSimpleString('2.7.0')
public static readonly v280 = API.fromSimpleString('2.8.0')
public static readonly v290 = API.fromSimpleString('2.9.0')
public static readonly v291 = API.fromSimpleString('2.9.1')
public static readonly v292 = API.fromSimpleString('2.9.2')
public static readonly v300 = API.fromSimpleString('3.0.0')
public static readonly v310 = API.fromSimpleString('3.1.0')
public static readonly v314 = API.fromSimpleString('3.1.4')
public static readonly v320 = API.fromSimpleString('3.2.0')
public static readonly v330 = API.fromSimpleString('3.3.0')
public static readonly v333 = API.fromSimpleString('3.3.3')
public static readonly v340 = API.fromSimpleString('3.4.0')
public static readonly v345 = API.fromSimpleString('3.4.5')
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)
if (!version) {
return new API('invalid version', '1.0.0')
}
public static fromVersionString(versionString: string): API {
let version = semver.valid(versionString)
if (!version) {
return new API('invalid version', '1.0.0')
}
// Cut off any prerelease tag since we sometimes consume those on purpose.
const index = versionString.indexOf('-')
if (index >= 0) {
version = version.substr(0, index)
}
return new API(versionString, version)
}
// Cut off any prerelease tag since we sometimes consume those on purpose.
const index = versionString.indexOf('-')
if (index >= 0) {
version = version.substr(0, index)
}
return new API(versionString, version)
}
private constructor(
public readonly versionString: string,
private readonly version: string
) { }
private constructor(
public readonly versionString: string,
private readonly version: string
) { }
public gte(other: API): boolean {
return semver.gte(this.version, other.version)
}
public gte(other: API): boolean {
return semver.gte(this.version, other.version)
}
public lt(other: API): boolean {
return !this.gte(other)
}
public lt(other: API): boolean {
return !this.gte(other)
}
}