-
-
Notifications
You must be signed in to change notification settings - Fork 371
/
documentHighlights.ts
41 lines (35 loc) · 1.02 KB
/
documentHighlights.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
import * as vscode from 'vscode-languageserver-protocol';
import type { LanguageServiceRuntimeContext } from '../types';
import * as shared from '@volar/shared';
import { languageFeatureWorker } from '../utils/featureWorkers';
export function register(context: LanguageServiceRuntimeContext) {
return (uri: string, position: vscode.Position) => {
return languageFeatureWorker(
context,
uri,
position,
function* (position, sourceMap) {
for (const [mappedRange] of sourceMap.getMappedRanges(
position,
position,
data => !!data.capabilities.basic,
)) {
yield mappedRange.start;
}
},
(plugin, document, position) => plugin.findDocumentHighlights?.(document, position),
(data, sourceMap) => data.map(highlisht => {
if (!sourceMap)
return highlisht;
const range = sourceMap.getSourceRange(highlisht.range.start, highlisht.range.end)?.[0];
if (range) {
return {
...highlisht,
range,
};
}
}).filter(shared.notEmpty),
arr => arr.flat(),
);
}
}