@volar/language-core 2.3.0-alpha.6 → 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.d.ts +1 -1
- package/index.js +20 -2
- package/lib/types.d.ts +27 -19
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export * from './lib/types';
|
|
|
5
5
|
export * from './lib/utils';
|
|
6
6
|
import type { Language, LanguagePlugin, SourceScript, VirtualCode } from './lib/types';
|
|
7
7
|
export declare function createLanguage<T>(plugins: LanguagePlugin<T>[], scriptRegistry: Map<T, SourceScript<T>>, sync: (id: T) => void): Language<T>;
|
|
8
|
-
export declare function forEachEmbeddedCode
|
|
8
|
+
export declare function forEachEmbeddedCode(virtualCode: VirtualCode): Generator<VirtualCode>;
|
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
|
@@ -7,14 +7,14 @@ export interface Language<T = unknown> {
|
|
|
7
7
|
get(id: T): SourceScript<T> | undefined;
|
|
8
8
|
set(id: T, snapshot: ts.IScriptSnapshot, languageId?: string, plugins?: LanguagePlugin<T>[]): SourceScript<T> | undefined;
|
|
9
9
|
delete(id: T): void;
|
|
10
|
-
fromVirtualCode(virtualCode: VirtualCode
|
|
10
|
+
fromVirtualCode(virtualCode: VirtualCode): SourceScript<T>;
|
|
11
11
|
};
|
|
12
12
|
maps: {
|
|
13
|
-
get(virtualCode: VirtualCode
|
|
14
|
-
forEach(virtualCode: VirtualCode
|
|
13
|
+
get(virtualCode: VirtualCode): SourceMap<CodeInformation>;
|
|
14
|
+
forEach(virtualCode: VirtualCode): Generator<[id: T, snapshot: ts.IScriptSnapshot, map: SourceMap<CodeInformation>]>;
|
|
15
15
|
};
|
|
16
16
|
linkedCodeMaps: {
|
|
17
|
-
get(virtualCode: VirtualCode
|
|
17
|
+
get(virtualCode: VirtualCode): LinkedCodeMap | undefined;
|
|
18
18
|
};
|
|
19
19
|
typescript?: {
|
|
20
20
|
configFileName: string | undefined;
|
|
@@ -23,7 +23,7 @@ export interface Language<T = unknown> {
|
|
|
23
23
|
sync?(): Promise<number>;
|
|
24
24
|
};
|
|
25
25
|
languageServiceHost: ts.LanguageServiceHost;
|
|
26
|
-
getExtraServiceScript(fileName: string): TypeScriptExtraServiceScript
|
|
26
|
+
getExtraServiceScript(fileName: string): TypeScriptExtraServiceScript | undefined;
|
|
27
27
|
asScriptId(fileName: string): T;
|
|
28
28
|
asFileName(scriptId: T): string;
|
|
29
29
|
};
|
|
@@ -34,21 +34,22 @@ 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
|
-
root: VirtualCode
|
|
40
|
+
root: VirtualCode;
|
|
40
41
|
languagePlugin: LanguagePlugin<T>;
|
|
41
|
-
embeddedCodes: Map<string, VirtualCode
|
|
42
|
+
embeddedCodes: Map<string, VirtualCode>;
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
45
|
export type CodeMapping = Mapping<CodeInformation>;
|
|
45
|
-
export interface VirtualCode
|
|
46
|
+
export interface VirtualCode {
|
|
46
47
|
id: string;
|
|
47
48
|
languageId: string;
|
|
48
49
|
snapshot: ts.IScriptSnapshot;
|
|
49
50
|
mappings: CodeMapping[];
|
|
50
|
-
associatedScriptMappings?: Map<
|
|
51
|
-
embeddedCodes?: VirtualCode
|
|
51
|
+
associatedScriptMappings?: Map<unknown, CodeMapping[]>;
|
|
52
|
+
embeddedCodes?: VirtualCode[];
|
|
52
53
|
linkedCodeMappings?: Mapping[];
|
|
53
54
|
}
|
|
54
55
|
export interface CodeInformation {
|
|
@@ -76,17 +77,17 @@ export interface CodeInformation {
|
|
|
76
77
|
/** virtual code is expected correctly reflect the format information of the source code */
|
|
77
78
|
format?: boolean;
|
|
78
79
|
}
|
|
79
|
-
export interface TypeScriptServiceScript
|
|
80
|
-
code: VirtualCode
|
|
80
|
+
export interface TypeScriptServiceScript {
|
|
81
|
+
code: VirtualCode;
|
|
81
82
|
extension: '.ts' | '.js' | '.mts' | '.mjs' | '.cjs' | '.cts' | '.d.ts' | string;
|
|
82
83
|
scriptKind: ts.ScriptKind;
|
|
83
84
|
/** See #188 */
|
|
84
85
|
preventLeadingOffset?: boolean;
|
|
85
86
|
}
|
|
86
|
-
export interface TypeScriptExtraServiceScript
|
|
87
|
+
export interface TypeScriptExtraServiceScript extends TypeScriptServiceScript {
|
|
87
88
|
fileName: string;
|
|
88
89
|
}
|
|
89
|
-
export interface LanguagePlugin<T = unknown, K extends VirtualCode
|
|
90
|
+
export interface LanguagePlugin<T = unknown, K extends VirtualCode = VirtualCode> {
|
|
90
91
|
/**
|
|
91
92
|
* For files that are not opened in the IDE, the language ID will not be synchronized to the language server, so a hook is needed to parse the language ID of files that are known extension but not opened in the IDE.
|
|
92
93
|
*/
|
|
@@ -103,7 +104,14 @@ export interface LanguagePlugin<T = unknown, K extends VirtualCode<T> = VirtualC
|
|
|
103
104
|
* Cleanup a virtual code.
|
|
104
105
|
*/
|
|
105
106
|
disposeVirtualCode?(scriptId: T, virtualCode: K): void;
|
|
106
|
-
|
|
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;
|
|
114
|
+
typescript?: TypeScriptGenericOptions<K> & TypeScriptNonTSPluginOptions<K>;
|
|
107
115
|
}
|
|
108
116
|
export interface CodegenContext<T = unknown> {
|
|
109
117
|
getAssociatedScript(scriptId: T): SourceScript<T> | undefined;
|
|
@@ -111,16 +119,16 @@ export interface CodegenContext<T = unknown> {
|
|
|
111
119
|
/**
|
|
112
120
|
* The following options available to all situations.
|
|
113
121
|
*/
|
|
114
|
-
interface TypeScriptGenericOptions<
|
|
122
|
+
interface TypeScriptGenericOptions<K> {
|
|
115
123
|
extraFileExtensions: ts.FileExtensionInfo[];
|
|
116
124
|
resolveHiddenExtensions?: boolean;
|
|
117
|
-
getServiceScript(root: K): TypeScriptServiceScript
|
|
125
|
+
getServiceScript(root: K): TypeScriptServiceScript | undefined;
|
|
118
126
|
}
|
|
119
127
|
/**
|
|
120
128
|
* The following options will not be available in TS plugin.
|
|
121
129
|
*/
|
|
122
|
-
interface TypeScriptNonTSPluginOptions<
|
|
123
|
-
getExtraServiceScripts?(fileName: string, rootVirtualCode: K): TypeScriptExtraServiceScript
|
|
130
|
+
interface TypeScriptNonTSPluginOptions<K> {
|
|
131
|
+
getExtraServiceScripts?(fileName: string, rootVirtualCode: K): TypeScriptExtraServiceScript[];
|
|
124
132
|
resolveLanguageServiceHost?(host: ts.LanguageServiceHost): ts.LanguageServiceHost;
|
|
125
133
|
}
|
|
126
134
|
export {};
|
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.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.
|
|
15
|
+
"@volar/source-map": "2.3.0-alpha.8"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "377a0083ac697a476509805a6777a2339391dcaf"
|
|
18
18
|
}
|