-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathprovideDocumentColors.ts
More file actions
39 lines (38 loc) · 1.11 KB
/
provideDocumentColors.ts
File metadata and controls
39 lines (38 loc) · 1.11 KB
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
import { isColorEnabled } from '@volar/language-core';
import type * as vscode from 'vscode-languageserver-protocol';
import { type URI } from 'vscode-uri';
import type { LanguageServiceContext } from '../types';
import { NoneCancellationToken } from '../utils/cancellation';
import { documentFeatureWorker, getSourceRange } from '../utils/featureWorkers';
export function register(context: LanguageServiceContext) {
return (uri: URI, token = NoneCancellationToken) => {
return documentFeatureWorker(
context,
uri,
docs => docs[2].mappings.some(mapping => isColorEnabled(mapping.data)),
(plugin, document) => {
if (token.isCancellationRequested) {
return;
}
return plugin[1].provideDocumentColors?.(document, token);
},
(data, docs) => {
if (!docs) {
return data;
}
return data
.map<vscode.ColorInformation | undefined>(color => {
const range = getSourceRange(docs, color.range, isColorEnabled);
if (range) {
return {
range,
color: color.color,
};
}
})
.filter(color => !!color);
},
arr => arr.flat(),
);
};
}