@volar/language-core 2.3.0-alpha.7 → 2.3.0-alpha.9
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/index.js +36 -16
- package/lib/types.d.ts +9 -1
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -34,6 +34,11 @@ function createLanguage(plugins, scriptRegistry, sync) {
|
|
|
34
34
|
},
|
|
35
35
|
get(id) {
|
|
36
36
|
sync(id);
|
|
37
|
+
const result = scriptRegistry.get(id);
|
|
38
|
+
// The sync function provider may not always call the set function due to caching, so it is necessary to explicitly check isAssociationDirty.
|
|
39
|
+
if (result?.isAssociationDirty) {
|
|
40
|
+
this.set(id, result.snapshot, result.languageId);
|
|
41
|
+
}
|
|
37
42
|
return scriptRegistry.get(id);
|
|
38
43
|
},
|
|
39
44
|
set(id, snapshot, languageId, _plugins = plugins) {
|
|
@@ -49,13 +54,22 @@ function createLanguage(plugins, scriptRegistry, sync) {
|
|
|
49
54
|
console.warn(`languageId not found for ${id}`);
|
|
50
55
|
return;
|
|
51
56
|
}
|
|
57
|
+
let associatedOnly = false;
|
|
58
|
+
for (const plugin of plugins) {
|
|
59
|
+
if (plugin.isAssociatedFileOnly?.(id, languageId)) {
|
|
60
|
+
associatedOnly = true;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
52
64
|
if (scriptRegistry.has(id)) {
|
|
53
65
|
const sourceScript = scriptRegistry.get(id);
|
|
54
|
-
if (sourceScript.languageId !== languageId) {
|
|
55
|
-
// languageId changed
|
|
66
|
+
if (sourceScript.languageId !== languageId || sourceScript.associatedOnly !== associatedOnly) {
|
|
56
67
|
this.delete(id);
|
|
57
68
|
return this.set(id, snapshot, languageId);
|
|
58
69
|
}
|
|
70
|
+
else if (associatedOnly) {
|
|
71
|
+
sourceScript.snapshot = snapshot;
|
|
72
|
+
}
|
|
59
73
|
else if (sourceScript.isAssociationDirty || sourceScript.snapshot !== snapshot) {
|
|
60
74
|
// snapshot updated
|
|
61
75
|
sourceScript.snapshot = snapshot;
|
|
@@ -94,8 +108,12 @@ function createLanguage(plugins, scriptRegistry, sync) {
|
|
|
94
108
|
snapshot,
|
|
95
109
|
associatedIds: new Set(),
|
|
96
110
|
targetIds: new Set(),
|
|
111
|
+
associatedOnly
|
|
97
112
|
};
|
|
98
113
|
scriptRegistry.set(id, sourceScript);
|
|
114
|
+
if (associatedOnly) {
|
|
115
|
+
return sourceScript;
|
|
116
|
+
}
|
|
99
117
|
for (const languagePlugin of _plugins) {
|
|
100
118
|
const virtualCode = languagePlugin.createVirtualCode?.(id, languageId, snapshot, prepareCreateVirtualCode(sourceScript));
|
|
101
119
|
if (virtualCode) {
|
|
@@ -124,30 +142,32 @@ function createLanguage(plugins, scriptRegistry, sync) {
|
|
|
124
142
|
},
|
|
125
143
|
},
|
|
126
144
|
maps: {
|
|
127
|
-
get(virtualCode) {
|
|
128
|
-
for (const map of this.forEach(virtualCode)) {
|
|
129
|
-
return map[2];
|
|
130
|
-
}
|
|
131
|
-
throw `no map found for ${virtualCode.id}`;
|
|
132
|
-
},
|
|
133
|
-
*forEach(virtualCode) {
|
|
145
|
+
get(virtualCode, sourceScript, mappings) {
|
|
134
146
|
let mapCache = virtualCodeToSourceMap.get(virtualCode.snapshot);
|
|
135
147
|
if (!mapCache) {
|
|
136
148
|
virtualCodeToSourceMap.set(virtualCode.snapshot, mapCache = new WeakMap());
|
|
137
149
|
}
|
|
138
|
-
const sourceScript = virtualCodeToSourceScriptMap.get(virtualCode);
|
|
139
150
|
if (!mapCache.has(sourceScript.snapshot)) {
|
|
140
|
-
mapCache.set(sourceScript.snapshot, new source_map_1.SourceMap(virtualCode.mappings));
|
|
151
|
+
mapCache.set(sourceScript.snapshot, new source_map_1.SourceMap(mappings ?? virtualCode.mappings));
|
|
141
152
|
}
|
|
142
|
-
|
|
153
|
+
return mapCache.get(sourceScript.snapshot);
|
|
154
|
+
},
|
|
155
|
+
*forEach(virtualCode) {
|
|
156
|
+
const sourceScript = virtualCodeToSourceScriptMap.get(virtualCode);
|
|
157
|
+
yield [
|
|
158
|
+
sourceScript.id,
|
|
159
|
+
sourceScript.snapshot,
|
|
160
|
+
this.get(virtualCode, sourceScript),
|
|
161
|
+
];
|
|
143
162
|
if (virtualCode.associatedScriptMappings) {
|
|
144
163
|
for (const [relatedScriptId, relatedMappings] of virtualCode.associatedScriptMappings) {
|
|
145
164
|
const relatedSourceScript = scriptRegistry.get(relatedScriptId);
|
|
146
165
|
if (relatedSourceScript) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
166
|
+
yield [
|
|
167
|
+
relatedSourceScript.id,
|
|
168
|
+
relatedSourceScript.snapshot,
|
|
169
|
+
this.get(virtualCode, relatedSourceScript, relatedMappings),
|
|
170
|
+
];
|
|
151
171
|
}
|
|
152
172
|
}
|
|
153
173
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface Language<T = unknown> {
|
|
|
10
10
|
fromVirtualCode(virtualCode: VirtualCode): SourceScript<T>;
|
|
11
11
|
};
|
|
12
12
|
maps: {
|
|
13
|
-
get(virtualCode: VirtualCode): SourceMap<CodeInformation>;
|
|
13
|
+
get(virtualCode: VirtualCode, sourceScript: SourceScript<T>, mappings?: Mapping<CodeInformation>[]): SourceMap<CodeInformation>;
|
|
14
14
|
forEach(virtualCode: VirtualCode): Generator<[id: T, snapshot: ts.IScriptSnapshot, map: SourceMap<CodeInformation>]>;
|
|
15
15
|
};
|
|
16
16
|
linkedCodeMaps: {
|
|
@@ -34,6 +34,7 @@ export interface SourceScript<T = unknown> {
|
|
|
34
34
|
snapshot: ts.IScriptSnapshot;
|
|
35
35
|
targetIds: Set<T>;
|
|
36
36
|
associatedIds: Set<T>;
|
|
37
|
+
associatedOnly: boolean;
|
|
37
38
|
isAssociationDirty?: boolean;
|
|
38
39
|
generated?: {
|
|
39
40
|
root: VirtualCode;
|
|
@@ -103,6 +104,13 @@ export interface LanguagePlugin<T = unknown, K extends VirtualCode = VirtualCode
|
|
|
103
104
|
* Cleanup a virtual code.
|
|
104
105
|
*/
|
|
105
106
|
disposeVirtualCode?(scriptId: T, virtualCode: K): void;
|
|
107
|
+
/**
|
|
108
|
+
* Some file types should not be parsed or processed as TypeScript files,
|
|
109
|
+
* as they are used only as sources for generated files.
|
|
110
|
+
*
|
|
111
|
+
* This functionality is required only in TS plugin mode.
|
|
112
|
+
*/
|
|
113
|
+
isAssociatedFileOnly?(scriptId: T, languageId: string): boolean;
|
|
106
114
|
typescript?: TypeScriptGenericOptions<K> & TypeScriptNonTSPluginOptions<K>;
|
|
107
115
|
}
|
|
108
116
|
export interface CodegenContext<T = unknown> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-core",
|
|
3
|
-
"version": "2.3.0-alpha.
|
|
3
|
+
"version": "2.3.0-alpha.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/language-core"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/source-map": "2.3.0-alpha.
|
|
15
|
+
"@volar/source-map": "2.3.0-alpha.9"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "3f741930343896dfc464a893ebe5f3619bb1a1aa"
|
|
18
18
|
}
|