mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 11:35:40 +01:00
Move DefinitionAdapter and ReferenceAdapter to /common/
This commit is contained in:
parent
09c6ea48f0
commit
4b2441bf66
3 changed files with 83 additions and 61 deletions
|
|
@ -398,7 +398,7 @@ export interface ILanguageWorkerWithHover {
|
|||
}
|
||||
|
||||
export class HoverAdapter<T extends ILanguageWorkerWithHover> implements languages.HoverProvider {
|
||||
constructor(private _worker: WorkerAccessor<T>) {}
|
||||
constructor(private readonly _worker: WorkerAccessor<T>) {}
|
||||
|
||||
provideHover(
|
||||
model: editor.IReadOnlyModel,
|
||||
|
|
@ -475,7 +475,7 @@ export interface ILanguageWorkerWithDocumentHighlights {
|
|||
export class DocumentHighlightAdapter<T extends ILanguageWorkerWithDocumentHighlights>
|
||||
implements languages.DocumentHighlightProvider
|
||||
{
|
||||
constructor(private _worker: WorkerAccessor<T>) {}
|
||||
constructor(private readonly _worker: WorkerAccessor<T>) {}
|
||||
|
||||
public provideDocumentHighlights(
|
||||
model: editor.IReadOnlyModel,
|
||||
|
|
@ -515,3 +515,77 @@ function toDocumentHighlightKind(
|
|||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region DefinitionAdapter
|
||||
|
||||
export interface ILanguageWorkerWithDefinitions {
|
||||
findDefinition(uri: string, position: lsTypes.Position): Promise<lsTypes.Location>;
|
||||
}
|
||||
|
||||
export class DefinitionAdapter<T extends ILanguageWorkerWithDefinitions>
|
||||
implements languages.DefinitionProvider
|
||||
{
|
||||
constructor(private readonly _worker: WorkerAccessor<T>) {}
|
||||
|
||||
public provideDefinition(
|
||||
model: editor.IReadOnlyModel,
|
||||
position: Position,
|
||||
token: CancellationToken
|
||||
): Promise<languages.Definition> {
|
||||
const resource = model.uri;
|
||||
|
||||
return this._worker(resource)
|
||||
.then((worker) => {
|
||||
return worker.findDefinition(resource.toString(), fromPosition(position));
|
||||
})
|
||||
.then((definition) => {
|
||||
if (!definition) {
|
||||
return;
|
||||
}
|
||||
return [toLocation(definition)];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function toLocation(location: lsTypes.Location): languages.Location {
|
||||
return {
|
||||
uri: Uri.parse(location.uri),
|
||||
range: toRange(location.range)
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region ReferenceAdapter
|
||||
|
||||
export interface ILanguageWorkerWithReferences {
|
||||
findReferences(uri: string, position: lsTypes.Position): Promise<lsTypes.Location[]>;
|
||||
}
|
||||
|
||||
export class ReferenceAdapter<T extends ILanguageWorkerWithReferences>
|
||||
implements languages.ReferenceProvider
|
||||
{
|
||||
constructor(private readonly _worker: WorkerAccessor<T>) {}
|
||||
|
||||
provideReferences(
|
||||
model: editor.IReadOnlyModel,
|
||||
position: Position,
|
||||
context: languages.ReferenceContext,
|
||||
token: CancellationToken
|
||||
): Promise<languages.Location[]> {
|
||||
const resource = model.uri;
|
||||
|
||||
return this._worker(resource)
|
||||
.then((worker) => {
|
||||
return worker.findReferences(resource.toString(), fromPosition(position));
|
||||
})
|
||||
.then((entries) => {
|
||||
if (!entries) {
|
||||
return;
|
||||
}
|
||||
return entries.map(toLocation);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ export function setupMode(defaults: LanguageServiceDefaults): IDisposable {
|
|||
providers.push(
|
||||
languages.registerDefinitionProvider(
|
||||
languageId,
|
||||
new languageFeatures.DefinitionAdapter(worker)
|
||||
new languageFeatures.CSSDefinitionAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ export function setupMode(defaults: LanguageServiceDefaults): IDisposable {
|
|||
providers.push(
|
||||
languages.registerReferenceProvider(
|
||||
languageId,
|
||||
new languageFeatures.ReferenceAdapter(worker)
|
||||
new languageFeatures.CSSReferenceAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ import {
|
|||
fromRange,
|
||||
CompletionAdapter,
|
||||
HoverAdapter,
|
||||
DocumentHighlightAdapter
|
||||
DocumentHighlightAdapter,
|
||||
DefinitionAdapter,
|
||||
ReferenceAdapter
|
||||
} from '../common/lspLanguageFeatures';
|
||||
|
||||
export interface WorkerAccessor {
|
||||
|
|
@ -38,63 +40,9 @@ export class CSSHoverAdapter extends HoverAdapter<CSSWorker> {}
|
|||
|
||||
export class CSSDocumentHighlightAdapter extends DocumentHighlightAdapter<CSSWorker> {}
|
||||
|
||||
// --- definition ------
|
||||
export class CSSDefinitionAdapter extends DefinitionAdapter<CSSWorker> {}
|
||||
|
||||
function toLocation(location: lsTypes.Location): languages.Location {
|
||||
return {
|
||||
uri: Uri.parse(location.uri),
|
||||
range: toRange(location.range)
|
||||
};
|
||||
}
|
||||
|
||||
export class DefinitionAdapter {
|
||||
constructor(private _worker: WorkerAccessor) {}
|
||||
|
||||
public provideDefinition(
|
||||
model: editor.IReadOnlyModel,
|
||||
position: Position,
|
||||
token: CancellationToken
|
||||
): Promise<languages.Definition> {
|
||||
const resource = model.uri;
|
||||
|
||||
return this._worker(resource)
|
||||
.then((worker) => {
|
||||
return worker.findDefinition(resource.toString(), fromPosition(position));
|
||||
})
|
||||
.then((definition) => {
|
||||
if (!definition) {
|
||||
return;
|
||||
}
|
||||
return [toLocation(definition)];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// --- references ------
|
||||
|
||||
export class ReferenceAdapter implements languages.ReferenceProvider {
|
||||
constructor(private _worker: WorkerAccessor) {}
|
||||
|
||||
provideReferences(
|
||||
model: editor.IReadOnlyModel,
|
||||
position: Position,
|
||||
context: languages.ReferenceContext,
|
||||
token: CancellationToken
|
||||
): Promise<languages.Location[]> {
|
||||
const resource = model.uri;
|
||||
|
||||
return this._worker(resource)
|
||||
.then((worker) => {
|
||||
return worker.findReferences(resource.toString(), fromPosition(position));
|
||||
})
|
||||
.then((entries) => {
|
||||
if (!entries) {
|
||||
return;
|
||||
}
|
||||
return entries.map(toLocation);
|
||||
});
|
||||
}
|
||||
}
|
||||
export class CSSReferenceAdapter extends ReferenceAdapter<CSSWorker> {}
|
||||
|
||||
// --- rename ------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue