diff --git a/src/server/features/completionItemProvider.ts b/src/server/features/completionItemProvider.ts index 49060fd..66d8392 100644 --- a/src/server/features/completionItemProvider.ts +++ b/src/server/features/completionItemProvider.ts @@ -344,7 +344,7 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP if (!this.completeOption.importStatementSuggestions || !this.client.apiVersion.lt(API.v430)) { return false } - return pre === 'import '; + return pre === 'import ' } return true diff --git a/src/server/features/documentSymbol.ts b/src/server/features/documentSymbol.ts index 6bb4110..98a4586 100644 --- a/src/server/features/documentSymbol.ts +++ b/src/server/features/documentSymbol.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { TextDocument } from 'coc.nvim' import { DocumentSymbolProvider } from 'coc.nvim' -import { CancellationToken, DocumentSymbol, Range, SymbolKind } from 'vscode-languageserver-protocol' +import { CancellationToken, DocumentSymbol, Range, SymbolKind, SymbolTag } from 'vscode-languageserver-protocol' import * as Proto from '../protocol' import * as PConst from '../protocol.const' import { ITypeScriptServiceClient } from '../typescriptService' @@ -82,20 +82,15 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP } private static convertNavTree( - bucket: DocumentSymbol[], + output: DocumentSymbol[], item: Proto.NavigationTree, ): boolean { let shouldInclude = TypeScriptDocumentSymbolProvider.shouldInclueEntry(item) const children = new Set(item.childItems || []) for (const span of item.spans) { const range = typeConverters.Range.fromTextSpan(span) - const symbolInfo = DocumentSymbol.create( - item.text, - '', - getSymbolKind(item.kind), - range, - range) - symbolInfo.children = children.size > 0 ? [] : null + const symbolInfo = TypeScriptDocumentSymbolProvider.convertSymbol(item, range) + if (children.size) symbolInfo.children = [] for (const child of children) { if (child.spans.some(span => !!containsRange(range, typeConverters.Range.fromTextSpan(span)))) { @@ -106,13 +101,33 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP } if (shouldInclude) { - bucket.push(symbolInfo) + output.push(symbolInfo) } } - return shouldInclude } + private static convertSymbol(item: Proto.NavigationTree, range: Range): DocumentSymbol { + const selectionRange = item.nameSpan ? typeConverters.Range.fromTextSpan(item.nameSpan) : range + let label = item.text + switch (item.kind) { + case PConst.Kind.memberGetAccessor: label = `(get) ${label}`; break + case PConst.Kind.memberSetAccessor: label = `(set) ${label}`; break + } + const symbolInfo = DocumentSymbol.create( + label, + '', + getSymbolKind(item.kind), + range, + containsRange(range, selectionRange) ? selectionRange : range) + + const kindModifiers = parseKindModifier(item.kindModifiers) + if (kindModifiers.has(PConst.KindModifiers.deprecated)) { + symbolInfo.tags = [SymbolTag.Deprecated] + } + return symbolInfo + } + private static shouldInclueEntry( item: Proto.NavigationTree | Proto.NavigationBarItem ): boolean { @@ -142,3 +157,7 @@ function containsRange(range: Range, otherRange: Range): boolean { } return true } + +function parseKindModifier(kindModifiers: string): Set { + return new Set(kindModifiers.split(/,|\s+/g)) +} diff --git a/src/server/protocol.const.ts b/src/server/protocol.const.ts index 546f136..418fbf4 100644 --- a/src/server/protocol.const.ts +++ b/src/server/protocol.const.ts @@ -60,7 +60,7 @@ export class KindModifiers { KindModifiers.tsxFile, KindModifiers.jsFile, KindModifiers.jsxFile, - KindModifiers.jsonFile, + KindModifiers.jsonFile ] } @@ -72,3 +72,19 @@ export class DisplayPartKind { public static readonly punctuation = 'punctuation' public static readonly text = 'text' } + +export enum EventName { + syntaxDiag = 'syntaxDiag', + semanticDiag = 'semanticDiag', + suggestionDiag = 'suggestionDiag', + configFileDiag = 'configFileDiag', + telemetry = 'telemetry', + projectLanguageServiceState = 'projectLanguageServiceState', + projectsUpdatedInBackground = 'projectsUpdatedInBackground', + beginInstallTypes = 'beginInstallTypes', + endInstallTypes = 'endInstallTypes', + typesInstallerInitializationFailed = 'typesInstallerInitializationFailed', + surveyReady = 'surveyReady', + projectLoadingStart = 'projectLoadingStart', + projectLoadingFinish = 'projectLoadingFinish' +}