@volar/language-core 2.3.5-alpha.1 → 2.3.5-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/types.d.ts +27 -42
- package/package.json +3 -3
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Mapping } from '@volar/source-map';
|
|
2
|
-
import type * as ts from 'typescript';
|
|
3
2
|
import type { LinkedCodeMap } from './linkedCodeMap';
|
|
4
3
|
export interface Mapper {
|
|
5
4
|
mappings: Mapping<CodeInformation>[];
|
|
@@ -14,7 +13,7 @@ export interface Language<T = unknown> {
|
|
|
14
13
|
plugins: LanguagePlugin<T>[];
|
|
15
14
|
scripts: {
|
|
16
15
|
get(id: T): SourceScript<T> | undefined;
|
|
17
|
-
set(id: T, snapshot:
|
|
16
|
+
set(id: T, snapshot: IScriptSnapshot, languageId?: string, plugins?: LanguagePlugin<T>[]): SourceScript<T> | undefined;
|
|
18
17
|
delete(id: T): void;
|
|
19
18
|
fromVirtualCode(virtualCode: VirtualCode): SourceScript<T>;
|
|
20
19
|
};
|
|
@@ -25,22 +24,11 @@ export interface Language<T = unknown> {
|
|
|
25
24
|
linkedCodeMaps: {
|
|
26
25
|
get(virtualCode: VirtualCode): LinkedCodeMap | undefined;
|
|
27
26
|
};
|
|
28
|
-
typescript?: {
|
|
29
|
-
configFileName: string | undefined;
|
|
30
|
-
sys: ts.System & {
|
|
31
|
-
version?: number;
|
|
32
|
-
sync?(): Promise<number>;
|
|
33
|
-
};
|
|
34
|
-
languageServiceHost: ts.LanguageServiceHost;
|
|
35
|
-
getExtraServiceScript(fileName: string): TypeScriptExtraServiceScript | undefined;
|
|
36
|
-
asScriptId(fileName: string): T;
|
|
37
|
-
asFileName(scriptId: T): string;
|
|
38
|
-
};
|
|
39
27
|
}
|
|
40
28
|
export interface SourceScript<T = unknown> {
|
|
41
29
|
id: T;
|
|
42
30
|
languageId: string;
|
|
43
|
-
snapshot:
|
|
31
|
+
snapshot: IScriptSnapshot;
|
|
44
32
|
targetIds: Set<T>;
|
|
45
33
|
associatedIds: Set<T>;
|
|
46
34
|
associatedOnly: boolean;
|
|
@@ -55,7 +43,7 @@ export type CodeMapping = Mapping<CodeInformation>;
|
|
|
55
43
|
export interface VirtualCode {
|
|
56
44
|
id: string;
|
|
57
45
|
languageId: string;
|
|
58
|
-
snapshot:
|
|
46
|
+
snapshot: IScriptSnapshot;
|
|
59
47
|
mappings: CodeMapping[];
|
|
60
48
|
associatedScriptMappings?: Map<unknown, CodeMapping[]>;
|
|
61
49
|
embeddedCodes?: VirtualCode[];
|
|
@@ -86,16 +74,6 @@ export interface CodeInformation {
|
|
|
86
74
|
/** virtual code is expected correctly reflect the format information of the source code */
|
|
87
75
|
format?: boolean;
|
|
88
76
|
}
|
|
89
|
-
export interface TypeScriptServiceScript {
|
|
90
|
-
code: VirtualCode;
|
|
91
|
-
extension: '.ts' | '.js' | '.mts' | '.mjs' | '.cjs' | '.cts' | '.d.ts' | string;
|
|
92
|
-
scriptKind: ts.ScriptKind;
|
|
93
|
-
/** See #188 */
|
|
94
|
-
preventLeadingOffset?: boolean;
|
|
95
|
-
}
|
|
96
|
-
export interface TypeScriptExtraServiceScript extends TypeScriptServiceScript {
|
|
97
|
-
fileName: string;
|
|
98
|
-
}
|
|
99
77
|
export interface LanguagePlugin<T = unknown, K extends VirtualCode = VirtualCode> {
|
|
100
78
|
/**
|
|
101
79
|
* 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.
|
|
@@ -104,11 +82,11 @@ export interface LanguagePlugin<T = unknown, K extends VirtualCode = VirtualCode
|
|
|
104
82
|
/**
|
|
105
83
|
* Generate a virtual code.
|
|
106
84
|
*/
|
|
107
|
-
createVirtualCode?(scriptId: T, languageId: string, snapshot:
|
|
85
|
+
createVirtualCode?(scriptId: T, languageId: string, snapshot: IScriptSnapshot, ctx: CodegenContext<T>): K | undefined;
|
|
108
86
|
/**
|
|
109
87
|
* Incremental update a virtual code. If not provide, call createVirtualCode again.
|
|
110
88
|
*/
|
|
111
|
-
updateVirtualCode?(scriptId: T, virtualCode: K, newSnapshot:
|
|
89
|
+
updateVirtualCode?(scriptId: T, virtualCode: K, newSnapshot: IScriptSnapshot, ctx: CodegenContext<T>): K | undefined;
|
|
112
90
|
/**
|
|
113
91
|
* Cleanup a virtual code.
|
|
114
92
|
*/
|
|
@@ -120,24 +98,31 @@ export interface LanguagePlugin<T = unknown, K extends VirtualCode = VirtualCode
|
|
|
120
98
|
* This functionality is required only in TS plugin mode.
|
|
121
99
|
*/
|
|
122
100
|
isAssociatedFileOnly?(scriptId: T, languageId: string): boolean;
|
|
123
|
-
typescript?: TypeScriptGenericOptions<K> & TypeScriptNonTSPluginOptions<K>;
|
|
124
101
|
}
|
|
125
102
|
export interface CodegenContext<T = unknown> {
|
|
126
103
|
getAssociatedScript(scriptId: T): SourceScript<T> | undefined;
|
|
127
104
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
105
|
+
export interface IScriptSnapshot {
|
|
106
|
+
/** Gets a portion of the script snapshot specified by [start, end). */
|
|
107
|
+
getText(start: number, end: number): string;
|
|
108
|
+
/** Gets the length of this script snapshot. */
|
|
109
|
+
getLength(): number;
|
|
110
|
+
/**
|
|
111
|
+
* Gets the TextChangeRange that describe how the text changed between this text and
|
|
112
|
+
* an older version. This information is used by the incremental parser to determine
|
|
113
|
+
* what sections of the script need to be re-parsed. 'undefined' can be returned if the
|
|
114
|
+
* change range cannot be determined. However, in that case, incremental parsing will
|
|
115
|
+
* not happen and the entire document will be re - parsed.
|
|
116
|
+
*/
|
|
117
|
+
getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined;
|
|
118
|
+
/** Releases all resources held by this script snapshot */
|
|
119
|
+
dispose?(): void;
|
|
120
|
+
}
|
|
121
|
+
export interface TextChangeRange {
|
|
122
|
+
span: TextSpan;
|
|
123
|
+
newLength: number;
|
|
135
124
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
interface TypeScriptNonTSPluginOptions<K> {
|
|
140
|
-
getExtraServiceScripts?(fileName: string, rootVirtualCode: K): TypeScriptExtraServiceScript[];
|
|
141
|
-
resolveLanguageServiceHost?(host: ts.LanguageServiceHost): ts.LanguageServiceHost;
|
|
125
|
+
export interface TextSpan {
|
|
126
|
+
start: number;
|
|
127
|
+
length: number;
|
|
142
128
|
}
|
|
143
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-core",
|
|
3
|
-
"version": "2.3.5-alpha.
|
|
3
|
+
"version": "2.3.5-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.3.5-alpha.
|
|
15
|
+
"@volar/source-map": "2.3.5-alpha.2"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "875106ba581210ab30829170585205cdb69b73ec"
|
|
18
18
|
}
|