support @ts-expect-error directive on tsserver v390
This commit is contained in:
parent
ef22359a1b
commit
92891a3096
2 changed files with 67 additions and 53 deletions
|
@ -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
|
||||
|
|
|
@ -35,6 +35,9 @@ export default class API {
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue