Replace occurrences with highlights

pull/3619/head
Jake Bailey 2023-03-01 14:27:42 -08:00
parent 2b2e2a1eb7
commit 9d5d765fe4
4 changed files with 26 additions and 20 deletions

View File

@ -715,7 +715,10 @@ export class QuickInfoAdapter extends Adapter implements languages.HoverProvider
// --- occurrences ------
export class OccurrencesAdapter extends Adapter implements languages.DocumentHighlightProvider {
export class DocumentHighlightAdapter
extends Adapter
implements languages.DocumentHighlightProvider
{
public async provideDocumentHighlights(
model: editor.ITextModel,
position: Position,
@ -729,19 +732,24 @@ export class OccurrencesAdapter extends Adapter implements languages.DocumentHig
return;
}
const entries = await worker.getOccurrencesAtPosition(resource.toString(), offset);
const entries = await worker.getDocumentHighlights(resource.toString(), offset, [
resource.toString()
]);
if (!entries || model.isDisposed()) {
return;
}
return entries.map((entry) => {
return <languages.DocumentHighlight>{
range: this._textSpanToRange(model, entry.textSpan),
kind: entry.isWriteAccess
? languages.DocumentHighlightKind.Write
: languages.DocumentHighlightKind.Text
};
return entries.flatMap((entry) => {
return entry.highlightSpans.map((highlightSpans) => {
return <languages.DocumentHighlight>{
range: this._textSpanToRange(model, highlightSpans.textSpan),
kind:
highlightSpans.kind === 'writtenReference'
? languages.DocumentHighlightKind.Write
: languages.DocumentHighlightKind.Text
};
});
});
}
}

View File

@ -440,13 +440,10 @@ export interface TypeScriptWorker {
*/
getQuickInfoAtPosition(fileName: string, position: number): Promise<any | undefined>;
/**
* Get other ranges which are related to the item at the given position in the file (often used for highlighting).
* @returns `Promise<ReadonlyArray<typescript.ReferenceEntry> | undefined>`
*/
getOccurrencesAtPosition(
getDocumentHighlights(
fileName: string,
position: number
position: number,
filesToSearch: string[]
): Promise<ReadonlyArray<any> | undefined>;
/**

View File

@ -86,7 +86,7 @@ function setupMode(
providers.push(
languages.registerDocumentHighlightProvider(
modeId,
new languageFeatures.OccurrencesAdapter(worker)
new languageFeatures.DocumentHighlightAdapter(worker)
)
);
}

View File

@ -299,14 +299,15 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork
return this._languageService.getQuickInfoAtPosition(fileName, position);
}
async getOccurrencesAtPosition(
async getDocumentHighlights(
fileName: string,
position: number
): Promise<ReadonlyArray<ts.ReferenceEntry> | undefined> {
position: number,
filesToSearch: string[]
): Promise<ReadonlyArray<ts.DocumentHighlights> | undefined> {
if (fileNameIsLib(fileName)) {
return undefined;
}
return this._languageService.getOccurrencesAtPosition(fileName, position);
return this._languageService.getDocumentHighlights(fileName, position, filesToSearch);
}
async getDefinitionAtPosition(