mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 20:52:56 +01:00
Extract a common DocumentHighlightAdapter
This commit is contained in:
parent
ca17e09d53
commit
09c6ea48f0
5 changed files with 62 additions and 85 deletions
|
|
@ -19,7 +19,8 @@ import {
|
|||
toTextEdit,
|
||||
fromRange,
|
||||
CompletionAdapter,
|
||||
HoverAdapter
|
||||
HoverAdapter,
|
||||
DocumentHighlightAdapter
|
||||
} from '../common/lspLanguageFeatures';
|
||||
|
||||
export interface WorkerAccessor {
|
||||
|
|
@ -36,45 +37,7 @@ export class HTMLHoverAdapter extends HoverAdapter<HTMLWorker> {}
|
|||
|
||||
// --- document highlights ------
|
||||
|
||||
function toDocumentHighlightKind(
|
||||
kind: lsTypes.DocumentHighlightKind
|
||||
): languages.DocumentHighlightKind {
|
||||
switch (kind) {
|
||||
case lsTypes.DocumentHighlightKind.Read:
|
||||
return languages.DocumentHighlightKind.Read;
|
||||
case lsTypes.DocumentHighlightKind.Write:
|
||||
return languages.DocumentHighlightKind.Write;
|
||||
case lsTypes.DocumentHighlightKind.Text:
|
||||
return languages.DocumentHighlightKind.Text;
|
||||
}
|
||||
return languages.DocumentHighlightKind.Text;
|
||||
}
|
||||
|
||||
export class DocumentHighlightAdapter implements languages.DocumentHighlightProvider {
|
||||
constructor(private _worker: WorkerAccessor) {}
|
||||
|
||||
public provideDocumentHighlights(
|
||||
model: editor.IReadOnlyModel,
|
||||
position: Position,
|
||||
token: CancellationToken
|
||||
): Promise<languages.DocumentHighlight[]> {
|
||||
const resource = model.uri;
|
||||
|
||||
return this._worker(resource)
|
||||
.then((worker) => worker.findDocumentHighlights(resource.toString(), fromPosition(position)))
|
||||
.then((entries) => {
|
||||
if (!entries) {
|
||||
return;
|
||||
}
|
||||
return entries.map((entry) => {
|
||||
return <languages.DocumentHighlight>{
|
||||
range: toRange(entry.range),
|
||||
kind: toDocumentHighlightKind(entry.kind)
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
export class HTMLDocumentHighlightAdapter extends DocumentHighlightAdapter<HTMLWorker> {}
|
||||
|
||||
function toWorkspaceEdit(edit: lsTypes.WorkspaceEdit): languages.WorkspaceEdit {
|
||||
if (!edit || !edit.changes) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue