Skip to content

Commit 583509f

Browse files
authored
fix: update VLS context type argumentation (#769)
1 parent 094f819 commit 583509f

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/volar/utils/augment-vls-ctx.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type { Code } from '@vue/language-core'
88
*/
99
export function augmentVlsCtx(content: Code[], codes: Code[]) {
1010
let from = -1
11-
let to = -1
1211

1312
for (let i = 0; i < content.length; i++) {
1413
const code = content[i]
@@ -19,16 +18,24 @@ export function augmentVlsCtx(content: Code[], codes: Code[]) {
1918

2019
if (from === -1 && code.startsWith(`const __VLS_ctx`)) {
2120
from = i
22-
} else if (from !== -1 && code === `}`) {
23-
to = i
24-
break
21+
} else if (from !== -1) {
22+
if (code === `}`) {
23+
content.splice(i, 0, ...codes.map((code) => `...${code},\n`))
24+
break
25+
} else if (code === `;\n`) {
26+
content.splice(
27+
from + 1,
28+
i - from,
29+
`{\n`,
30+
`...`,
31+
...content.slice(from + 1, i),
32+
`,\n`,
33+
...codes.map((code) => `...${code},\n`),
34+
`}`,
35+
`;\n`
36+
)
37+
break
38+
}
2539
}
2640
}
27-
28-
if (to === -1) {
29-
return
30-
}
31-
32-
// TODO: getCodes should return a Code[] type but unsure of how to build that
33-
content.splice(to, 0, ...codes.map((code) => `...${code},\n`))
3441
}

0 commit comments

Comments
 (0)