|
1 | 1 | import type { Language, VueCompilerOptions } from '@vue/language-core' |
2 | | -import { FileMap, createLanguage, createVueLanguagePlugin, defaultMapperFactory, resolveVueCompilerOptions } from '@vue/language-core' |
| 2 | +import { FileMap, createLanguage, createVueLanguagePlugin, defaultMapperFactory, resolveVueCompilerOptions, setupGlobalTypes } from '@vue/language-core' |
3 | 3 | import type { CompilerOptions } from 'typescript' |
4 | 4 | import ts from 'typescript' |
5 | 5 | import type { |
@@ -65,7 +65,9 @@ export function createTwoslasher(createOptions: CreateTwoslashVueOptions = {}): |
65 | 65 | return cache.get(key)! |
66 | 66 |
|
67 | 67 | function getLanguage() { |
68 | | - const vueLanguagePlugin = createVueLanguagePlugin<string>(ts, id => id, () => '', () => true, defaultCompilerOptions, resolveVueCompilerOptions(vueCompilerOptions)) |
| 68 | + const resolvedVueOptions = resolveVueCompilerOptions(vueCompilerOptions) |
| 69 | + resolvedVueOptions.__setupedGlobalTypes = setupGlobalTypes(ts.sys.getCurrentDirectory(), resolvedVueOptions, ts.sys) |
| 70 | + const vueLanguagePlugin = createVueLanguagePlugin<string>(ts, defaultCompilerOptions, resolvedVueOptions, id => id) |
69 | 71 | return createLanguage( |
70 | 72 | [vueLanguagePlugin], |
71 | 73 | new FileMap(ts.sys.useCaseSensitiveFileNames), |
@@ -138,9 +140,8 @@ export function createTwoslasher(createOptions: CreateTwoslashVueOptions = {}): |
138 | 140 |
|
139 | 141 | const lang = getVueLanguage(compilerOptions, vueCompilerOptions) |
140 | 142 | const sourceScript = lang.scripts.set('index.vue', ts.ScriptSnapshot.fromString(strippedCode))! |
141 | | - const fileCompiled = get(sourceScript.generated!.embeddedCodes.values(), 1)! |
| 143 | + const fileCompiled = get(sourceScript.generated!.embeddedCodes.values(), 2)! |
142 | 144 | const compiled = fileCompiled.snapshot.getText(0, fileCompiled.snapshot.getLength()) |
143 | | - .replace(/(?=export const __VLS_globalTypesStart)/, '// ---cut-after---\n') |
144 | 145 |
|
145 | 146 | const map = defaultMapperFactory(fileCompiled.mappings) |
146 | 147 |
|
|
0 commit comments