diff --git a/src/server/features/documentHighlight.ts b/src/server/features/documentHighlight.ts index 7ab549c..9e8572e 100644 --- a/src/server/features/documentHighlight.ts +++ b/src/server/features/documentHighlight.ts @@ -7,6 +7,7 @@ import { DocumentHighlightProvider } from 'coc.nvim/lib/provider' import Proto from '../protocol' import { ITypeScriptServiceClient } from '../typescriptService' import * as typeConverters from '../utils/typeConverters' +import { flatten } from '../../utils/arrays' export default class TypeScriptDocumentHighlightProvider implements DocumentHighlightProvider { public constructor(private readonly client: ITypeScriptServiceClient) { } @@ -19,30 +20,28 @@ export default class TypeScriptDocumentHighlightProvider implements DocumentHigh const file = this.client.toPath(resource.uri) if (!file) return [] - const args = typeConverters.Position.toFileLocationRequestArgs( - file, - position - ) - try { - const response = await this.client.execute('occurrences', args, token) - if (response.type == 'response' && response.body) { - return response.body - .filter(x => !x.isInString) - .map(documentHighlightFromOccurance) - } - } catch { - // noop + const args = { + ...typeConverters.Position.toFileLocationRequestArgs(file, position), + filesToSearch: [file] + } + const response = await this.client.execute('documentHighlights', args, token) + if (response.type !== 'response' || !response.body) { + return [] } - return [] + return flatten( + response.body + .filter(highlight => highlight.file === file) + .map(convertDocumentHighlight)) + } } -function documentHighlightFromOccurance( - occurrence: Proto.OccurrencesResponseItem // tslint:disable-line -): DocumentHighlight { - return { - range: typeConverters.Range.fromTextSpan(occurrence), - kind: occurrence.isWriteAccess ? DocumentHighlightKind.Write : DocumentHighlightKind.Read - } +function convertDocumentHighlight(highlight: Proto.DocumentHighlightsItem): ReadonlyArray { + return highlight.highlightSpans.map(span => { + return { + range: typeConverters.Range.fromTextSpan(span), + kind: span.kind === 'writtenReference' ? DocumentHighlightKind.Write : DocumentHighlightKind.Read + } + }) } diff --git a/src/server/typescriptService.ts b/src/server/typescriptService.ts index e630c10..23f2b86 100644 --- a/src/server/typescriptService.ts +++ b/src/server/typescriptService.ts @@ -55,13 +55,12 @@ export interface TypeScriptRequestTypes { 'jsxClosingTag': [Proto.JsxClosingTagRequestArgs, Proto.JsxClosingTagResponse] 'navto': [Proto.NavtoRequestArgs, Proto.NavtoResponse] 'navtree': [Proto.FileRequestArgs, Proto.NavTreeResponse] - // tslint:disable-next-line: deprecation - 'occurrences': [Proto.FileLocationRequestArgs, Proto.OccurrencesResponse] 'organizeImports': [Proto.OrganizeImportsRequestArgs, Proto.OrganizeImportsResponse] 'projectInfo': [Proto.ProjectInfoRequestArgs, Proto.ProjectInfoResponse] 'quickinfo': [Proto.FileLocationRequestArgs, Proto.QuickInfoResponse] 'references': [Proto.FileLocationRequestArgs, Proto.ReferencesResponse] 'rename': [Proto.RenameRequestArgs, Proto.RenameResponse] + 'selectionRange': [Proto.SelectionRangeRequestArgs, Proto.SelectionRangeResponse] 'signatureHelp': [Proto.SignatureHelpRequestArgs, Proto.SignatureHelpResponse] 'typeDefinition': [Proto.FileLocationRequestArgs, Proto.TypeDefinitionResponse] }