@volar/language-core 2.4.11 → 2.4.13

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 CHANGED
@@ -1,9 +1,9 @@
1
1
  export { Mapping, SourceMap } from '@volar/source-map';
2
- export * from './lib/editorFeatures';
2
+ export * from './lib/editor';
3
3
  export * from './lib/linkedCodeMap';
4
4
  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, shouldRegister: 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
@@ -19,7 +19,7 @@ exports.createLanguage = createLanguage;
19
19
  exports.forEachEmbeddedCode = forEachEmbeddedCode;
20
20
  var source_map_1 = require("@volar/source-map");
21
21
  Object.defineProperty(exports, "SourceMap", { enumerable: true, get: function () { return source_map_1.SourceMap; } });
22
- __exportStar(require("./lib/editorFeatures"), exports);
22
+ __exportStar(require("./lib/editor"), exports);
23
23
  __exportStar(require("./lib/linkedCodeMap"), exports);
24
24
  __exportStar(require("./lib/types"), exports);
25
25
  __exportStar(require("./lib/utils"), exports);
@@ -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();
@@ -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 = 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
- // snapshot updated
81
- sourceScript.snapshot = snapshot;
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
  }
@@ -0,0 +1,34 @@
1
+ import type { CodeInformation, Mapper } from './types';
2
+ export declare function isHoverEnabled(info: CodeInformation): boolean;
3
+ export declare function isInlayHintsEnabled(info: CodeInformation): boolean;
4
+ export declare function isCodeLensEnabled(info: CodeInformation): boolean;
5
+ export declare function isMonikerEnabled(info: CodeInformation): boolean;
6
+ export declare function isInlineValueEnabled(info: CodeInformation): boolean;
7
+ export declare function isSemanticTokensEnabled(info: CodeInformation): boolean;
8
+ export declare function isCallHierarchyEnabled(info: CodeInformation): boolean;
9
+ export declare function isTypeHierarchyEnabled(info: CodeInformation): boolean;
10
+ export declare function isRenameEnabled(info: CodeInformation): boolean;
11
+ export declare function isDefinitionEnabled(info: CodeInformation): boolean;
12
+ export declare function isTypeDefinitionEnabled(info: CodeInformation): boolean;
13
+ export declare function isReferencesEnabled(info: CodeInformation): boolean;
14
+ export declare function isImplementationEnabled(info: CodeInformation): boolean;
15
+ export declare function isHighlightEnabled(info: CodeInformation): boolean;
16
+ export declare function isSymbolsEnabled(info: CodeInformation): boolean;
17
+ export declare function isFoldingRangesEnabled(info: CodeInformation): boolean;
18
+ export declare function isSelectionRangesEnabled(info: CodeInformation): boolean;
19
+ export declare function isLinkedEditingEnabled(info: CodeInformation): boolean;
20
+ export declare function isColorEnabled(info: CodeInformation): boolean;
21
+ export declare function isDocumentLinkEnabled(info: CodeInformation): boolean;
22
+ export declare function isDiagnosticsEnabled(info: CodeInformation): boolean;
23
+ export declare function isCodeActionsEnabled(info: CodeInformation): boolean;
24
+ export declare function isFormattingEnabled(info: CodeInformation): boolean;
25
+ export declare function isCompletionEnabled(info: CodeInformation): boolean;
26
+ export declare function isAutoInsertEnabled(info: CodeInformation): boolean;
27
+ export declare function isSignatureHelpEnabled(info: CodeInformation): boolean;
28
+ export declare function shouldReportDiagnostics(info: CodeInformation, source: string | undefined, code: string | number | undefined): boolean;
29
+ export declare function resolveRenameNewName(newName: string, info: CodeInformation): string;
30
+ export declare function resolveRenameEditText(text: string, info: CodeInformation): string;
31
+ export declare function findOverlapCodeRange(start: number, end: number, map: Mapper, filter: (data: CodeInformation) => boolean): {
32
+ start: number;
33
+ end: number;
34
+ } | undefined;
package/lib/editor.js ADDED
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isHoverEnabled = isHoverEnabled;
4
+ exports.isInlayHintsEnabled = isInlayHintsEnabled;
5
+ exports.isCodeLensEnabled = isCodeLensEnabled;
6
+ exports.isMonikerEnabled = isMonikerEnabled;
7
+ exports.isInlineValueEnabled = isInlineValueEnabled;
8
+ exports.isSemanticTokensEnabled = isSemanticTokensEnabled;
9
+ exports.isCallHierarchyEnabled = isCallHierarchyEnabled;
10
+ exports.isTypeHierarchyEnabled = isTypeHierarchyEnabled;
11
+ exports.isRenameEnabled = isRenameEnabled;
12
+ exports.isDefinitionEnabled = isDefinitionEnabled;
13
+ exports.isTypeDefinitionEnabled = isTypeDefinitionEnabled;
14
+ exports.isReferencesEnabled = isReferencesEnabled;
15
+ exports.isImplementationEnabled = isImplementationEnabled;
16
+ exports.isHighlightEnabled = isHighlightEnabled;
17
+ exports.isSymbolsEnabled = isSymbolsEnabled;
18
+ exports.isFoldingRangesEnabled = isFoldingRangesEnabled;
19
+ exports.isSelectionRangesEnabled = isSelectionRangesEnabled;
20
+ exports.isLinkedEditingEnabled = isLinkedEditingEnabled;
21
+ exports.isColorEnabled = isColorEnabled;
22
+ exports.isDocumentLinkEnabled = isDocumentLinkEnabled;
23
+ exports.isDiagnosticsEnabled = isDiagnosticsEnabled;
24
+ exports.isCodeActionsEnabled = isCodeActionsEnabled;
25
+ exports.isFormattingEnabled = isFormattingEnabled;
26
+ exports.isCompletionEnabled = isCompletionEnabled;
27
+ exports.isAutoInsertEnabled = isAutoInsertEnabled;
28
+ exports.isSignatureHelpEnabled = isSignatureHelpEnabled;
29
+ exports.shouldReportDiagnostics = shouldReportDiagnostics;
30
+ exports.resolveRenameNewName = resolveRenameNewName;
31
+ exports.resolveRenameEditText = resolveRenameEditText;
32
+ exports.findOverlapCodeRange = findOverlapCodeRange;
33
+ function isHoverEnabled(info) {
34
+ return !!info.semantic;
35
+ }
36
+ function isInlayHintsEnabled(info) {
37
+ return !!info.semantic;
38
+ }
39
+ function isCodeLensEnabled(info) {
40
+ return !!info.semantic;
41
+ }
42
+ function isMonikerEnabled(info) {
43
+ return !!info.semantic;
44
+ }
45
+ function isInlineValueEnabled(info) {
46
+ return !!info.semantic;
47
+ }
48
+ function isSemanticTokensEnabled(info) {
49
+ return typeof info.semantic === 'object'
50
+ ? info.semantic.shouldHighlight?.() ?? true
51
+ : !!info.semantic;
52
+ }
53
+ function isCallHierarchyEnabled(info) {
54
+ return !!info.navigation;
55
+ }
56
+ function isTypeHierarchyEnabled(info) {
57
+ return !!info.navigation;
58
+ }
59
+ function isRenameEnabled(info) {
60
+ return typeof info.navigation === 'object'
61
+ ? info.navigation.shouldRename?.() ?? true
62
+ : !!info.navigation;
63
+ }
64
+ function isDefinitionEnabled(info) {
65
+ return !!info.navigation;
66
+ }
67
+ function isTypeDefinitionEnabled(info) {
68
+ return !!info.navigation;
69
+ }
70
+ function isReferencesEnabled(info) {
71
+ return !!info.navigation;
72
+ }
73
+ function isImplementationEnabled(info) {
74
+ return !!info.navigation;
75
+ }
76
+ function isHighlightEnabled(info) {
77
+ return !!info.navigation;
78
+ }
79
+ function isSymbolsEnabled(info) {
80
+ return !!info.structure;
81
+ }
82
+ function isFoldingRangesEnabled(info) {
83
+ return !!info.structure;
84
+ }
85
+ function isSelectionRangesEnabled(info) {
86
+ return !!info.structure;
87
+ }
88
+ function isLinkedEditingEnabled(info) {
89
+ return !!info.structure;
90
+ }
91
+ function isColorEnabled(info) {
92
+ return !!info.structure;
93
+ }
94
+ function isDocumentLinkEnabled(info) {
95
+ return !!info.structure;
96
+ }
97
+ function isDiagnosticsEnabled(info) {
98
+ return !!info.verification;
99
+ }
100
+ function isCodeActionsEnabled(info) {
101
+ return !!info.verification;
102
+ }
103
+ function isFormattingEnabled(info) {
104
+ return !!info.format;
105
+ }
106
+ function isCompletionEnabled(info) {
107
+ return !!info.completion;
108
+ }
109
+ function isAutoInsertEnabled(info) {
110
+ return !!info.completion;
111
+ }
112
+ function isSignatureHelpEnabled(info) {
113
+ return !!info.completion;
114
+ }
115
+ // should...
116
+ function shouldReportDiagnostics(info, source, code) {
117
+ return typeof info.verification === 'object'
118
+ ? info.verification.shouldReport?.(source, code) ?? true
119
+ : !!info.verification;
120
+ }
121
+ // resolve...
122
+ function resolveRenameNewName(newName, info) {
123
+ return typeof info.navigation === 'object'
124
+ ? info.navigation.resolveRenameNewName?.(newName) ?? newName
125
+ : newName;
126
+ }
127
+ function resolveRenameEditText(text, info) {
128
+ return typeof info.navigation === 'object'
129
+ ? info.navigation.resolveRenameEditText?.(text) ?? text
130
+ : text;
131
+ }
132
+ function findOverlapCodeRange(start, end, map, filter) {
133
+ let mappedStart;
134
+ let mappedEnd;
135
+ for (const [mapped, mapping] of map.toGeneratedLocation(start)) {
136
+ if (filter(mapping.data)) {
137
+ mappedStart = mapped;
138
+ break;
139
+ }
140
+ }
141
+ for (const [mapped, mapping] of map.toGeneratedLocation(end)) {
142
+ if (filter(mapping.data)) {
143
+ mappedEnd = mapped;
144
+ break;
145
+ }
146
+ }
147
+ if (mappedStart === undefined || mappedEnd === undefined) {
148
+ for (const mapping of map.mappings) {
149
+ if (filter(mapping.data)) {
150
+ const mappingStart = mapping.sourceOffsets[0];
151
+ const mappingEnd = mapping.sourceOffsets[mapping.sourceOffsets.length - 1] + mapping.lengths[mapping.lengths.length - 1];
152
+ const overlap = getOverlapRange(start, end, mappingStart, mappingEnd);
153
+ if (overlap) {
154
+ const curMappedStart = (overlap.start - mappingStart) + mapping.generatedOffsets[0];
155
+ const lastGeneratedLength = (mapping.generatedLengths ?? mapping.lengths)[mapping.generatedOffsets.length - 1];
156
+ const curMappedEndOffset = Math.min(overlap.end - mapping.sourceOffsets[mapping.sourceOffsets.length - 1], lastGeneratedLength);
157
+ const curMappedEnd = mapping.generatedOffsets[mapping.generatedOffsets.length - 1] + curMappedEndOffset;
158
+ mappedStart = mappedStart === undefined ? curMappedStart : Math.min(mappedStart, curMappedStart);
159
+ mappedEnd = mappedEnd === undefined ? curMappedEnd : Math.max(mappedEnd, curMappedEnd);
160
+ }
161
+ }
162
+ }
163
+ }
164
+ if (mappedStart !== undefined && mappedEnd !== undefined) {
165
+ return {
166
+ start: mappedStart,
167
+ end: mappedEnd,
168
+ };
169
+ }
170
+ }
171
+ function getOverlapRange(range1Start, range1End, range2Start, range2End) {
172
+ const start = Math.max(range1Start, range2Start);
173
+ const end = Math.min(range1End, range2End);
174
+ if (start > end) {
175
+ return undefined;
176
+ }
177
+ return {
178
+ start,
179
+ end,
180
+ };
181
+ }
182
+ //# sourceMappingURL=editor.js.map
@@ -26,5 +26,3 @@ export declare function isCompletionEnabled(info: CodeInformation): boolean;
26
26
  export declare function isAutoInsertEnabled(info: CodeInformation): boolean;
