-
-
Notifications
You must be signed in to change notification settings - Fork 371
/
renamePrepare.ts
42 lines (35 loc) · 1.03 KB
/
renamePrepare.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
import * as vscode from 'vscode-languageserver-protocol';
import type { LanguageServiceRuntimeContext } from '../types';
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.rename,
)) {
yield mappedRange.start;
}
},
(plugin, document, position) => plugin.doRenamePrepare?.(document, position),
(data, sourceMap) => {
if (sourceMap && vscode.Range.is(data))
return sourceMap.getSourceRange(data.start, data.end)?.[0];
return data;
},
prepares => {
for (const prepare of prepares) {
if (vscode.Range.is(prepare)) {
return prepare; // if has any valid range, ignore other errors
}
}
return prepares[0];
},
);
}
}