@volar/language-core 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/languageContext.js +37 -41
- package/out/types.d.ts +0 -1
- package/package.json +3 -3
package/out/languageContext.js
CHANGED
|
@@ -21,16 +21,17 @@ function createEmbeddedLanguageServiceHost(host, languageModules) {
|
|
|
21
21
|
let tsProjectVersion = 0;
|
|
22
22
|
const documentRegistry = (0, documentRegistry_1.createDocumentRegistry)();
|
|
23
23
|
const ts = host.getTypeScriptModule();
|
|
24
|
-
const tsFileVersions = new Map();
|
|
25
24
|
const scriptSnapshots = new Map();
|
|
26
|
-
const
|
|
25
|
+
const sourceTsFileVersions = new Map();
|
|
26
|
+
const sourceVueFileVersions = new Map();
|
|
27
|
+
const virtualFileVersions = new Map();
|
|
27
28
|
const _tsHost = {
|
|
28
29
|
fileExists: host.fileExists
|
|
29
30
|
? fileName => {
|
|
30
31
|
var _a;
|
|
31
32
|
// .vue.js -> .vue
|
|
32
33
|
// .vue.ts -> .vue
|
|
33
|
-
// .vue.d.ts
|
|
34
|
+
// .vue.d.ts -> [ignored]
|
|
34
35
|
const vueFileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
|
35
36
|
if (!documentRegistry.get(vueFileName)) {
|
|
36
37
|
// create virtual files
|
|
@@ -104,77 +105,75 @@ function createEmbeddedLanguageServiceHost(host, languageModules) {
|
|
|
104
105
|
function update() {
|
|
105
106
|
var _a;
|
|
106
107
|
const newProjectVersion = (_a = host.getProjectVersion) === null || _a === void 0 ? void 0 : _a.call(host);
|
|
107
|
-
const
|
|
108
|
+
const shouldUpdate = newProjectVersion === undefined || newProjectVersion !== lastProjectVersion;
|
|
108
109
|
lastProjectVersion = newProjectVersion;
|
|
109
|
-
if (!
|
|
110
|
+
if (!shouldUpdate)
|
|
110
111
|
return;
|
|
111
112
|
let tsFileUpdated = false;
|
|
112
|
-
const
|
|
113
|
-
const
|
|
113
|
+
const checkRemains = new Set(host.getScriptFileNames());
|
|
114
|
+
const sourceFilesShouldUpdate = [];
|
|
114
115
|
// .vue
|
|
115
116
|
for (const [sourceFile, languageModule] of documentRegistry.getAll()) {
|
|
116
|
-
|
|
117
|
+
checkRemains.delete(sourceFile.fileName);
|
|
118
|
+
const snapshot = host.getScriptSnapshot(sourceFile.fileName);
|
|
119
|
+
if (!snapshot) {
|
|
120
|
+
// delete
|
|
121
|
+
documentRegistry.delete(sourceFile.fileName);
|
|
122
|
+
tsFileUpdated = true;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
117
125
|
const newVersion = host.getScriptVersion(sourceFile.fileName);
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// update
|
|
123
|
-
sourceFilesToUpdate.push([sourceFile, languageModule, snapshot]);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
// delete
|
|
127
|
-
if (documentRegistry.delete(sourceFile.fileName)) {
|
|
128
|
-
tsFileUpdated = true;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
126
|
+
if (sourceVueFileVersions.get(sourceFile.fileName) !== newVersion) {
|
|
127
|
+
// update
|
|
128
|
+
sourceVueFileVersions.set(sourceFile.fileName, newVersion);
|
|
129
|
+
sourceFilesShouldUpdate.push([sourceFile, languageModule, snapshot]);
|
|
131
130
|
}
|
|
132
131
|
}
|
|
133
132
|
// no any vue file version change, it mean project version was update by ts file change at this time
|
|
134
|
-
if (!
|
|
133
|
+
if (!sourceFilesShouldUpdate.length) {
|
|
135
134
|
tsFileUpdated = true;
|
|
136
135
|
}
|
|
137
136
|
// add
|
|
138
|
-
for (const fileName of [...
|
|
137
|
+
for (const fileName of [...checkRemains]) {
|
|
139
138
|
const snapshot = host.getScriptSnapshot(fileName);
|
|
140
139
|
if (snapshot) {
|
|
141
140
|
for (const languageModule of languageModules) {
|
|
142
141
|
const sourceFile = languageModule.createSourceFile(fileName, snapshot);
|
|
143
142
|
if (sourceFile) {
|
|
144
|
-
|
|
143
|
+
sourceVueFileVersions.set(sourceFile.fileName, host.getScriptVersion(fileName));
|
|
145
144
|
documentRegistry.set(fileName, (0, reactivity_1.shallowReactive)(sourceFile), languageModule);
|
|
146
|
-
|
|
145
|
+
checkRemains.delete(fileName);
|
|
147
146
|
break;
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
149
|
}
|
|
151
150
|
}
|
|
152
151
|
// .ts / .js / .d.ts / .json ...
|
|
153
|
-
for (const [oldTsFileName, oldTsFileVersion] of [...
|
|
152
|
+
for (const [oldTsFileName, oldTsFileVersion] of [...sourceTsFileVersions]) {
|
|
154
153
|
const newVersion = host.getScriptVersion(oldTsFileName);
|
|
155
154
|
if (oldTsFileVersion !== newVersion) {
|
|
156
|
-
if (!
|
|
155
|
+
if (!checkRemains.has(oldTsFileName) && !host.getScriptSnapshot(oldTsFileName)) {
|
|
157
156
|
// delete
|
|
158
|
-
|
|
157
|
+
sourceTsFileVersions.delete(oldTsFileName);
|
|
159
158
|
}
|
|
160
159
|
else {
|
|
161
160
|
// update
|
|
162
|
-
|
|
161
|
+
sourceTsFileVersions.set(oldTsFileName, newVersion);
|
|
163
162
|
}
|
|
164
163
|
tsFileUpdated = true;
|
|
165
164
|
}
|
|
166
165
|
}
|
|
167
|
-
for (const nowFileName of
|
|
168
|
-
if (!
|
|
166
|
+
for (const nowFileName of checkRemains) {
|
|
167
|
+
if (!sourceTsFileVersions.has(nowFileName)) {
|
|
169
168
|
// add
|
|
170
169
|
const newVersion = host.getScriptVersion(nowFileName);
|
|
171
|
-
|
|
170
|
+
sourceTsFileVersions.set(nowFileName, newVersion);
|
|
172
171
|
tsFileUpdated = true;
|
|
173
172
|
}
|
|
174
173
|
}
|
|
175
|
-
for (const [sourceFile, languageModule, snapshot] of
|
|
174
|
+
for (const [sourceFile, languageModule, snapshot] of sourceFilesShouldUpdate) {
|
|
176
175
|
(0, documentRegistry_1.forEachEmbeddeds)(sourceFile, embedded => {
|
|
177
|
-
|
|
176
|
+
virtualFileVersions.delete(embedded.fileName);
|
|
178
177
|
});
|
|
179
178
|
const oldScripts = {};
|
|
180
179
|
const newScripts = {};
|
|
@@ -212,10 +211,7 @@ function createEmbeddedLanguageServiceHost(host, languageModules) {
|
|
|
212
211
|
}
|
|
213
212
|
}
|
|
214
213
|
for (const fileName of host.getScriptFileNames()) {
|
|
215
|
-
if (
|
|
216
|
-
tsFileNames.add(fileName); // .vue + .ts
|
|
217
|
-
}
|
|
218
|
-
else if (!documentRegistry.has(fileName)) {
|
|
214
|
+
if (!documentRegistry.has(fileName)) {
|
|
219
215
|
tsFileNames.add(fileName); // .ts
|
|
220
216
|
}
|
|
221
217
|
}
|
|
@@ -225,8 +221,8 @@ function createEmbeddedLanguageServiceHost(host, languageModules) {
|
|
|
225
221
|
var _a, _b, _c;
|
|
226
222
|
let mapped = documentRegistry.fromEmbeddedFileName(fileName);
|
|
227
223
|
if (mapped) {
|
|
228
|
-
if (
|
|
229
|
-
return
|
|
224
|
+
if (virtualFileVersions.has(mapped.embedded.fileName)) {
|
|
225
|
+
return virtualFileVersions.get(mapped.embedded.fileName);
|
|
230
226
|
}
|
|
231
227
|
else {
|
|
232
228
|
let version = (_c = (_b = (_a = ts.sys) === null || _a === void 0 ? void 0 : _a.createHash) === null || _b === void 0 ? void 0 : _b.call(_a, mapped.embedded.text)) !== null && _c !== void 0 ? _c : mapped.embedded.text;
|
|
@@ -234,7 +230,7 @@ function createEmbeddedLanguageServiceHost(host, languageModules) {
|
|
|
234
230
|
// fix https://github.com/johnsoncodehk/volar/issues/1082
|
|
235
231
|
version = host.getScriptVersion(mapped.sourceFile.fileName) + ':' + version;
|
|
236
232
|
}
|
|
237
|
-
|
|
233
|
+
virtualFileVersions.set(mapped.embedded.fileName, version);
|
|
238
234
|
return version;
|
|
239
235
|
}
|
|
240
236
|
}
|
package/out/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"directory": "packages/language-core"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/source-map": "1.0.
|
|
16
|
+
"@volar/source-map": "1.0.16",
|
|
17
17
|
"@vue/reactivity": "^3.2.45",
|
|
18
18
|
"muggle-string": "^0.1.0"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "af476047d8859652254ed36f8aee184f1972a97a"
|
|
21
21
|
}
|