@volar/language-core 2.4.10 → 2.4.12
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 +14 -8
- package/lib/types.d.ts +30 -3
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export * from './lib/types';
|
|
|
5
5
|
export * from './lib/utils';
|
|
6
6
|
import type { Language, LanguagePlugin, MapperFactory, SourceScript, VirtualCode } from './lib/types';
|
|
7
7
|
export declare const defaultMapperFactory: MapperFactory;
|
|
8
|
-
export declare function createLanguage<T>(plugins: LanguagePlugin<T>[], scriptRegistry: Map<T, SourceScript<T>>, sync: (id: T, includeFsFiles: boolean) => void): Language<T>;
|
|
8
|
+
export declare function createLanguage<T>(plugins: LanguagePlugin<T>[], scriptRegistry: Map<T, SourceScript<T>>, sync: (id: T, includeFsFiles: boolean, shouldRegister: boolean) => void, onAssociationDirty?: (targetId: T) => void): Language<T>;
|
|
9
9
|
export declare function forEachEmbeddedCode(virtualCode: VirtualCode): Generator<VirtualCode>;
|
package/index.js
CHANGED
|
@@ -27,7 +27,7 @@ const source_map_2 = require("@volar/source-map");
|
|
|
27
27
|
const linkedCodeMap_1 = require("./lib/linkedCodeMap");
|
|
28
28
|
const defaultMapperFactory = mappings => new source_map_2.SourceMap(mappings);
|
|
29
29
|
exports.defaultMapperFactory = defaultMapperFactory;
|
|
30
|
-
function createLanguage(plugins, scriptRegistry, sync) {
|
|
30
|
+
function createLanguage(plugins, scriptRegistry, sync, onAssociationDirty) {
|
|
31
31
|
const virtualCodeToSourceScriptMap = new WeakMap();
|
|
32
32
|
const virtualCodeToSourceMap = new WeakMap();
|
|
33
33
|
const virtualCodeToLinkedCodeMap = new WeakMap();
|
|
@@ -38,8 +38,8 @@ function createLanguage(plugins, scriptRegistry, sync) {
|
|
|
38
38
|
fromVirtualCode(virtualCode) {
|
|
39
39
|
return virtualCodeToSourceScriptMap.get(virtualCode);
|
|
40
40
|
},
|
|
41
|
-
get(id, includeFsFiles = true) {
|
|
42
|
-
sync(id, includeFsFiles);
|
|
41
|
+
get(id, includeFsFiles = true, shouldRegister = false) {
|
|
42
|
+
sync(id, includeFsFiles, shouldRegister);
|
|
43
43
|
const result = scriptRegistry.get(id);
|
|
44
44
|
// The sync function provider may not always call the set function due to caching, so it is necessary to explicitly check isAssociationDirty.
|
|
45
45
|
if (result?.isAssociationDirty) {
|
|
@@ -71,14 +71,20 @@ function createLanguage(plugins, scriptRegistry, sync) {
|
|
|
71
71
|
const sourceScript = scriptRegistry.get(id);
|
|
72
72
|
if (sourceScript.languageId !== languageId || sourceScript.associatedOnly !== associatedOnly) {
|
|
73
73
|
this.delete(id);
|
|
74
|
+
triggerTargetsDirty(sourceScript);
|
|
74
75
|
return this.set(id, snapshot, languageId);
|
|
75
76
|
}
|
|
76
77
|
else if (associatedOnly) {
|
|
77
|
-
sourceScript.snapshot
|
|
78
|
+
if (sourceScript.snapshot !== snapshot) {
|
|
79
|
+
sourceScript.snapshot = snapshot;
|
|
80
|
+
triggerTargetsDirty(sourceScript);
|
|
81
|
+
}
|
|
78
82
|
}
|
|
79
83
|
else if (sourceScript.isAssociationDirty || sourceScript.snapshot !== snapshot) {
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
if (sourceScript.snapshot !== snapshot) {
|
|
85
|
+
sourceScript.snapshot = snapshot;
|
|
86
|
+
triggerTargetsDirty(sourceScript);
|
|
87
|
+
}
|
|
82
88
|
const codegenCtx = prepareCreateVirtualCode(sourceScript);
|
|
83
89
|
if (sourceScript.generated) {
|
|
84
90
|
const { updateVirtualCode, createVirtualCode } = sourceScript.generated.languagePlugin;
|
|
@@ -99,7 +105,6 @@ function createLanguage(plugins, scriptRegistry, sync) {
|
|
|
99
105
|
return;
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
|
-
triggerTargetsDirty(sourceScript);
|
|
103
108
|
}
|
|
104
109
|
else {
|
|
105
110
|
// not changed
|
|
@@ -200,6 +205,7 @@ function createLanguage(plugins, scriptRegistry, sync) {
|
|
|
200
205
|
const sourceScript = scriptRegistry.get(id);
|
|
201
206
|
if (sourceScript) {
|
|
202
207
|
sourceScript.isAssociationDirty = true;
|
|
208
|
+
onAssociationDirty?.(sourceScript.id);
|
|
203
209
|
}
|
|
204
210
|
});
|
|
205
211
|
}
|
|
@@ -211,7 +217,7 @@ function createLanguage(plugins, scriptRegistry, sync) {
|
|
|
211
217
|
sourceScript.isAssociationDirty = false;
|
|
212
218
|
return {
|
|
213
219
|
getAssociatedScript(id) {
|
|
214
|
-
sync(id, true);
|
|
220
|
+
sync(id, true, true);
|
|
215
221
|
const relatedSourceScript = scriptRegistry.get(id);
|
|
216
222
|
if (relatedSourceScript) {
|
|
217
223
|
relatedSourceScript.targetIds.add(sourceScript.id);
|
package/lib/types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface Language<T = unknown> {
|
|
|
12
12
|
mapperFactory: MapperFactory;
|
|
13
13
|
plugins: LanguagePlugin<T>[];
|
|
14
14
|
scripts: {
|
|
15
|
-
get(id: T, includeFsFiles?: boolean): SourceScript<T> | undefined;
|
|
15
|
+
get(id: T, includeFsFiles?: boolean, shouldRegister?: boolean): SourceScript<T> | undefined;
|
|
16
16
|
set(id: T, snapshot: IScriptSnapshot, languageId?: string, plugins?: LanguagePlugin<T>[]): SourceScript<T> | undefined;
|
|
17
17
|
delete(id: T): void;
|
|
18
18
|
fromVirtualCode(virtualCode: VirtualCode): SourceScript<T>;
|
|
@@ -49,9 +49,27 @@ export interface VirtualCode {
|
|
|
49
49
|
embeddedCodes?: VirtualCode[];
|
|
50
50
|
linkedCodeMappings?: Mapping[];
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* CodeInformation is a configuration object attached to each CodeMapping (between source code and generated code,
|
|
54
|
+
* e.g. between the template code in a .vue file and the type-checkable TS code generated from it) that
|
|
55
|
+
* determines what code/language features are expected to be available for the mapping.
|
|
56
|
+
*
|
|
57
|
+
* Due to the dynamic nature of code generation and the fact that, for example, things like Code Actions
|
|
58
|
+
* and auto-complete shouldn't be triggerable on certain "in-between" regions of generated code, we need
|
|
59
|
+
* a way to shut off certain features in certain regions, while leaving them enabled in others.
|
|
60
|
+
*/
|
|
52
61
|
export interface CodeInformation {
|
|
53
|
-
/** virtual code is expected to support verification
|
|
62
|
+
/** virtual code is expected to support verification, where verification includes:
|
|
63
|
+
*
|
|
64
|
+
* - diagnostics (syntactic, semantic, and others, such as those generated by the TypeScript language service on generated TS code)
|
|
65
|
+
* - code actions (refactorings, quick fixes,etc.)
|
|
66
|
+
*/
|
|
54
67
|
verification?: boolean | {
|
|
68
|
+
/**
|
|
69
|
+
* when present, `shouldReport` callback is invoked to determine whether a diagnostic
|
|
70
|
+
* raised in the generated code should be propagated back to the original source code.
|
|
71
|
+
* Note that when this callback is present, diagnostic processing (e.g. typechecking) will
|
|
72
|
+
* still be performed, but the results will not be reported back to the original source code. */
|
|
55
73
|
shouldReport?(source: string | undefined, code: string | number | undefined): boolean;
|
|
56
74
|
};
|
|
57
75
|
/** virtual code is expected to support assisted completion */
|
|
@@ -59,7 +77,16 @@ export interface CodeInformation {
|
|
|
59
77
|
isAdditional?: boolean;
|
|
60
78
|
onlyImport?: boolean;
|
|
61
79
|
};
|
|
62
|
-
/** virtual code is expected correctly reflect semantic of the source code
|
|
80
|
+
/** virtual code is expected correctly reflect semantic of the source code. Specifically this controls the following langauge features:
|
|
81
|
+
*
|
|
82
|
+
* - hover
|
|
83
|
+
* - inlay hints
|
|
84
|
+
* - code lens
|
|
85
|
+
* - semantic tokens
|
|
86
|
+
* - others
|
|
87
|
+
*
|
|
88
|
+
* Note that semantic diagnostics (e.g. TS type-checking) are covered by the `verification` property above.
|
|
89
|
+
*/
|
|
63
90
|
semantic?: boolean | {
|
|
64
91
|
shouldHighlight?(): boolean;
|
|
65
92
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-core",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.12",
|
|
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.4.
|
|
15
|
+
"@volar/source-map": "2.4.12"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "17b9b8a1f522afd1aad1e598d2fd935680d8a8d7"
|
|
18
18
|
}
|