mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 19:42:56 +01:00
Extract a common DocumentColorAdapter
This commit is contained in:
parent
3cb8acd2e9
commit
8d7bf2ad76
6 changed files with 79 additions and 132 deletions
|
|
@ -11,15 +11,14 @@ import {
|
|||
DiagnosticsAdapter,
|
||||
fromPosition,
|
||||
toRange,
|
||||
toTextEdit,
|
||||
fromRange,
|
||||
CompletionAdapter,
|
||||
HoverAdapter,
|
||||
DocumentHighlightAdapter,
|
||||
DefinitionAdapter,
|
||||
ReferenceAdapter,
|
||||
RenameAdapter,
|
||||
DocumentSymbolAdapter
|
||||
DocumentSymbolAdapter,
|
||||
DocumentColorAdapter
|
||||
} from '../common/lspLanguageFeatures';
|
||||
|
||||
export interface WorkerAccessor {
|
||||
|
|
@ -50,59 +49,7 @@ export class CSSRenameAdapter extends RenameAdapter<CSSWorker> {}
|
|||
|
||||
export class CSSDocumentSymbolAdapter extends DocumentSymbolAdapter<CSSWorker> {}
|
||||
|
||||
export class DocumentColorAdapter implements languages.DocumentColorProvider {
|
||||
constructor(private _worker: WorkerAccessor) {}
|
||||
|
||||
public provideDocumentColors(
|
||||
model: editor.IReadOnlyModel,
|
||||
token: CancellationToken
|
||||
): Promise<languages.IColorInformation[] | undefined> {
|
||||
const resource = model.uri;
|
||||
|
||||
return this._worker(resource)
|
||||
.then((worker) => worker.findDocumentColors(resource.toString()))
|
||||
.then((infos) => {
|
||||
if (!infos) {
|
||||
return;
|
||||
}
|
||||
return infos.map((item) => ({
|
||||
color: item.color,
|
||||
range: toRange(item.range)
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public provideColorPresentations(
|
||||
model: editor.IReadOnlyModel,
|
||||
info: languages.IColorInformation,
|
||||
token: CancellationToken
|
||||
): Promise<languages.IColorPresentation[] | undefined> {
|
||||
const resource = model.uri;
|
||||
|
||||
return this._worker(resource)
|
||||
.then((worker) =>
|
||||
worker.getColorPresentations(resource.toString(), info.color, fromRange(info.range))
|
||||
)
|
||||
.then((presentations) => {
|
||||
if (!presentations) {
|
||||
return;
|
||||
}
|
||||
return presentations.map((presentation) => {
|
||||
let item: languages.IColorPresentation = {
|
||||
label: presentation.label
|
||||
};
|
||||
if (presentation.textEdit) {
|
||||
item.textEdit = toTextEdit(presentation.textEdit);
|
||||
}
|
||||
if (presentation.additionalTextEdits) {
|
||||
item.additionalTextEdits =
|
||||
presentation.additionalTextEdits.map<languages.TextEdit>(toTextEdit);
|
||||
}
|
||||
return item;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
export class CSSDocumentColorAdapter extends DocumentColorAdapter<CSSWorker> {}
|
||||
|
||||
export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
|
||||
constructor(private _worker: WorkerAccessor) {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue