mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 23:13:02 +01:00
Move DocumentLinkAdapter to /common/
This commit is contained in:
parent
81023950c6
commit
89d05c5889
3 changed files with 44 additions and 28 deletions
|
|
@ -463,7 +463,7 @@ function toMarkedStringArray(
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region
|
//#region DocumentHighlightAdapter
|
||||||
|
|
||||||
export interface ILanguageWorkerWithDocumentHighlights {
|
export interface ILanguageWorkerWithDocumentHighlights {
|
||||||
findDocumentHighlights(
|
findDocumentHighlights(
|
||||||
|
|
@ -728,3 +728,38 @@ function toSymbolKind(kind: lsTypes.SymbolKind): languages.SymbolKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
//#region DocumentLinkAdapter
|
||||||
|
|
||||||
|
export interface ILanguageWorkerWithDocumentLinks {
|
||||||
|
findDocumentLinks(uri: string): Promise<lsTypes.DocumentLink[]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DocumentLinkAdapter<T extends ILanguageWorkerWithDocumentLinks>
|
||||||
|
implements languages.LinkProvider
|
||||||
|
{
|
||||||
|
constructor(private _worker: WorkerAccessor<T>) {}
|
||||||
|
|
||||||
|
public provideLinks(
|
||||||
|
model: editor.IReadOnlyModel,
|
||||||
|
token: CancellationToken
|
||||||
|
): Promise<languages.ILinksList> {
|
||||||
|
const resource = model.uri;
|
||||||
|
|
||||||
|
return this._worker(resource)
|
||||||
|
.then((worker) => worker.findDocumentLinks(resource.toString()))
|
||||||
|
.then((items) => {
|
||||||
|
if (!items) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
links: items.map((item) => ({
|
||||||
|
range: toRange(item.range),
|
||||||
|
url: item.target
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ export function setupMode1(defaults: LanguageServiceDefaults): void {
|
||||||
languageId,
|
languageId,
|
||||||
new languageFeatures.HTMLDocumentHighlightAdapter(worker)
|
new languageFeatures.HTMLDocumentHighlightAdapter(worker)
|
||||||
);
|
);
|
||||||
languages.registerLinkProvider(languageId, new languageFeatures.DocumentLinkAdapter(worker));
|
languages.registerLinkProvider(languageId, new languageFeatures.HTMLDocumentLinkAdapter(worker));
|
||||||
languages.registerFoldingRangeProvider(
|
languages.registerFoldingRangeProvider(
|
||||||
languageId,
|
languageId,
|
||||||
new languageFeatures.FoldingRangeAdapter(worker)
|
new languageFeatures.FoldingRangeAdapter(worker)
|
||||||
|
|
@ -96,7 +96,10 @@ export function setupMode(defaults: LanguageServiceDefaults): IDisposable {
|
||||||
}
|
}
|
||||||
if (modeConfiguration.links) {
|
if (modeConfiguration.links) {
|
||||||
providers.push(
|
providers.push(
|
||||||
languages.registerLinkProvider(languageId, new languageFeatures.DocumentLinkAdapter(worker))
|
languages.registerLinkProvider(
|
||||||
|
languageId,
|
||||||
|
new languageFeatures.HTMLDocumentLinkAdapter(worker)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (modeConfiguration.documentSymbols) {
|
if (modeConfiguration.documentSymbols) {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@ import {
|
||||||
HoverAdapter,
|
HoverAdapter,
|
||||||
DocumentHighlightAdapter,
|
DocumentHighlightAdapter,
|
||||||
RenameAdapter,
|
RenameAdapter,
|
||||||
DocumentSymbolAdapter
|
DocumentSymbolAdapter,
|
||||||
|
DocumentLinkAdapter
|
||||||
} from '../common/lspLanguageFeatures';
|
} from '../common/lspLanguageFeatures';
|
||||||
|
|
||||||
export interface WorkerAccessor {
|
export interface WorkerAccessor {
|
||||||
|
|
@ -43,30 +44,7 @@ export class HTMLRenameAdapter extends RenameAdapter<HTMLWorker> {}
|
||||||
|
|
||||||
export class HTMLDocumentSymbolAdapter extends DocumentSymbolAdapter<HTMLWorker> {}
|
export class HTMLDocumentSymbolAdapter extends DocumentSymbolAdapter<HTMLWorker> {}
|
||||||
|
|
||||||
export class DocumentLinkAdapter implements languages.LinkProvider {
|
export class HTMLDocumentLinkAdapter extends DocumentLinkAdapter<HTMLWorker> {}
|
||||||
constructor(private _worker: WorkerAccessor) {}
|
|
||||||
|
|
||||||
public provideLinks(
|
|
||||||
model: editor.IReadOnlyModel,
|
|
||||||
token: CancellationToken
|
|
||||||
): Promise<languages.ILinksList> {
|
|
||||||
const resource = model.uri;
|
|
||||||
|
|
||||||
return this._worker(resource)
|
|
||||||
.then((worker) => worker.findDocumentLinks(resource.toString()))
|
|
||||||
.then((items) => {
|
|
||||||
if (!items) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
links: items.map((item) => ({
|
|
||||||
range: toRange(item.range),
|
|
||||||
url: item.target
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function fromFormattingOptions(options: languages.FormattingOptions): lsTypes.FormattingOptions {
|
function fromFormattingOptions(options: languages.FormattingOptions): lsTypes.FormattingOptions {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue