support deprecated tag
This commit is contained in:
parent
5c7e44f36f
commit
8ba598b218
6 changed files with 50 additions and 10 deletions
10
package.json
10
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
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
|
|
@ -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<string> {
|
||||
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
|
||||
|
|
|
@ -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<boolean>('showUnused', true)
|
||||
const reportDeprecated = config.get<boolean>('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
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue