Use TS's document highlight API instead of references api to get highlights
Fixes #65921 Fixes #65051pull/65973/head
parent
7086fb76ec
commit
44b5a77632
|
@ -6,6 +6,7 @@
|
|||
import * as vscode from 'vscode';
|
||||
import * as Proto from '../protocol';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import { flatten } from '../utils/arrays';
|
||||
import * as typeConverters from '../utils/typeConverters';
|
||||
|
||||
class TypeScriptDocumentHighlightProvider implements vscode.DocumentHighlightProvider {
|
||||
|
@ -23,22 +24,27 @@ class TypeScriptDocumentHighlightProvider implements vscode.DocumentHighlightPro
|
|||
return [];
|
||||
}
|
||||
|
||||
const args = typeConverters.Position.toFileLocationRequestArgs(file, position);
|
||||
const response = await this.client.execute('references', args, token);
|
||||
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 response.body.refs
|
||||
.filter(ref => ref.file === file)
|
||||
.map(documentHighlightFromReference);
|
||||
return flatten(
|
||||
response.body
|
||||
.filter(highlight => highlight.file === file)
|
||||
.map(convertDocumentHighlight));
|
||||
}
|
||||
}
|
||||
|
||||
function documentHighlightFromReference(reference: Proto.ReferencesResponseItem): vscode.DocumentHighlight {
|
||||
return new vscode.DocumentHighlight(
|
||||
typeConverters.Range.fromTextSpan(reference),
|
||||
reference.isWriteAccess ? vscode.DocumentHighlightKind.Write : vscode.DocumentHighlightKind.Read);
|
||||
function convertDocumentHighlight(highlight: Proto.DocumentHighlightsItem): ReadonlyArray<vscode.DocumentHighlight> {
|
||||
return highlight.highlightSpans.map(span =>
|
||||
new vscode.DocumentHighlight(
|
||||
typeConverters.Range.fromTextSpan(span),
|
||||
span.kind === 'writtenReference' ? vscode.DocumentHighlightKind.Write : vscode.DocumentHighlightKind.Read));
|
||||
}
|
||||
|
||||
export function register(
|
||||
|
|
|
@ -34,6 +34,7 @@ interface TypeScriptRequestTypes {
|
|||
'definition': [Proto.FileLocationRequestArgs, Proto.DefinitionResponse];
|
||||
'definitionAndBoundSpan': [Proto.FileLocationRequestArgs, Proto.DefinitionInfoAndBoundSpanReponse];
|
||||
'docCommentTemplate': [Proto.FileLocationRequestArgs, Proto.DocCommandTemplateResponse];
|
||||
'documentHighlights': [Proto.DocumentHighlightsRequestArgs, Proto.DocumentHighlightsResponse];
|
||||
'format': [Proto.FormatRequestArgs, Proto.FormatResponse];
|
||||
'formatonkey': [Proto.FormatOnKeyRequestArgs, Proto.FormatResponse];
|
||||
'getApplicableRefactors': [Proto.GetApplicableRefactorsRequestArgs, Proto.GetApplicableRefactorsResponse];
|
||||
|
|
Loading…
Reference in New Issue