diff --git a/packages/component-meta/lib/base.ts b/packages/component-meta/lib/base.ts index 0a4edc3ad4..aeaa19ed5c 100644 --- a/packages/component-meta/lib/base.ts +++ b/packages/component-meta/lib/base.ts @@ -139,7 +139,12 @@ export function baseCreate( const fileExists = languageServiceHost.fileExists.bind(languageServiceHost); const getScriptSnapshot = languageServiceHost.getScriptSnapshot.bind(languageServiceHost); const globalTypesName = `${commandLine.vueOptions.lib}_${commandLine.vueOptions.target}_${commandLine.vueOptions.strictTemplates}.d.ts`; - const snapshots = new Map(); + const globalTypesContents = vue.generateGlobalTypes(commandLine.vueOptions.lib, commandLine.vueOptions.target, commandLine.vueOptions.strictTemplates); + const globalTypesSnapshot: ts.IScriptSnapshot = { + getText: (start, end) => globalTypesContents.substring(start, end), + getLength: () => globalTypesContents.length, + getChangeRange: () => undefined, + }; if (directoryExists) { languageServiceHost.directoryExists = path => { if (path.endsWith('.vue-global-types')) { @@ -149,22 +154,14 @@ export function baseCreate( }; } languageServiceHost.fileExists = path => { - if (path.endsWith(globalTypesName)) { + if (path.endsWith(`.vue-global-types/${globalTypesName}`) || path.endsWith(`.vue-global-types\\${globalTypesName}`)) { return true; } return fileExists(path); }; languageServiceHost.getScriptSnapshot = path => { if (path.endsWith(`.vue-global-types/${globalTypesName}`) || path.endsWith(`.vue-global-types\\${globalTypesName}`)) { - if (!snapshots.has(path)) { - const contents = vue.generateGlobalTypes(commandLine.vueOptions.lib, commandLine.vueOptions.target, commandLine.vueOptions.strictTemplates); - snapshots.set(path, { - getText: (start, end) => contents.substring(start, end), - getLength: () => contents.length, - getChangeRange: () => undefined, - }); - } - return snapshots.get(path)!; + return globalTypesSnapshot; } return getScriptSnapshot(path); }; diff --git a/packages/language-server/lib/initialize.ts b/packages/language-server/lib/initialize.ts index 54bae91e17..fe033942cd 100644 --- a/packages/language-server/lib/initialize.ts +++ b/packages/language-server/lib/initialize.ts @@ -52,11 +52,16 @@ export function initialize( project.vue = { compilerOptions: vueCompilerOptions }; if (project.typescript) { - const globalTypesName = `${vueCompilerOptions.lib}_${vueCompilerOptions.target}_${vueCompilerOptions.strictTemplates}.d.ts`; const directoryExists = project.typescript.languageServiceHost.directoryExists?.bind(project.typescript.languageServiceHost); const fileExists = project.typescript.languageServiceHost.fileExists.bind(project.typescript.languageServiceHost); const getScriptSnapshot = project.typescript.languageServiceHost.getScriptSnapshot.bind(project.typescript.languageServiceHost); - const snapshots = new Map(); + const globalTypesName = `${vueCompilerOptions.lib}_${vueCompilerOptions.target}_${vueCompilerOptions.strictTemplates}.d.ts`; + const globalTypesContents = generateGlobalTypes(vueCompilerOptions.lib, vueCompilerOptions.target, vueCompilerOptions.strictTemplates); + const globalTypesSnapshot: ts.IScriptSnapshot = { + getText: (start, end) => globalTypesContents.substring(start, end), + getLength: () => globalTypesContents.length, + getChangeRange: () => undefined, + }; if (directoryExists) { project.typescript.languageServiceHost.directoryExists = path => { if (path.endsWith('.vue-global-types')) { @@ -66,22 +71,14 @@ export function initialize( }; } project.typescript.languageServiceHost.fileExists = path => { - if (path.endsWith(globalTypesName)) { + if (path.endsWith(`.vue-global-types/${globalTypesName}`) || path.endsWith(`.vue-global-types\\${globalTypesName}`)) { return true; } return fileExists(path); }; project.typescript.languageServiceHost.getScriptSnapshot = path => { if (path.endsWith(`.vue-global-types/${globalTypesName}`) || path.endsWith(`.vue-global-types\\${globalTypesName}`)) { - if (!snapshots.has(path)) { - const contents = generateGlobalTypes(vueCompilerOptions.lib, vueCompilerOptions.target, vueCompilerOptions.strictTemplates); - snapshots.set(path, { - getText: (start, end) => contents.substring(start, end), - getLength: () => contents.length, - getChangeRange: () => undefined, - }); - } - return snapshots.get(path)!; + return globalTypesSnapshot; } return getScriptSnapshot(path); };