mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 15:05:39 +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 {
|
export class HoverAdapter<T extends ILanguageWorkerWithHover> implements languages.HoverProvider {
|
||||||
constructor(private _worker: WorkerAccessor<T>) {}
|
constructor(private readonly _worker: WorkerAccessor<T>) {}
|
||||||
|
|
||||||
provideHover(
|
provideHover(
|
||||||
model: editor.IReadOnlyModel,
|
model: editor.IReadOnlyModel,
|
||||||
|
|
@ -475,7 +475,7 @@ export interface ILanguageWorkerWithDocumentHighlights {
|
||||||
export class DocumentHighlightAdapter<T extends ILanguageWorkerWithDocumentHighlights>
|
export class DocumentHighlightAdapter<T extends ILanguageWorkerWithDocumentHighlights>
|
||||||
implements languages.DocumentHighlightProvider
|
implements languages.DocumentHighlightProvider
|
||||||
{
|
{
|
||||||
constructor(private _worker: WorkerAccessor<T>) {}
|
constructor(private readonly _worker: WorkerAccessor<T>) {}
|
||||||
|
|
||||||
public provideDocumentHighlights(
|
public provideDocumentHighlights(
|
||||||
model: editor.IReadOnlyModel,
|
model: editor.IReadOnlyModel,
|
||||||
|
|
@ -515,3 +515,77 @@ function toDocumentHighlightKind(
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#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(
|
providers.push(
|
||||||
languages.registerDefinitionProvider(
|
languages.registerDefinitionProvider(
|
||||||
languageId,
|
languageId,
|
||||||
new languageFeatures.DefinitionAdapter(worker)
|
new languageFeatures.CSSDefinitionAdapter(worker)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +58,7 @@ export function setupMode(defaults: LanguageServiceDefaults): IDisposable {
|
||||||
providers.push(
|
providers.push(
|
||||||
languages.registerReferenceProvider(
|
languages.registerReferenceProvider(
|
||||||
languageId,
|
languageId,
|
||||||
new languageFeatures.ReferenceAdapter(worker)
|
new languageFeatures.CSSReferenceAdapter(worker)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,9 @@ import {
|
||||||
fromRange,
|
fromRange,
|
||||||
CompletionAdapter,
|
CompletionAdapter,
|
||||||
HoverAdapter,
|
HoverAdapter,
|
||||||
DocumentHighlightAdapter
|
DocumentHighlightAdapter,
|
||||||
|
DefinitionAdapter,
|
||||||
|
ReferenceAdapter
|
||||||
} from '../common/lspLanguageFeatures';
|
} from '../common/lspLanguageFeatures';
|
||||||
|
|
||||||
export interface WorkerAccessor {
|
export interface WorkerAccessor {
|
||||||
|
|
@ -38,63 +40,9 @@ export class CSSHoverAdapter extends HoverAdapter<CSSWorker> {}
|
||||||
|
|
||||||
export class CSSDocumentHighlightAdapter extends DocumentHighlightAdapter<CSSWorker> {}
|
export class CSSDocumentHighlightAdapter extends DocumentHighlightAdapter<CSSWorker> {}
|
||||||
|
|
||||||
// --- definition ------
|
export class CSSDefinitionAdapter extends DefinitionAdapter<CSSWorker> {}
|
||||||
|
|
||||||
function toLocation(location: lsTypes.Location): languages.Location {
|
export class CSSReferenceAdapter extends ReferenceAdapter<CSSWorker> {}
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- rename ------
|
// --- rename ------
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue