-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
index.js
46 lines (44 loc) · 1.28 KB
/
index.js
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
const plugin = () => {
return {
getEmbeddedFileNames(fileName, sfc) {
const fileNames = []
for (let i = 0; i < sfc.customBlocks.length; i++) {
const block = sfc.customBlocks[i]
if (block.type === 'route' && block.lang === 'ts') {
fileNames.push(`${fileName}.route_${i}.${block.lang}`)
}
}
return fileNames
},
resolveEmbeddedFile(fileName, sfc, embeddedFile) {
const match = embeddedFile.fileName.match(/^(.*)\.route_(\d+)\.([^.]+)$/)
if (match) {
const index = parseInt(match[2])
const block = sfc.customBlocks[index]
embeddedFile.capabilities = {
diagnostics: true,
foldingRanges: true,
formatting: true,
documentSymbol: true,
codeActions: true,
inlayHints: true,
}
embeddedFile.isTsHostFile = true
embeddedFile.codeGen.addCode2(block.content, 0, {
vueTag: 'customBlock',
vueTagIndex: index,
capabilities: {
basic: true,
references: true,
definitions: true,
diagnostic: true,
rename: true,
completion: true,
semanticTokens: true,
},
})
}
},
}
}
export default plugin