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