@volar/language-core 2.2.5 → 2.3.0-alpha.1
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 +3 -3
- package/index.js +10 -11
- package/lib/types.d.ts +28 -33
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './lib/types';
|
|
|
5
5
|
export * from './lib/utils';
|
|
6
6
|
import { SourceMap } from '@volar/source-map';
|
|
7
7
|
import type * as ts from 'typescript';
|
|
8
|
-
import type { CodeInformation, Language, LanguagePlugin, VirtualCode } from './lib/types';
|
|
9
|
-
export declare function createLanguage(plugins: LanguagePlugin[],
|
|
10
|
-
export declare function updateVirtualCodeMapOfMap(virtualCode: VirtualCode, mapOfMap: Map<
|
|
8
|
+
import type { CodeInformation, Language, LanguagePlugin, SourceScript, VirtualCode } from './lib/types';
|
|
9
|
+
export declare function createLanguage<T>(plugins: LanguagePlugin<T>[], scriptRegistry: Map<T, SourceScript<T>>, sync: (id: T) => void): Language<T>;
|
|
10
|
+
export declare function updateVirtualCodeMapOfMap<T>(virtualCode: VirtualCode, mapOfMap: Map<T, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>, getSourceSnapshot: (source: string | undefined) => [T, ts.IScriptSnapshot] | undefined): void;
|
|
11
11
|
export declare function forEachEmbeddedCode(virtualCode: VirtualCode): Generator<VirtualCode>;
|
package/index.js
CHANGED
|
@@ -22,9 +22,7 @@ __exportStar(require("./lib/types"), exports);
|
|
|
22
22
|
__exportStar(require("./lib/utils"), exports);
|
|
23
23
|
const source_map_1 = require("@volar/source-map");
|
|
24
24
|
const linkedCodeMap_1 = require("./lib/linkedCodeMap");
|
|
25
|
-
|
|
26
|
-
function createLanguage(plugins, caseSensitive, sync) {
|
|
27
|
-
const sourceScripts = new utils_1.FileMap(caseSensitive);
|
|
25
|
+
function createLanguage(plugins, scriptRegistry, sync) {
|
|
28
26
|
const virtualCodeToSourceFileMap = new WeakMap();
|
|
29
27
|
const virtualCodeToMaps = new WeakMap();
|
|
30
28
|
const virtualCodeToLinkedCodeMap = new WeakMap();
|
|
@@ -33,7 +31,7 @@ function createLanguage(plugins, caseSensitive, sync) {
|
|
|
33
31
|
scripts: {
|
|
34
32
|
get(id) {
|
|
35
33
|
sync(id);
|
|
36
|
-
return
|
|
34
|
+
return scriptRegistry.get(id);
|
|
37
35
|
},
|
|
38
36
|
set(id, snapshot, languageId, _plugins = plugins) {
|
|
39
37
|
if (!languageId) {
|
|
@@ -48,8 +46,8 @@ function createLanguage(plugins, caseSensitive, sync) {
|
|
|
48
46
|
console.warn(`languageId not found for ${id}`);
|
|
49
47
|
return;
|
|
50
48
|
}
|
|
51
|
-
if (
|
|
52
|
-
const sourceScript =
|
|
49
|
+
if (scriptRegistry.has(id)) {
|
|
50
|
+
const sourceScript = scriptRegistry.get(id);
|
|
53
51
|
if (sourceScript.languageId !== languageId) {
|
|
54
52
|
// languageId changed
|
|
55
53
|
this.delete(id);
|
|
@@ -83,7 +81,7 @@ function createLanguage(plugins, caseSensitive, sync) {
|
|
|
83
81
|
else {
|
|
84
82
|
// created
|
|
85
83
|
const sourceScript = { id, languageId, snapshot };
|
|
86
|
-
|
|
84
|
+
scriptRegistry.set(id, sourceScript);
|
|
87
85
|
for (const languagePlugin of _plugins) {
|
|
88
86
|
const virtualCode = languagePlugin.createVirtualCode?.(id, languageId, snapshot);
|
|
89
87
|
if (virtualCode) {
|
|
@@ -103,12 +101,12 @@ function createLanguage(plugins, caseSensitive, sync) {
|
|
|
103
101
|
}
|
|
104
102
|
},
|
|
105
103
|
delete(id) {
|
|
106
|
-
const value =
|
|
104
|
+
const value = scriptRegistry.get(id);
|
|
107
105
|
if (value) {
|
|
108
106
|
if (value.generated) {
|
|
109
107
|
value.generated.languagePlugin.disposeVirtualCode?.(id, value.generated.root);
|
|
110
108
|
}
|
|
111
|
-
|
|
109
|
+
scriptRegistry.delete(id);
|
|
112
110
|
}
|
|
113
111
|
},
|
|
114
112
|
},
|
|
@@ -135,8 +133,9 @@ function createLanguage(plugins, caseSensitive, sync) {
|
|
|
135
133
|
}
|
|
136
134
|
updateVirtualCodeMapOfMap(virtualCode, map, id => {
|
|
137
135
|
if (id) {
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
throw 'not implemented';
|
|
137
|
+
// const sourceScript = sourceScripts.get(id)!;
|
|
138
|
+
// return [id, sourceScript.snapshot];
|
|
140
139
|
}
|
|
141
140
|
else {
|
|
142
141
|
const sourceScript = virtualCodeToSourceFileMap.get(virtualCode);
|
package/lib/types.d.ts
CHANGED
|
@@ -1,36 +1,39 @@
|
|
|
1
|
-
import type { Mapping, SourceMap
|
|
1
|
+
import type { Mapping, SourceMap } from '@volar/source-map';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { LinkedCodeMap } from './linkedCodeMap';
|
|
4
|
-
export interface Language {
|
|
5
|
-
plugins: LanguagePlugin[];
|
|
4
|
+
export interface Language<T> {
|
|
5
|
+
plugins: LanguagePlugin<T>[];
|
|
6
6
|
scripts: {
|
|
7
|
-
get(id:
|
|
8
|
-
set(id:
|
|
9
|
-
delete(id:
|
|
7
|
+
get(id: T): SourceScript<T> | undefined;
|
|
8
|
+
set(id: T, snapshot: ts.IScriptSnapshot, languageId?: string, plugins?: LanguagePlugin<T>[]): SourceScript<T> | undefined;
|
|
9
|
+
delete(id: T): void;
|
|
10
10
|
};
|
|
11
11
|
maps: {
|
|
12
|
-
get(virtualCode: VirtualCode, scriptId?:
|
|
13
|
-
forEach(virtualCode: VirtualCode): Map<
|
|
12
|
+
get(virtualCode: VirtualCode, scriptId?: T): SourceMap<CodeInformation> | undefined;
|
|
13
|
+
forEach(virtualCode: VirtualCode): Map<T, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>;
|
|
14
14
|
};
|
|
15
15
|
linkedCodeMaps: {
|
|
16
16
|
get(virtualCode: VirtualCode): LinkedCodeMap | undefined;
|
|
17
17
|
};
|
|
18
18
|
typescript?: {
|
|
19
|
-
|
|
19
|
+
configFileName: string | undefined;
|
|
20
|
+
sys: ts.System & {
|
|
21
|
+
version?: number;
|
|
22
|
+
sync?(): Promise<number>;
|
|
23
|
+
};
|
|
20
24
|
languageServiceHost: ts.LanguageServiceHost;
|
|
21
|
-
getExtraServiceScript(fileName: string):
|
|
25
|
+
getExtraServiceScript(fileName: string): [SourceScript<T>, TypeScriptExtraServiceScript] | undefined;
|
|
26
|
+
asScriptId(fileName: string): T;
|
|
27
|
+
asFileName(scriptId: T): string;
|
|
22
28
|
};
|
|
23
29
|
}
|
|
24
|
-
export interface SourceScript {
|
|
25
|
-
|
|
26
|
-
* uri or fileName
|
|
27
|
-
*/
|
|
28
|
-
id: string;
|
|
30
|
+
export interface SourceScript<T> {
|
|
31
|
+
id: T;
|
|
29
32
|
languageId: string;
|
|
30
33
|
snapshot: ts.IScriptSnapshot;
|
|
31
34
|
generated?: {
|
|
32
35
|
root: VirtualCode;
|
|
33
|
-
languagePlugin: LanguagePlugin
|
|
36
|
+
languagePlugin: LanguagePlugin<T>;
|
|
34
37
|
embeddedCodes: Map<string, VirtualCode>;
|
|
35
38
|
};
|
|
36
39
|
}
|
|
@@ -41,7 +44,6 @@ export interface VirtualCode {
|
|
|
41
44
|
snapshot: ts.IScriptSnapshot;
|
|
42
45
|
mappings: CodeMapping[];
|
|
43
46
|
embeddedCodes?: VirtualCode[];
|
|
44
|
-
codegenStacks?: Stack[];
|
|
45
47
|
linkedCodeMappings?: Mapping[];
|
|
46
48
|
}
|
|
47
49
|
export interface CodeInformation {
|
|
@@ -69,19 +71,19 @@ export interface CodeInformation {
|
|
|
69
71
|
/** virtual code is expected correctly reflect the format information of the source code */
|
|
70
72
|
format?: boolean;
|
|
71
73
|
}
|
|
72
|
-
export interface
|
|
74
|
+
export interface TypeScriptServiceScript {
|
|
73
75
|
code: VirtualCode;
|
|
74
76
|
extension: '.ts' | '.js' | '.mts' | '.mjs' | '.cjs' | '.cts' | '.d.ts' | string;
|
|
75
77
|
scriptKind: ts.ScriptKind;
|
|
76
78
|
}
|
|
77
|
-
export interface
|
|
79
|
+
export interface TypeScriptExtraServiceScript extends TypeScriptServiceScript {
|
|
78
80
|
fileName: string;
|
|
79
81
|
}
|
|
80
|
-
export interface LanguagePlugin<T extends VirtualCode = VirtualCode> {
|
|
81
|
-
getLanguageId(scriptId:
|
|
82
|
-
createVirtualCode?(scriptId:
|
|
83
|
-
updateVirtualCode?(scriptId:
|
|
84
|
-
disposeVirtualCode?(scriptId:
|
|
82
|
+
export interface LanguagePlugin<T, K extends VirtualCode = VirtualCode> {
|
|
83
|
+
getLanguageId(scriptId: T): string | undefined;
|
|
84
|
+
createVirtualCode?(scriptId: T, languageId: string, snapshot: ts.IScriptSnapshot): K | undefined;
|
|
85
|
+
updateVirtualCode?(scriptId: T, virtualCode: K, newSnapshot: ts.IScriptSnapshot): K | undefined;
|
|
86
|
+
disposeVirtualCode?(scriptId: T, virtualCode: K): void;
|
|
85
87
|
typescript?: {
|
|
86
88
|
/**
|
|
87
89
|
* LSP + TS Plugin
|
|
@@ -90,21 +92,14 @@ export interface LanguagePlugin<T extends VirtualCode = VirtualCode> {
|
|
|
90
92
|
/**
|
|
91
93
|
* LSP + TS Plugin
|
|
92
94
|
*/
|
|
93
|
-
getServiceScript(rootVirtualCode:
|
|
95
|
+
getServiceScript(rootVirtualCode: K): TypeScriptServiceScript | undefined;
|
|
94
96
|
/**
|
|
95
97
|
* LSP only
|
|
96
98
|
*/
|
|
97
|
-
getExtraServiceScripts?(fileName: string, rootVirtualCode:
|
|
99
|
+
getExtraServiceScripts?(fileName: string, rootVirtualCode: K): TypeScriptExtraServiceScript[];
|
|
98
100
|
/**
|
|
99
101
|
* LSP only
|
|
100
102
|
*/
|
|
101
103
|
resolveLanguageServiceHost?(host: ts.LanguageServiceHost): ts.LanguageServiceHost;
|
|
102
104
|
};
|
|
103
105
|
}
|
|
104
|
-
export interface TypeScriptProjectHost extends ts.System, Pick<ts.LanguageServiceHost, 'getLocalizedDiagnosticMessages' | 'getCompilationSettings' | 'getProjectReferences' | 'getCurrentDirectory' | 'getScriptFileNames' | 'getProjectVersion' | 'getScriptSnapshot'> {
|
|
105
|
-
configFileName: string | undefined;
|
|
106
|
-
getSystemVersion?(): number;
|
|
107
|
-
syncSystem?(): Promise<number>;
|
|
108
|
-
scriptIdToFileName(scriptId: string): string;
|
|
109
|
-
fileNameToScriptId(fileName: string): string;
|
|
110
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-alpha.1",
|
|
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.
|
|
15
|
+
"@volar/source-map": "2.3.0-alpha.1"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "173be13e1d51c62cfe5ddc9926933d30a7aa1d11"
|
|
18
18
|
}
|