Merge pull request #3619 from jakebailey/replace-occurrences
Replace occurrences with highlightspull/3618/head
commit
6f4b37e3fa
|
@ -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
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>;
|
||||
|
||||
/**
|
||||
|
|
|
@ -86,7 +86,7 @@ function setupMode(
|
|||
providers.push(
|
||||
languages.registerDocumentHighlightProvider(
|
||||
modeId,
|
||||
new languageFeatures.OccurrencesAdapter(worker)
|
||||
new languageFeatures.DocumentHighlightAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue