forked from vuejs/language-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-sfc-template.ts
53 lines (48 loc) · 1.2 KB
/
vue-sfc-template.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
50
51
52
53
import { VueLanguagePlugin } from '../sourceFile';
const presetInitialIndentBrackets: Record<string, [string, string] | undefined> = {
html: ['<template>', '</template>'],
pug: ['div', '\n'],
};
const plugin: VueLanguagePlugin = () => {
return {
getEmbeddedFileNames(fileName, sfc) {
if (sfc.template) {
return [fileName + '.template.' + sfc.template.lang];
}
return [];
},
resolveEmbeddedFile(fileName, sfc, embeddedFile) {
const match = embeddedFile.fileName.match(/^(.*)\.template\.([^.]+)$/);
if (match && sfc.template) {
embeddedFile.capabilities = {
diagnostics: true,
foldingRanges: true,
formatting: {
initialIndentBracket: presetInitialIndentBrackets[sfc.template.lang],
},
documentSymbol: true,
codeActions: true,
inlayHints: true,
};
embeddedFile.isTsHostFile = false;
embeddedFile.codeGen.addCode2(
sfc.template.content,
0,
{
vueTag: sfc.template.tag,
capabilities: {
basic: true,
references: true,
definitions: true,
diagnostic: true,
rename: true,
completion: true,
semanticTokens: true,
},
},
);
}
},
};
}
export = plugin;