/
fileRename.ts
41 lines (29 loc) · 934 Bytes
/
fileRename.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 type { LanguageServiceRuntimeContext } from '../types';
import { embeddedEditToSourceEdit } from './rename';
import type * as _ from 'vscode-languageserver-protocol';
import * as dedupe from '../utils/dedupe';
export function register(context: LanguageServiceRuntimeContext) {
return async (oldUri: string, newUri: string) => {
const vueDocument = context.vueDocuments.get(oldUri);
if (vueDocument) {
oldUri += '.ts';
newUri += '.ts';
}
const plugins = context.getPlugins();
for (const plugin of plugins) {
if (!plugin.doFileRename)
continue;
const workspaceEdit = await plugin.doFileRename(oldUri, newUri);
if (workspaceEdit) {
const result = embeddedEditToSourceEdit(
workspaceEdit,
context.vueDocuments,
);
if (result?.documentChanges) {
result.documentChanges = dedupe.withDocumentChanges(result.documentChanges);
}
return result;
}
}
};
}