Move DocumentLinkAdapter to /common/

This commit is contained in:
Alex Dima 2021-11-17 14:07:39 +01:00
parent 81023950c6
commit 89d05c5889
No known key found for this signature in database
GPG key ID: 39563C1504FDD0C9
3 changed files with 44 additions and 28 deletions

View file

@ -463,7 +463,7 @@ function toMarkedStringArray(
//#endregion
//#region
//#region DocumentHighlightAdapter
export interface ILanguageWorkerWithDocumentHighlights {
findDocumentHighlights(
@ -728,3 +728,38 @@ function toSymbolKind(kind: lsTypes.SymbolKind): languages.SymbolKind {
}
//#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