use new API for documentHighlight
This commit is contained in:
parent
046670f54b
commit
a3d81e2cb8
2 changed files with 21 additions and 23 deletions
|
@ -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)
|
||||
const args = {
|
||||
...typeConverters.Position.toFileLocationRequestArgs(file, position),
|
||||
filesToSearch: [file]
|
||||
}
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
|
||||
const response = await this.client.execute('documentHighlights', args, token)
|
||||
if (response.type !== 'response' || !response.body) {
|
||||
return []
|
||||
}
|
||||
|
||||
return flatten(
|
||||
response.body
|
||||
.filter(highlight => highlight.file === file)
|
||||
.map(convertDocumentHighlight))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function documentHighlightFromOccurance(
|
||||
occurrence: Proto.OccurrencesResponseItem // tslint:disable-line
|
||||
): DocumentHighlight {
|
||||
function convertDocumentHighlight(highlight: Proto.DocumentHighlightsItem): ReadonlyArray<DocumentHighlight> {
|
||||
return highlight.highlightSpans.map(span => {
|
||||
return {
|
||||
range: typeConverters.Range.fromTextSpan(occurrence),
|
||||
kind: occurrence.isWriteAccess ? DocumentHighlightKind.Write : DocumentHighlightKind.Read
|
||||
range: typeConverters.Range.fromTextSpan(span),
|
||||
kind: span.kind === 'writtenReference' ? DocumentHighlightKind.Write : DocumentHighlightKind.Read
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue