@volar/language-core 2.1.4 → 2.2.0-alpha.0
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 +7 -2
- package/index.js +148 -3
- package/lib/types.d.ts +37 -23
- package/package.json +3 -3
- package/lib/fileRegistry.d.ts +0 -17
- package/lib/fileRegistry.js +0 -137
package/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
export * from '@volar/source-map';
|
|
1
2
|
export * from './lib/editorFeatures';
|
|
2
|
-
export * from './lib/fileRegistry';
|
|
3
3
|
export * from './lib/linkedCodeMap';
|
|
4
4
|
export * from './lib/types';
|
|
5
5
|
export * from './lib/utils';
|
|
6
|
-
|
|
6
|
+
import { SourceMap } from '@volar/source-map';
|
|
7
|
+
import type * as ts from 'typescript';
|
|
8
|
+
import type { CodeInformation, Language, LanguagePlugin, VirtualCode } from './lib/types';
|
|
9
|
+
export declare function createLanguage(plugins: LanguagePlugin[], caseSensitive: boolean, sync: (id: string) => void): Language;
|
|
10
|
+
export declare function updateVirtualCodeMapOfMap(virtualCode: VirtualCode, mapOfMap: Map<string, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>, getSourceSnapshot: (id: string | undefined) => [string, ts.IScriptSnapshot] | undefined): void;
|
|
11
|
+
export declare function forEachEmbeddedCode(virtualCode: VirtualCode): Generator<VirtualCode>;
|
|
7
12
|
export declare function resolveCommonLanguageId(fileNameOrUri: string): string;
|
package/index.js
CHANGED
|
@@ -14,13 +14,158 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.resolveCommonLanguageId = void 0;
|
|
17
|
+
exports.resolveCommonLanguageId = exports.forEachEmbeddedCode = exports.updateVirtualCodeMapOfMap = exports.createLanguage = void 0;
|
|
18
|
+
__exportStar(require("@volar/source-map"), exports);
|
|
18
19
|
__exportStar(require("./lib/editorFeatures"), exports);
|
|
19
|
-
__exportStar(require("./lib/fileRegistry"), exports);
|
|
20
20
|
__exportStar(require("./lib/linkedCodeMap"), exports);
|
|
21
21
|
__exportStar(require("./lib/types"), exports);
|
|
22
22
|
__exportStar(require("./lib/utils"), exports);
|
|
23
|
-
|
|
23
|
+
const source_map_1 = require("@volar/source-map");
|
|
24
|
+
const linkedCodeMap_1 = require("./lib/linkedCodeMap");
|
|
25
|
+
const utils_1 = require("./lib/utils");
|
|
26
|
+
function createLanguage(plugins, caseSensitive, sync) {
|
|
27
|
+
const sourceScripts = new utils_1.FileMap(caseSensitive);
|
|
28
|
+
const virtualCodeToSourceFileMap = new WeakMap();
|
|
29
|
+
const virtualCodeToMaps = new WeakMap();
|
|
30
|
+
const virtualCodeToLinkedCodeMap = new WeakMap();
|
|
31
|
+
return {
|
|
32
|
+
plugins,
|
|
33
|
+
scripts: {
|
|
34
|
+
get(id) {
|
|
35
|
+
sync(id);
|
|
36
|
+
return sourceScripts.get(id);
|
|
37
|
+
},
|
|
38
|
+
set(id, languageId, snapshot, _plugins = plugins) {
|
|
39
|
+
if (sourceScripts.has(id)) {
|
|
40
|
+
const sourceScript = sourceScripts.get(id);
|
|
41
|
+
if (sourceScript.languageId !== languageId) {
|
|
42
|
+
// languageId changed
|
|
43
|
+
this.delete(id);
|
|
44
|
+
return this.set(id, languageId, snapshot);
|
|
45
|
+
}
|
|
46
|
+
else if (sourceScript.snapshot !== snapshot) {
|
|
47
|
+
// snapshot updated
|
|
48
|
+
sourceScript.snapshot = snapshot;
|
|
49
|
+
if (sourceScript.generated) {
|
|
50
|
+
sourceScript.generated.root = sourceScript.generated.languagePlugin.updateVirtualCode(id, sourceScript.generated.root, snapshot);
|
|
51
|
+
sourceScript.generated.embeddedCodes.clear();
|
|
52
|
+
for (const code of forEachEmbeddedCode(sourceScript.generated.root)) {
|
|
53
|
+
virtualCodeToSourceFileMap.set(code, sourceScript);
|
|
54
|
+
sourceScript.generated.embeddedCodes.set(code.id, code);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return sourceScript;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// not changed
|
|
61
|
+
return sourceScript;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// created
|
|
66
|
+
const sourceScript = { id, languageId, snapshot };
|
|
67
|
+
sourceScripts.set(id, sourceScript);
|
|
68
|
+
for (const languagePlugin of _plugins) {
|
|
69
|
+
const virtualCode = languagePlugin.createVirtualCode(id, languageId, snapshot);
|
|
70
|
+
if (virtualCode) {
|
|
71
|
+
sourceScript.generated = {
|
|
72
|
+
root: virtualCode,
|
|
73
|
+
languagePlugin,
|
|
74
|
+
embeddedCodes: new Map(),
|
|
75
|
+
};
|
|
76
|
+
for (const code of forEachEmbeddedCode(virtualCode)) {
|
|
77
|
+
virtualCodeToSourceFileMap.set(code, sourceScript);
|
|
78
|
+
sourceScript.generated.embeddedCodes.set(code.id, code);
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return sourceScript;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
delete(id) {
|
|
87
|
+
const value = sourceScripts.get(id);
|
|
88
|
+
if (value) {
|
|
89
|
+
if (value.generated) {
|
|
90
|
+
value.generated.languagePlugin.disposeVirtualCode?.(id, value.generated.root);
|
|
91
|
+
}
|
|
92
|
+
sourceScripts.delete(id);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
maps: {
|
|
97
|
+
get(virtualCode, scriptId) {
|
|
98
|
+
if (!scriptId) {
|
|
99
|
+
const sourceScript = virtualCodeToSourceFileMap.get(virtualCode);
|
|
100
|
+
if (!sourceScript) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
scriptId = sourceScript.id;
|
|
104
|
+
}
|
|
105
|
+
for (const [id, [_snapshot, map]] of this.forEach(virtualCode)) {
|
|
106
|
+
if (id === scriptId) {
|
|
107
|
+
return map;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
forEach(virtualCode) {
|
|
112
|
+
let map = virtualCodeToMaps.get(virtualCode.snapshot);
|
|
113
|
+
if (!map) {
|
|
114
|
+
map = new Map();
|
|
115
|
+
virtualCodeToMaps.set(virtualCode.snapshot, map);
|
|
116
|
+
}
|
|
117
|
+
updateVirtualCodeMapOfMap(virtualCode, map, id => {
|
|
118
|
+
if (id) {
|
|
119
|
+
const sourceScript = sourceScripts.get(id);
|
|
120
|
+
return [id, sourceScript.snapshot];
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const sourceScript = virtualCodeToSourceFileMap.get(virtualCode);
|
|
124
|
+
return [sourceScript.id, sourceScript.snapshot];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return map;
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
linkedCodeMaps: {
|
|
131
|
+
get(virtualCode) {
|
|
132
|
+
if (!virtualCodeToLinkedCodeMap.has(virtualCode.snapshot)) {
|
|
133
|
+
virtualCodeToLinkedCodeMap.set(virtualCode.snapshot, virtualCode.linkedCodeMappings
|
|
134
|
+
? new linkedCodeMap_1.LinkedCodeMap(virtualCode.linkedCodeMappings)
|
|
135
|
+
: undefined);
|
|
136
|
+
}
|
|
137
|
+
return virtualCodeToLinkedCodeMap.get(virtualCode.snapshot);
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
exports.createLanguage = createLanguage;
|
|
143
|
+
function updateVirtualCodeMapOfMap(virtualCode, mapOfMap, getSourceSnapshot) {
|
|
144
|
+
const sources = new Set();
|
|
145
|
+
for (const mapping of virtualCode.mappings) {
|
|
146
|
+
if (sources.has(mapping.source)) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
sources.add(mapping.source);
|
|
150
|
+
const source = getSourceSnapshot(mapping.source);
|
|
151
|
+
if (!source) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (!mapOfMap.has(source[0]) || mapOfMap.get(source[0])[0] !== source[1]) {
|
|
155
|
+
mapOfMap.set(source[0], [source[1], new source_map_1.SourceMap(virtualCode.mappings.filter(mapping2 => mapping2.source === mapping.source))]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.updateVirtualCodeMapOfMap = updateVirtualCodeMapOfMap;
|
|
160
|
+
function* forEachEmbeddedCode(virtualCode) {
|
|
161
|
+
yield virtualCode;
|
|
162
|
+
if (virtualCode.embeddedCodes) {
|
|
163
|
+
for (const embeddedCode of virtualCode.embeddedCodes) {
|
|
164
|
+
yield* forEachEmbeddedCode(embeddedCode);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.forEachEmbeddedCode = forEachEmbeddedCode;
|
|
24
169
|
function resolveCommonLanguageId(fileNameOrUri) {
|
|
25
170
|
const ext = fileNameOrUri.split('.').pop();
|
|
26
171
|
switch (ext) {
|
package/lib/types.d.ts
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-
import type { Mapping, Stack } from '@volar/source-map';
|
|
1
|
+
import type { Mapping, SourceMap, Stack } from '@volar/source-map';
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
|
-
import type {
|
|
4
|
-
export interface
|
|
3
|
+
import type { LinkedCodeMap } from './linkedCodeMap';
|
|
4
|
+
export interface Language {
|
|
5
|
+
plugins: LanguagePlugin[];
|
|
6
|
+
scripts: {
|
|
7
|
+
get(id: string): SourceScript | undefined;
|
|
8
|
+
set(id: string, languageId: string, snapshot: ts.IScriptSnapshot, plugins?: LanguagePlugin[]): SourceScript;
|
|
9
|
+
delete(id: string): void;
|
|
10
|
+
};
|
|
11
|
+
maps: {
|
|
12
|
+
get(virtualCode: VirtualCode, scriptId?: string): SourceMap<CodeInformation> | undefined;
|
|
13
|
+
forEach(virtualCode: VirtualCode): Map<string, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>;
|
|
14
|
+
};
|
|
15
|
+
linkedCodeMaps: {
|
|
16
|
+
get(virtualCode: VirtualCode): LinkedCodeMap | undefined;
|
|
17
|
+
};
|
|
18
|
+
typescript?: {
|
|
19
|
+
projectHost: TypeScriptProjectHost;
|
|
20
|
+
languageServiceHost: ts.LanguageServiceHost;
|
|
21
|
+
getExtraServiceScript(fileName: string): ExtraServiceScript | undefined;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface SourceScript {
|
|
5
25
|
/**
|
|
6
26
|
* uri or fileName
|
|
7
27
|
*/
|
|
@@ -9,8 +29,9 @@ export interface SourceFile {
|
|
|
9
29
|
languageId: string;
|
|
10
30
|
snapshot: ts.IScriptSnapshot;
|
|
11
31
|
generated?: {
|
|
12
|
-
|
|
32
|
+
root: VirtualCode;
|
|
13
33
|
languagePlugin: LanguagePlugin;
|
|
34
|
+
embeddedCodes: Map<string, VirtualCode>;
|
|
14
35
|
};
|
|
15
36
|
}
|
|
16
37
|
export type CodeMapping = Mapping<CodeInformation>;
|
|
@@ -57,9 +78,9 @@ export interface ExtraServiceScript extends ServiceScript {
|
|
|
57
78
|
fileName: string;
|
|
58
79
|
}
|
|
59
80
|
export interface LanguagePlugin<T extends VirtualCode = VirtualCode> {
|
|
60
|
-
createVirtualCode(
|
|
61
|
-
updateVirtualCode(
|
|
62
|
-
disposeVirtualCode?(
|
|
81
|
+
createVirtualCode(scriptId: string, languageId: string, snapshot: ts.IScriptSnapshot): T | undefined;
|
|
82
|
+
updateVirtualCode(scriptId: string, virtualCode: T, newSnapshot: ts.IScriptSnapshot): T;
|
|
83
|
+
disposeVirtualCode?(scriptId: string, virtualCode: T): void;
|
|
63
84
|
typescript?: {
|
|
64
85
|
/**
|
|
65
86
|
* LSP + TS Plugin
|
|
@@ -68,29 +89,22 @@ export interface LanguagePlugin<T extends VirtualCode = VirtualCode> {
|
|
|
68
89
|
/**
|
|
69
90
|
* LSP + TS Plugin
|
|
70
91
|
*/
|
|
71
|
-
|
|
92
|
+
getServiceScript(rootVirtualCode: T): ServiceScript | undefined;
|
|
72
93
|
/**
|
|
73
94
|
* LSP only
|
|
74
95
|
*/
|
|
75
|
-
|
|
96
|
+
getExtraServiceScripts?(fileName: string, rootVirtualCode: T): ExtraServiceScript[];
|
|
76
97
|
/**
|
|
77
98
|
* LSP only
|
|
78
99
|
*/
|
|
79
100
|
resolveLanguageServiceHost?(host: ts.LanguageServiceHost): ts.LanguageServiceHost;
|
|
80
101
|
};
|
|
81
102
|
}
|
|
82
|
-
export interface
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
projectHost: TypeScriptProjectHost;
|
|
90
|
-
languageServiceHost: ts.LanguageServiceHost;
|
|
91
|
-
getExtraScript(fileName: string): ExtraServiceScript | undefined;
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
export interface TypeScriptProjectHost extends Pick<ts.LanguageServiceHost, 'getLocalizedDiagnosticMessages' | 'getCompilationSettings' | 'getProjectReferences' | 'getCurrentDirectory' | 'getScriptFileNames' | 'getProjectVersion' | 'getScriptSnapshot'> {
|
|
95
|
-
getLanguageId(fileId: string): string;
|
|
103
|
+
export interface TypeScriptProjectHost extends ts.System, Pick<ts.LanguageServiceHost, 'getLocalizedDiagnosticMessages' | 'getCompilationSettings' | 'getProjectReferences' | 'getCurrentDirectory' | 'getScriptFileNames' | 'getProjectVersion' | 'getScriptSnapshot'> {
|
|
104
|
+
configFileName: string | undefined;
|
|
105
|
+
getLanguageId(scriptId: string): string;
|
|
106
|
+
getSystemVersion?(): number;
|
|
107
|
+
syncSystem?(): Promise<number>;
|
|
108
|
+
scriptIdToFileName(scriptId: string): string;
|
|
109
|
+
fileNameToScriptId(fileName: string): string;
|
|
96
110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-alpha.0",
|
|
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.2.0-alpha.0"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "95ffe51f944ee87f570be113541e17ddfe75f588"
|
|
18
18
|
}
|
package/lib/fileRegistry.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SourceMap } from '@volar/source-map';
|
|
2
|
-
import type * as ts from 'typescript';
|
|
3
|
-
import { LinkedCodeMap } from './linkedCodeMap';
|
|
4
|
-
import type { CodeInformation, LanguagePlugin, SourceFile, VirtualCode } from './types';
|
|
5
|
-
export type FileRegistry = ReturnType<typeof createFileRegistry>;
|
|
6
|
-
export declare function createFileRegistry(languagePlugins: LanguagePlugin[], caseSensitive: boolean, sync: (id: string) => void): {
|
|
7
|
-
languagePlugins: LanguagePlugin<VirtualCode>[];
|
|
8
|
-
set(id: string, languageId: string, snapshot: ts.IScriptSnapshot, plugins?: LanguagePlugin<VirtualCode>[]): SourceFile;
|
|
9
|
-
delete(id: string): void;
|
|
10
|
-
get(id: string): SourceFile | undefined;
|
|
11
|
-
getByVirtualCode(virtualCode: VirtualCode): SourceFile;
|
|
12
|
-
getLinkedCodeMap(virtualCode: VirtualCode): LinkedCodeMap | undefined;
|
|
13
|
-
getMaps(virtualCode: VirtualCode): Map<string, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>;
|
|
14
|
-
getVirtualCode(sourceFileId: string, virtualCodeId: string): readonly [VirtualCode, SourceFile] | readonly [undefined, undefined];
|
|
15
|
-
};
|
|
16
|
-
export declare function updateVirtualCodeMaps(virtualCode: VirtualCode, getSourceSnapshot: (sourceUri: string | undefined) => [string, ts.IScriptSnapshot] | undefined, map?: Map<string, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>): Map<string, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>;
|
|
17
|
-
export declare function forEachEmbeddedCode(code: VirtualCode): Generator<VirtualCode>;
|
package/lib/fileRegistry.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.forEachEmbeddedCode = exports.updateVirtualCodeMaps = exports.createFileRegistry = void 0;
|
|
4
|
-
const source_map_1 = require("@volar/source-map");
|
|
5
|
-
const linkedCodeMap_1 = require("./linkedCodeMap");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
function createFileRegistry(languagePlugins, caseSensitive, sync) {
|
|
8
|
-
const sourceFiles = new utils_1.FileMap(caseSensitive);
|
|
9
|
-
const virtualCodeToSourceFileMap = new WeakMap();
|
|
10
|
-
const virtualCodeToMaps = new WeakMap();
|
|
11
|
-
const virtualCodeToLinkedCodeMap = new WeakMap();
|
|
12
|
-
return {
|
|
13
|
-
languagePlugins,
|
|
14
|
-
set(id, languageId, snapshot, plugins = languagePlugins) {
|
|
15
|
-
const value = sourceFiles.get(id);
|
|
16
|
-
if (value) {
|
|
17
|
-
if (value.languageId !== languageId) {
|
|
18
|
-
// languageId changed
|
|
19
|
-
this.delete(id);
|
|
20
|
-
return this.set(id, languageId, snapshot);
|
|
21
|
-
}
|
|
22
|
-
else if (value.snapshot !== snapshot) {
|
|
23
|
-
// snapshot updated
|
|
24
|
-
value.snapshot = snapshot;
|
|
25
|
-
if (value.generated) {
|
|
26
|
-
value.generated.code = value.generated.languagePlugin.updateVirtualCode(id, value.generated.code, snapshot, this);
|
|
27
|
-
for (const code of forEachEmbeddedCode(value.generated.code)) {
|
|
28
|
-
virtualCodeToSourceFileMap.set(code, value);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
// not changed
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
// created
|
|
39
|
-
const sourceFile = { id, languageId, snapshot };
|
|
40
|
-
sourceFiles.set(id, sourceFile);
|
|
41
|
-
for (const languagePlugin of plugins) {
|
|
42
|
-
const virtualCode = languagePlugin.createVirtualCode(id, languageId, snapshot, this);
|
|
43
|
-
if (virtualCode) {
|
|
44
|
-
sourceFile.generated = {
|
|
45
|
-
code: virtualCode,
|
|
46
|
-
languagePlugin,
|
|
47
|
-
};
|
|
48
|
-
for (const code of forEachEmbeddedCode(virtualCode)) {
|
|
49
|
-
virtualCodeToSourceFileMap.set(code, sourceFile);
|
|
50
|
-
}
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return sourceFile;
|
|
55
|
-
},
|
|
56
|
-
delete(id) {
|
|
57
|
-
const value = sourceFiles.get(id);
|
|
58
|
-
if (value) {
|
|
59
|
-
if (value.generated) {
|
|
60
|
-
value.generated.languagePlugin.disposeVirtualCode?.(id, value.generated.code, this);
|
|
61
|
-
}
|
|
62
|
-
sourceFiles.delete(id);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
get(id) {
|
|
66
|
-
sync(id);
|
|
67
|
-
return sourceFiles.get(id);
|
|
68
|
-
},
|
|
69
|
-
getByVirtualCode(virtualCode) {
|
|
70
|
-
return virtualCodeToSourceFileMap.get(virtualCode);
|
|
71
|
-
},
|
|
72
|
-
getLinkedCodeMap(virtualCode) {
|
|
73
|
-
if (!virtualCodeToLinkedCodeMap.has(virtualCode.snapshot)) {
|
|
74
|
-
virtualCodeToLinkedCodeMap.set(virtualCode.snapshot, virtualCode.linkedCodeMappings
|
|
75
|
-
? new linkedCodeMap_1.LinkedCodeMap(virtualCode.linkedCodeMappings)
|
|
76
|
-
: undefined);
|
|
77
|
-
}
|
|
78
|
-
return virtualCodeToLinkedCodeMap.get(virtualCode.snapshot);
|
|
79
|
-
},
|
|
80
|
-
getMaps(virtualCode) {
|
|
81
|
-
if (!virtualCodeToMaps.has(virtualCode.snapshot)) {
|
|
82
|
-
virtualCodeToMaps.set(virtualCode.snapshot, new Map());
|
|
83
|
-
}
|
|
84
|
-
updateVirtualCodeMaps(virtualCode, sourceFileId => {
|
|
85
|
-
if (sourceFileId) {
|
|
86
|
-
const sourceFile = sourceFiles.get(sourceFileId);
|
|
87
|
-
return [sourceFileId, sourceFile.snapshot];
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
const sourceFile = virtualCodeToSourceFileMap.get(virtualCode);
|
|
91
|
-
return [sourceFile.id, sourceFile.snapshot];
|
|
92
|
-
}
|
|
93
|
-
}, virtualCodeToMaps.get(virtualCode.snapshot));
|
|
94
|
-
return virtualCodeToMaps.get(virtualCode.snapshot);
|
|
95
|
-
},
|
|
96
|
-
getVirtualCode(sourceFileId, virtualCodeId) {
|
|
97
|
-
const sourceFile = this.get(sourceFileId);
|
|
98
|
-
if (sourceFile?.generated) {
|
|
99
|
-
for (const code of forEachEmbeddedCode(sourceFile.generated.code)) {
|
|
100
|
-
if (code.id === virtualCodeId) {
|
|
101
|
-
return [code, sourceFile];
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return [undefined, undefined];
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
exports.createFileRegistry = createFileRegistry;
|
|
110
|
-
function updateVirtualCodeMaps(virtualCode, getSourceSnapshot, map = new Map()) {
|
|
111
|
-
const sources = new Set();
|
|
112
|
-
for (const mapping of virtualCode.mappings) {
|
|
113
|
-
if (sources.has(mapping.source)) {
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
sources.add(mapping.source);
|
|
117
|
-
const source = getSourceSnapshot(mapping.source);
|
|
118
|
-
if (!source) {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (!map.has(source[0]) || map.get(source[0])[0] !== source[1]) {
|
|
122
|
-
map.set(source[0], [source[1], new source_map_1.SourceMap(virtualCode.mappings.filter(mapping2 => mapping2.source === mapping.source))]);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return map;
|
|
126
|
-
}
|
|
127
|
-
exports.updateVirtualCodeMaps = updateVirtualCodeMaps;
|
|
128
|
-
function* forEachEmbeddedCode(code) {
|
|
129
|
-
yield code;
|
|
130
|
-
if (code.embeddedCodes) {
|
|
131
|
-
for (const embeddedCode of code.embeddedCodes) {
|
|
132
|
-
yield* forEachEmbeddedCode(embeddedCode);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
exports.forEachEmbeddedCode = forEachEmbeddedCode;
|
|
137
|
-
//# sourceMappingURL=fileRegistry.js.map
|