@volar/language-core 2.3.0-alpha.7 → 2.3.0-alpha.8

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 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) {
package/lib/types.d.ts CHANGED
@@ -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.7",
3
+ "version": "2.3.0-alpha.8",
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.7"
15
+ "@volar/source-map": "2.3.0-alpha.8"
16
16
  },
17
- "gitHead": "3cc2a62516113c5789e4f54766e25063099a13a5"
17
+ "gitHead": "377a0083ac697a476509805a6777a2339391dcaf"
18
18
  }