-
-
Notifications
You must be signed in to change notification settings - Fork 371
/
colorPresentations.ts
52 lines (40 loc) · 1.47 KB
/
colorPresentations.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { DocumentServiceRuntimeContext } from '../types';
import { documentArgFeatureWorker } from '../utils/featureWorkers';
import type { TextDocument } from 'vscode-languageserver-textdocument';
import * as vscode from 'vscode-languageserver-protocol';
import * as shared from '@volar/shared';
export function register(context: DocumentServiceRuntimeContext) {
return (document: TextDocument, color: vscode.Color, range: vscode.Range) => {
return documentArgFeatureWorker(
context,
document,
range,
sourceMap => sourceMap.embeddedFile.capabilities.documentSymbol, // TODO: add color capabilitie setting
function* (range, sourceMap) {
for (const [mappedRange] of sourceMap.getMappedRanges(range.start, range.end)) {
yield mappedRange;
}
},
(plugin, document, range) => plugin.getColorPresentations?.(document, color, range),
(data, sourceMap) => data.map(cp => {
if (!sourceMap)
return cp;
if (cp.textEdit) {
const editRange = sourceMap.getSourceRange(cp.textEdit.range.start, cp.textEdit.range.end)?.[0];
if (!editRange)
return undefined;
cp.textEdit.range = editRange;
}
if (cp.additionalTextEdits) {
for (const textEdit of cp.additionalTextEdits) {
const editRange = sourceMap.getSourceRange(textEdit.range.start, textEdit.range.end)?.[0];
if (!editRange)
return undefined;
textEdit.range = editRange;
}
}
return cp;
}).filter(shared.notEmpty),
);
}
}