@volar/language-core 2.0.0-alpha.0 → 2.0.0-alpha.2
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/lib/fileProvider.d.ts +5 -5
- package/lib/fileProvider.js +23 -23
- package/lib/types.d.ts +2 -9
- package/package.json +3 -3
package/lib/fileProvider.d.ts
CHANGED
|
@@ -3,13 +3,13 @@ import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
|
3
3
|
import { LinkedCodeMap } from './linkedCodeMap';
|
|
4
4
|
import type { CodeInformation, LanguagePlugin, SourceFile, VirtualFile } from './types';
|
|
5
5
|
export type FileProvider = ReturnType<typeof createFileProvider>;
|
|
6
|
-
export declare function createFileProvider(languages: LanguagePlugin[], caseSensitive: boolean, sync: (
|
|
7
|
-
updateSourceFile(
|
|
8
|
-
deleteSourceFile(
|
|
6
|
+
export declare function createFileProvider(languages: LanguagePlugin[], caseSensitive: boolean, sync: (sourceFileName: string) => void): {
|
|
7
|
+
updateSourceFile(fileName: string, languageId: string, snapshot: ts.IScriptSnapshot): SourceFile;
|
|
8
|
+
deleteSourceFile(fileName: string): void;
|
|
9
9
|
getLinkedCodeMap(file: VirtualFile): LinkedCodeMap | undefined;
|
|
10
10
|
getMaps(virtualFile: VirtualFile): Map<string, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>;
|
|
11
|
-
getSourceFile(
|
|
12
|
-
getVirtualFile(
|
|
11
|
+
getSourceFile(fileName: string): SourceFile | undefined;
|
|
12
|
+
getVirtualFile(fileName: string): [VirtualFile, SourceFile] | readonly [undefined, undefined];
|
|
13
13
|
};
|
|
14
14
|
export declare function updateVirtualFileMaps(virtualFile: VirtualFile, getSourceSnapshot: (sourceUri: string | undefined) => [string, ts.IScriptSnapshot] | undefined, map?: Map<string, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>): Map<string, [ts.IScriptSnapshot, SourceMap<CodeInformation>]>;
|
|
15
15
|
export declare function forEachEmbeddedFile(file: VirtualFile): Generator<VirtualFile>;
|
package/lib/fileProvider.js
CHANGED
|
@@ -10,13 +10,13 @@ function createFileProvider(languages, caseSensitive, sync) {
|
|
|
10
10
|
const virtualFileToMaps = new WeakMap();
|
|
11
11
|
const virtualFileToLinkedCodeMap = new WeakMap();
|
|
12
12
|
return {
|
|
13
|
-
updateSourceFile(
|
|
14
|
-
const value = sourceFileRegistry.get(
|
|
13
|
+
updateSourceFile(fileName, languageId, snapshot) {
|
|
14
|
+
const value = sourceFileRegistry.get(fileName);
|
|
15
15
|
if (value) {
|
|
16
16
|
if (value.languageId !== languageId) {
|
|
17
17
|
// languageId changed
|
|
18
|
-
this.deleteSourceFile(
|
|
19
|
-
return this.updateSourceFile(
|
|
18
|
+
this.deleteSourceFile(fileName);
|
|
19
|
+
return this.updateSourceFile(fileName, languageId, snapshot);
|
|
20
20
|
}
|
|
21
21
|
else if (value.snapshot !== snapshot) {
|
|
22
22
|
// updated
|
|
@@ -34,31 +34,31 @@ function createFileProvider(languages, caseSensitive, sync) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
for (const language of languages) {
|
|
37
|
-
const virtualFile = language.createVirtualFile(
|
|
37
|
+
const virtualFile = language.createVirtualFile(fileName, languageId, snapshot);
|
|
38
38
|
if (virtualFile) {
|
|
39
39
|
// created
|
|
40
40
|
const source = {
|
|
41
|
-
|
|
41
|
+
fileName,
|
|
42
42
|
languageId,
|
|
43
43
|
snapshot,
|
|
44
44
|
virtualFile: [virtualFile, language],
|
|
45
45
|
};
|
|
46
|
-
sourceFileRegistry.set(
|
|
46
|
+
sourceFileRegistry.set(fileName, source);
|
|
47
47
|
updateVirtualFiles(source);
|
|
48
48
|
return source;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
const source = {
|
|
52
|
-
sourceFileRegistry.set(
|
|
51
|
+
const source = { fileName, languageId, snapshot };
|
|
52
|
+
sourceFileRegistry.set(fileName, source);
|
|
53
53
|
return source;
|
|
54
54
|
},
|
|
55
|
-
deleteSourceFile(
|
|
56
|
-
const value = sourceFileRegistry.get(
|
|
55
|
+
deleteSourceFile(fileName) {
|
|
56
|
+
const value = sourceFileRegistry.get(fileName);
|
|
57
57
|
if (value) {
|
|
58
58
|
if (value.virtualFile) {
|
|
59
59
|
value.virtualFile[1].disposeVirtualFile?.(value.virtualFile[0]);
|
|
60
60
|
}
|
|
61
|
-
sourceFileRegistry.delete(
|
|
61
|
+
sourceFileRegistry.delete(fileName); // deleted
|
|
62
62
|
disposeVirtualFiles(value);
|
|
63
63
|
}
|
|
64
64
|
},
|
|
@@ -78,21 +78,21 @@ function createFileProvider(languages, caseSensitive, sync) {
|
|
|
78
78
|
return [sourceId, sourceFile.snapshot];
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
|
-
const sourceFile = virtualFileRegistry.get(virtualFile.
|
|
82
|
-
return [sourceFile.
|
|
81
|
+
const sourceFile = virtualFileRegistry.get(virtualFile.fileName)[1];
|
|
82
|
+
return [sourceFile.fileName, sourceFile.snapshot];
|
|
83
83
|
}
|
|
84
84
|
}, virtualFileToMaps.get(virtualFile.snapshot));
|
|
85
85
|
return virtualFileToMaps.get(virtualFile.snapshot);
|
|
86
86
|
},
|
|
87
|
-
getSourceFile(
|
|
88
|
-
sync(
|
|
89
|
-
return sourceFileRegistry.get(
|
|
87
|
+
getSourceFile(fileName) {
|
|
88
|
+
sync(fileName);
|
|
89
|
+
return sourceFileRegistry.get(fileName);
|
|
90
90
|
},
|
|
91
|
-
getVirtualFile(
|
|
92
|
-
let sourceAndVirtual = virtualFileRegistry.get(
|
|
91
|
+
getVirtualFile(fileName) {
|
|
92
|
+
let sourceAndVirtual = virtualFileRegistry.get(fileName);
|
|
93
93
|
if (sourceAndVirtual) {
|
|
94
|
-
sync(sourceAndVirtual[1].
|
|
95
|
-
sourceAndVirtual = virtualFileRegistry.get(
|
|
94
|
+
sync(sourceAndVirtual[1].fileName);
|
|
95
|
+
sourceAndVirtual = virtualFileRegistry.get(fileName);
|
|
96
96
|
if (sourceAndVirtual) {
|
|
97
97
|
return sourceAndVirtual;
|
|
98
98
|
}
|
|
@@ -103,14 +103,14 @@ function createFileProvider(languages, caseSensitive, sync) {
|
|
|
103
103
|
function disposeVirtualFiles(source) {
|
|
104
104
|
if (source.virtualFile) {
|
|
105
105
|
for (const file of forEachEmbeddedFile(source.virtualFile[0])) {
|
|
106
|
-
virtualFileRegistry.delete(file.
|
|
106
|
+
virtualFileRegistry.delete(file.fileName);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
function updateVirtualFiles(source) {
|
|
111
111
|
if (source.virtualFile) {
|
|
112
112
|
for (const file of forEachEmbeddedFile(source.virtualFile[0])) {
|
|
113
|
-
virtualFileRegistry.set(file.
|
|
113
|
+
virtualFileRegistry.set(file.fileName, [file, source]);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -39,12 +39,7 @@ export interface CodeInformation {
|
|
|
39
39
|
format: boolean;
|
|
40
40
|
}
|
|
41
41
|
export interface BaseFile {
|
|
42
|
-
|
|
43
|
-
* for language-server, kit, monaco, this is uri
|
|
44
|
-
*
|
|
45
|
-
* for typescript server plugin, tsc, this is fileName
|
|
46
|
-
*/
|
|
47
|
-
id: string;
|
|
42
|
+
fileName: string;
|
|
48
43
|
languageId: string;
|
|
49
44
|
snapshot: ts.IScriptSnapshot;
|
|
50
45
|
}
|
|
@@ -69,7 +64,5 @@ export interface Language {
|
|
|
69
64
|
};
|
|
70
65
|
}
|
|
71
66
|
export interface TypeScriptProjectHost extends Pick<ts.LanguageServiceHost, 'getLocalizedDiagnosticMessages' | 'getCompilationSettings' | 'getProjectReferences' | 'getCurrentDirectory' | 'getScriptFileNames' | 'getProjectVersion' | 'getScriptSnapshot' | 'getCancellationToken'> {
|
|
72
|
-
|
|
73
|
-
getFileName(fileId: string): string;
|
|
74
|
-
getLanguageId(id: string): string;
|
|
67
|
+
getLanguageId(fileName: string): string;
|
|
75
68
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-core",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.2",
|
|
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.0.0-alpha.
|
|
15
|
+
"@volar/source-map": "2.0.0-alpha.2"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "88e80b9f00541ab9478b9c7b7af213813fc8cb20"
|
|
18
18
|
}
|