-
-
Notifications
You must be signed in to change notification settings - Fork 366
/
linkedEditingRanges.ts
38 lines (33 loc) · 1.08 KB
/
linkedEditingRanges.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
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, position: vscode.Position) => {
return documentArgFeatureWorker(
context,
document,
position,
sourceMap => true,
function* (position, sourceMap) {
for (const [mappedRange] of sourceMap.getMappedRanges(
position,
position,
data => !!data.capabilities.completion,
)) {
yield mappedRange.start;
}
},
(plugin, document, position) => plugin.findLinkedEditingRanges?.(document, position),
(data, sourceMap) => ({
wordPattern: data.wordPattern,
ranges: data.ranges.map(range => {
if (!sourceMap)
return range;
return sourceMap.getSourceRange(range.start, range.end)?.[0]
}).filter(shared.notEmpty),
}),
);
}
}