27
27
  export declare function isSignatureHelpEnabled(info: CodeInformation): boolean;
28
28
  export declare function shouldReportDiagnostics(info: CodeInformation, source: string | undefined, code: string | number | undefined): boolean;
29
- export declare function resolveRenameNewName(newName: string, info: CodeInformation): string;
30
- export declare function resolveRenameEditText(text: string, info: CodeInformation): string;
@@ -27,8 +27,6 @@ exports.isCompletionEnabled = isCompletionEnabled;
27
27
  exports.isAutoInsertEnabled = isAutoInsertEnabled;
28
28
  exports.isSignatureHelpEnabled = isSignatureHelpEnabled;
29
29
  exports.shouldReportDiagnostics = shouldReportDiagnostics;
30
- exports.resolveRenameNewName = resolveRenameNewName;
31
- exports.resolveRenameEditText = resolveRenameEditText;
32
30
  function isHoverEnabled(info) {
33
31
  return !!info.semantic;
34
32
  }
@@ -117,15 +115,4 @@ function shouldReportDiagnostics(info, source, code) {
117
115
  ? info.verification.shouldReport?.(source, code) ?? true
118
116
  : !!info.verification;
119
117
  }
120
- // resolve...
121
- function resolveRenameNewName(newName, info) {
122
- return typeof info.navigation === 'object'
123
- ? info.navigation.resolveRenameNewName?.(newName) ?? newName
124
- : newName;
125
- }
126
- function resolveRenameEditText(text, info) {
127
- return typeof info.navigation === 'object'
128
- ? info.navigation.resolveRenameEditText?.(text) ?? text
129
- : text;
130
- }
131
118
  //# sourceMappingURL=editorFeatures.js.map
package/lib/types.d.ts CHANGED
@@ -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.11",
3
+ "version": "2.4.13",
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.11"
15
+ "@volar/source-map": "2.4.13"
16
16
  },
17
- "gitHead": "42ccae005cc8516e07ad38f4d7730cab9b723340"
17
+ "gitHead": "c5d727b9e73d0c6a45c64b38d74ca5c52363818f"
18
18
  }