mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 23:13:02 +01:00
Extract a common DocumentHighlightAdapter
This commit is contained in:
parent
ca17e09d53
commit
09c6ea48f0
5 changed files with 62 additions and 85 deletions
|
|
@ -14,7 +14,8 @@ import {
|
|||
toTextEdit,
|
||||
fromRange,
|
||||
CompletionAdapter,
|
||||
HoverAdapter
|
||||
HoverAdapter,
|
||||
DocumentHighlightAdapter
|
||||
} from '../common/lspLanguageFeatures';
|
||||
|
||||
export interface WorkerAccessor {
|
||||
|
|
@ -35,47 +36,7 @@ export class CSSCompletionAdapter extends CompletionAdapter<CSSWorker> {
|
|||
|
||||
export class CSSHoverAdapter extends HoverAdapter<CSSWorker> {}
|
||||
|
||||
// --- 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 CSSDocumentHighlightAdapter extends DocumentHighlightAdapter<CSSWorker> {}
|
||||
|
||||
// --- definition ------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue