Skip to content

Commit ac1bec7

Browse files
committed
chore: code consistency
1 parent 931444f commit ac1bec7

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

packages/component-meta/lib/base.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ export function baseCreate(
139139
const fileExists = languageServiceHost.fileExists.bind(languageServiceHost);
140140
const getScriptSnapshot = languageServiceHost.getScriptSnapshot.bind(languageServiceHost);
141141
const globalTypesName = `${commandLine.vueOptions.lib}_${commandLine.vueOptions.target}_${commandLine.vueOptions.strictTemplates}.d.ts`;
142-
const snapshots = new Map<string, ts.IScriptSnapshot>();
142+
const globalTypesContents = vue.generateGlobalTypes(commandLine.vueOptions.lib, commandLine.vueOptions.target, commandLine.vueOptions.strictTemplates);
143+
const globalTypesSnapshot: ts.IScriptSnapshot = {
144+
getText: (start, end) => globalTypesContents.substring(start, end),
145+
getLength: () => globalTypesContents.length,
146+
getChangeRange: () => undefined,
147+
};
143148
if (directoryExists) {
144149
languageServiceHost.directoryExists = path => {
145150
if (path.endsWith('.vue-global-types')) {
@@ -149,22 +154,14 @@ export function baseCreate(
149154
};
150155
}
151156
languageServiceHost.fileExists = path => {
152-
if (path.endsWith(globalTypesName)) {
157+
if (path.endsWith(`.vue-global-types/${globalTypesName}`) || path.endsWith(`.vue-global-types\\${globalTypesName}`)) {
153158
return true;
154159
}
155160
return fileExists(path);
156161
};
157162
languageServiceHost.getScriptSnapshot = path => {
158163
if (path.endsWith(`.vue-global-types/${globalTypesName}`) || path.endsWith(`.vue-global-types\\${globalTypesName}`)) {
159-
if (!snapshots.has(path)) {
160-
const contents = vue.generateGlobalTypes(commandLine.vueOptions.lib, commandLine.vueOptions.target, commandLine.vueOptions.strictTemplates);
161-
snapshots.set(path, {
162-
getText: (start, end) => contents.substring(start, end),
163-
getLength: () => contents.length,
164-
getChangeRange: () => undefined,
165-
});
166-
}
167-
return snapshots.get(path)!;
164+
return globalTypesSnapshot;
168165
}
169166
return getScriptSnapshot(path);
170167
};

packages/language-server/lib/initialize.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@ export function initialize(
5252
project.vue = { compilerOptions: vueCompilerOptions };
5353

5454
if (project.typescript) {
55-
const globalTypesName = `${vueCompilerOptions.lib}_${vueCompilerOptions.target}_${vueCompilerOptions.strictTemplates}.d.ts`;
5655
const directoryExists = project.typescript.languageServiceHost.directoryExists?.bind(project.typescript.languageServiceHost);
5756
const fileExists = project.typescript.languageServiceHost.fileExists.bind(project.typescript.languageServiceHost);
5857
const getScriptSnapshot = project.typescript.languageServiceHost.getScriptSnapshot.bind(project.typescript.languageServiceHost);
59-
const snapshots = new Map<string, ts.IScriptSnapshot>();
58+
const globalTypesName = `${vueCompilerOptions.lib}_${vueCompilerOptions.target}_${vueCompilerOptions.strictTemplates}.d.ts`;
59+
const globalTypesContents = generateGlobalTypes(vueCompilerOptions.lib, vueCompilerOptions.target, vueCompilerOptions.strictTemplates);
60+
const globalTypesSnapshot: ts.IScriptSnapshot = {
61+
getText: (start, end) => globalTypesContents.substring(start, end),
62+
getLength: () => globalTypesContents.length,
63+
getChangeRange: () => undefined,
64+
};
6065
if (directoryExists) {
6166
project.typescript.languageServiceHost.directoryExists = path => {
6267
if (path.endsWith('.vue-global-types')) {
@@ -66,22 +71,14 @@ export function initialize(
6671
};
6772
}
6873
project.typescript.languageServiceHost.fileExists = path => {
69-
if (path.endsWith(globalTypesName)) {
74+
if (path.endsWith(`.vue-global-types/${globalTypesName}`) || path.endsWith(`.vue-global-types\\${globalTypesName}`)) {
7075
return true;
7176
}
7277
return fileExists(path);
7378
};
7479
project.typescript.languageServiceHost.getScriptSnapshot = path => {
7580
if (path.endsWith(`.vue-global-types/${globalTypesName}`) || path.endsWith(`.vue-global-types\\${globalTypesName}`)) {
76-
if (!snapshots.has(path)) {
77-
const contents = generateGlobalTypes(vueCompilerOptions.lib, vueCompilerOptions.target, vueCompilerOptions.strictTemplates);
78-
snapshots.set(path, {
79-
getText: (start, end) => contents.substring(start, end),
80-
getLength: () => contents.length,
81-
getChangeRange: () => undefined,
82-
});
83-
}
84-
return snapshots.get(path)!;
81+
return globalTypesSnapshot;
8582
}
8683
return getScriptSnapshot(path);
8784
};

0 commit comments

Comments
 (0)