forked from vuejs/language-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-sfc-scripts.ts
46 lines (42 loc) · 1.16 KB
/
vue-sfc-scripts.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
import { VueLanguagePlugin } from '../sourceFile';
const plugin: VueLanguagePlugin = () => {
return {
getEmbeddedFileNames(fileName, sfc) {
const names: string[] = [];
if (sfc.script) {
names.push(fileName + '.script_format.' + sfc.script.lang);
}
if (sfc.scriptSetup) {
names.push(fileName + '.scriptSetup_format.' + sfc.scriptSetup.lang);
}
return names;
},
resolveEmbeddedFile(fileName, sfc, embeddedFile) {
const scriptMatch = embeddedFile.fileName.match(/^(.*)\.script_format\.([^.]+)$/);
const scriptSetupMatch = embeddedFile.fileName.match(/^(.*)\.scriptSetup_format\.([^.]+)$/);
const script = scriptMatch ? sfc.script : scriptSetupMatch ? sfc.scriptSetup : undefined;
if (script) {
embeddedFile.capabilities = {
diagnostics: false,
foldingRanges: true,
formatting: {
initialIndentBracket: ['{', '}'],
},
documentSymbol: true,
codeActions: false,
inlayHints: false,
};
embeddedFile.isTsHostFile = false;
embeddedFile.codeGen.addCode2(
script.content,
0,
{
vueTag: script.tag,
capabilities: {},
},
);
}
},
};
}
export = plugin;