-
-
Notifications
You must be signed in to change notification settings - Fork 371
/
middleware.ts
49 lines (48 loc) · 1.77 KB
/
middleware.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
43
44
45
46
47
48
49
import { middleware as baseMiddleware } from '@volar/vscode';
import { AttrNameCasing, TagNameCasing } from '@vue/language-server';
import * as vscode from 'vscode';
import type * as lsp from 'vscode-languageclient';
import { attrNameCasings, tagNameCasings } from './features/nameCasing';
export const middleware: lsp.Middleware = {
...baseMiddleware,
async resolveCodeAction(item, token, next) {
if (item.kind?.value === 'refactor.move.newFile.dumb') {
const inputName = await vscode.window.showInputBox({ value: (item as any).data.original.data.newName });
if (!inputName) {
return item; // cancel
}
(item as any).data.original.data.newName = inputName;
}
return await (baseMiddleware.resolveCodeAction?.(item, token, next) ?? next(item, token));
},
workspace: {
configuration(params, token, next) {
if (params.items.some(item => item.section === 'vue.complete.casing.props' || item.section === 'vue.complete.casing.tags')) {
return params.items.map(item => {
if (item.scopeUri) {
if (item.section === 'vue.complete.casing.tags') {
const tagNameCasing = tagNameCasings.get(item.scopeUri);
if (tagNameCasing === TagNameCasing.Kebab) {
return 'kebab';
}
else if (tagNameCasing === TagNameCasing.Pascal) {
return 'pascal';
}
}
else if (item.section === 'vue.complete.casing.props') {
const attrCase = attrNameCasings.get(item.scopeUri);
if (attrCase === AttrNameCasing.Kebab) {
return 'kebab';
}
if (attrCase === AttrNameCasing.Camel) {
return 'camel';
}
}
}
return vscode.workspace.getConfiguration(item.section, item.scopeUri ? vscode.Uri.parse(item.scopeUri) : undefined);
});
}
return next(params, token);
},
},
};