diff --git a/package.json b/package.json index b4bfa9d..e80cd71 100644 --- a/package.json +++ b/package.json @@ -265,6 +265,11 @@ "default": true, "description": "Show unused variable hint." }, + "typescript.showDeprecated": { + "type": "boolean", + "default": true, + "description": "Show deprecated variable hint." + }, "typescript.updateImportsOnFileMove.enable": { "type": "boolean", "default": true, @@ -473,6 +478,11 @@ "default": true, "description": "Show unused variable hint." }, + "javascript.showDeprecated": { + "type": "boolean", + "default": true, + "description": "Show deprecated variable hint." + }, "javascript.updateImportsOnFileMove.enable": { "type": "boolean", "default": true diff --git a/src/server/features/diagnostics.ts b/src/server/features/diagnostics.ts index 931a707..47f93af 100644 --- a/src/server/features/diagnostics.ts +++ b/src/server/features/diagnostics.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { DiagnosticCollection, languages, workspace } from 'coc.nvim' -import { Diagnostic } from 'vscode-languageserver-protocol' +import { Diagnostic, DiagnosticTag } from 'vscode-languageserver-protocol' import { ResourceMap } from './resourceMap' export class DiagnosticSet { @@ -146,8 +146,7 @@ export class DiagnosticsManager { .get(uri) .filter(x => { if (!enabled) { - // Still show unused - return x.code == 6133 + return x.tags && (x.tags.includes(DiagnosticTag.Unnecessary) || x.tags.includes(DiagnosticTag.Deprecated)) } return enabled }) diff --git a/src/server/features/workspaceSymbols.ts b/src/server/features/workspaceSymbols.ts index 679b8dc..15342fa 100644 --- a/src/server/features/workspaceSymbols.ts +++ b/src/server/features/workspaceSymbols.ts @@ -4,12 +4,17 @@ *--------------------------------------------------------------------------------------------*/ import { workspace } from 'coc.nvim' import { WorkspaceSymbolProvider } from 'coc.nvim' -import { CancellationToken, Range, SymbolInformation, SymbolKind } from 'vscode-languageserver-protocol' +import { CancellationToken, Range, SymbolInformation, SymbolKind, SymbolTag } from 'vscode-languageserver-protocol' import * as Proto from '../protocol' +import * as PConst from '../protocol.const' import { ITypeScriptServiceClient } from '../typescriptService' import API from '../utils/api' import * as typeConverters from '../utils/typeConverters' +function parseKindModifier(kindModifiers: string): Set { + return new Set(kindModifiers.split(/,|\s+/g)) +} + function getSymbolKind(item: Proto.NavtoItem): SymbolKind { switch (item.kind) { case 'method': @@ -75,7 +80,10 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo getSymbolKind(item), range, this.client.toResource(item.file)) - + const kindModifiers = item.kindModifiers ? parseKindModifier(item.kindModifiers) : undefined + if (kindModifiers?.has(PConst.KindModifiers.deprecated)) { + symbolInfo.tags = [SymbolTag.Deprecated] + } result.push(symbolInfo) } return result diff --git a/src/server/languageProvider.ts b/src/server/languageProvider.ts index 3e940ca..bce2bd7 100644 --- a/src/server/languageProvider.ts +++ b/src/server/languageProvider.ts @@ -179,17 +179,22 @@ export default class LanguageProvider { public diagnosticsReceived( diagnosticsKind: DiagnosticKind, file: Uri, - diagnostics: (Diagnostic & { reportUnnecessary: any })[] + diagnostics: (Diagnostic & { reportUnnecessary: any, reportDeprecated: any })[] ): void { const config = workspace.getConfiguration(this.id, file.toString()) const reportUnnecessary = config.get('showUnused', true) + const reportDeprecated = config.get('showDeprecated', true) this.client.diagnosticsManager.diagnosticsReceived(diagnosticsKind, file.toString(), diagnostics.filter(diag => { if (!reportUnnecessary) { - diag.tags = undefined if (diag.reportUnnecessary && diag.severity === DiagnosticSeverity.Information) { return false } } + if (!reportDeprecated) { + if (diag.reportDeprecated && diag.severity === DiagnosticSeverity.Hint) { + return false + } + } return true })) } diff --git a/src/server/typescriptServiceClientHost.ts b/src/server/typescriptServiceClientHost.ts index 5f1479a..dea0311 100644 --- a/src/server/typescriptServiceClientHost.ts +++ b/src/server/typescriptServiceClientHost.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { disposeAll, languages, TextDocument, Uri, workspace } from 'coc.nvim' -import { CancellationToken, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, Disposable, Position, Range } from 'vscode-languageserver-protocol' +import { CancellationToken, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, Disposable, Position, Range } from 'vscode-languageserver-protocol' import { flatten } from '../utils/arrays' import { PluginManager } from '../utils/plugins' import { DiagnosticKind } from './features/diagnostics' @@ -217,11 +217,11 @@ export default class TypeScriptServiceClientHost implements Disposable { } } - private createMarkerDatas(diagnostics: Proto.Diagnostic[]): (Diagnostic & { reportUnnecessary: any })[] { + private createMarkerDatas(diagnostics: Proto.Diagnostic[]): (Diagnostic & { reportUnnecessary: any, reportDeprecated: any })[] { return diagnostics.map(tsDiag => this.tsDiagnosticToLspDiagnostic(tsDiag)) } - private tsDiagnosticToLspDiagnostic(diagnostic: Proto.Diagnostic): (Diagnostic & { reportUnnecessary: any }) { + private tsDiagnosticToLspDiagnostic(diagnostic: Proto.Diagnostic): (Diagnostic & { reportUnnecessary: any, reportDeprecated: any }) { const { start, end, text } = diagnostic const range = { start: typeConverters.Position.fromLocation(start), @@ -237,11 +237,22 @@ export default class TypeScriptServiceClientHost implements Disposable { } }) } + let tags: DiagnosticTag[] | undefined = [] + if (diagnostic.reportsUnnecessary) { + tags.push(DiagnosticTag.Unnecessary) + } + if (diagnostic.reportsDeprecated) { + tags.push(DiagnosticTag.Deprecated) + } + tags = tags.length ? tags : undefined + return { range, + tags, message: text, code: diagnostic.code ? diagnostic.code : null, severity: this.getDiagnosticSeverity(diagnostic), + reportDeprecated: diagnostic.reportsDeprecated, reportUnnecessary: diagnostic.reportsUnnecessary, source: diagnostic.source || 'tsserver', relatedInformation diff --git a/src/server/utils/completionItem.ts b/src/server/utils/completionItem.ts index 7fcbe4f..1ccfec2 100644 --- a/src/server/utils/completionItem.ts +++ b/src/server/utils/completionItem.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { Range, CompletionItem, CompletionItemKind, InsertTextFormat, Position, TextEdit } from 'coc.nvim' +import { CompletionItemTag } from 'vscode-languageserver-protocol' import * as Proto from '../protocol' import * as PConst from '../protocol.const' @@ -52,6 +53,7 @@ export function convertCompletionEntry( let insertText = tsEntry.insertText let commitCharacters = getCommitCharacters(tsEntry, context) + let tags: CompletionItemTag[] if (tsEntry.isImportStatementCompletion) { insertText = label @@ -75,6 +77,10 @@ export function convertCompletionEntry( label += '?' } + if (kindModifiers.has(PConst.KindModifiers.deprecated)) { + tags = [CompletionItemTag.Deprecated] + } + if (kindModifiers.has(PConst.KindModifiers.color)) { kind = CompletionItemKind.Color } @@ -97,6 +103,7 @@ export function convertCompletionEntry( insertText, textEdit, kind, + tags, preselect, insertTextFormat, sortText,