@volar/language-core 2.3.0-alpha.9 → 2.3.1

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,8 +1,9 @@
1
- export * from '@volar/source-map';
1
+ export { Mapping } from '@volar/source-map';
2
2
  export * from './lib/editorFeatures';
3
3
  export * from './lib/linkedCodeMap';
4
4
  export * from './lib/types';
5
5
  export * from './lib/utils';
6
- import type { Language, LanguagePlugin, SourceScript, VirtualCode } from './lib/types';
6
+ import type { Language, LanguagePlugin, MapperFactory, SourceScript, VirtualCode } from './lib/types';
7
+ export declare const defaultMapperFactory: MapperFactory;
7
8
  export declare function createLanguage<T>(plugins: LanguagePlugin<T>[], scriptRegistry: Map<T, SourceScript<T>>, sync: (id: T) => void): Language<T>;
8
9
  export declare function forEachEmbeddedCode(virtualCode: VirtualCode): Generator<VirtualCode>;
package/index.js CHANGED
@@ -14,19 +14,23 @@ 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.forEachEmbeddedCode = exports.createLanguage = void 0;
18
- __exportStar(require("@volar/source-map"), exports);
17
+ exports.defaultMapperFactory = void 0;
18
+ exports.createLanguage = createLanguage;
19
+ exports.forEachEmbeddedCode = forEachEmbeddedCode;
19
20
  __exportStar(require("./lib/editorFeatures"), exports);
20
21
  __exportStar(require("./lib/linkedCodeMap"), exports);
21
22
  __exportStar(require("./lib/types"), exports);
22
23
  __exportStar(require("./lib/utils"), exports);
23
24
  const source_map_1 = require("@volar/source-map");
24
25
  const linkedCodeMap_1 = require("./lib/linkedCodeMap");
26
+ const defaultMapperFactory = mappings => new source_map_1.SourceMap(mappings);
27
+ exports.defaultMapperFactory = defaultMapperFactory;
25
28
  function createLanguage(plugins, scriptRegistry, sync) {
26
29
  const virtualCodeToSourceScriptMap = new WeakMap();
27
30
  const virtualCodeToSourceMap = new WeakMap();
28
31
  const virtualCodeToLinkedCodeMap = new WeakMap();
29
- return {
32
+ const language = {
33
+ mapperFactory: exports.defaultMapperFactory,
30
34
  plugins,
31
35
  scripts: {
32
36
  fromVirtualCode(virtualCode) {
@@ -142,31 +146,30 @@ function createLanguage(plugins, scriptRegistry, sync) {
142
146
  },
143
147
  },
144
148
  maps: {
145
- get(virtualCode, sourceScript, mappings) {
149
+ get(virtualCode, sourceScript) {
146
150
  let mapCache = virtualCodeToSourceMap.get(virtualCode.snapshot);
147
151
  if (!mapCache) {
148
152
  virtualCodeToSourceMap.set(virtualCode.snapshot, mapCache = new WeakMap());
149
153
  }
150
154
  if (!mapCache.has(sourceScript.snapshot)) {
151
- mapCache.set(sourceScript.snapshot, new source_map_1.SourceMap(mappings ?? virtualCode.mappings));
155
+ const mappings = virtualCode.associatedScriptMappings?.get(sourceScript.id) ?? virtualCode.mappings;
156
+ mapCache.set(sourceScript.snapshot, language.mapperFactory(mappings));
152
157
  }
153
158
  return mapCache.get(sourceScript.snapshot);
154
159
  },
155
160
  *forEach(virtualCode) {
156
161
  const sourceScript = virtualCodeToSourceScriptMap.get(virtualCode);
157
162
  yield [
158
- sourceScript.id,
159
- sourceScript.snapshot,
163
+ sourceScript,
160
164
  this.get(virtualCode, sourceScript),
161
165
  ];
162
166
  if (virtualCode.associatedScriptMappings) {
163
- for (const [relatedScriptId, relatedMappings] of virtualCode.associatedScriptMappings) {
167
+ for (const [relatedScriptId] of virtualCode.associatedScriptMappings) {
164
168
  const relatedSourceScript = scriptRegistry.get(relatedScriptId);
165
169
  if (relatedSourceScript) {
166
170
  yield [
167
- relatedSourceScript.id,
168
- relatedSourceScript.snapshot,
169
- this.get(virtualCode, relatedSourceScript, relatedMappings),
171
+ relatedSourceScript,
172
+ this.get(virtualCode, relatedSourceScript),
170
173
  ];
171
174
  }
172
175
  }
@@ -189,6 +192,7 @@ function createLanguage(plugins, scriptRegistry, sync) {
189
192
  },
190
193
  },
191
194
  };
195
+ return language;
192
196
  function triggerTargetsDirty(sourceScript) {
193
197
  sourceScript.targetIds.forEach(id => {
194
198
  const sourceScript = scriptRegistry.get(id);
@@ -216,7 +220,6 @@ function createLanguage(plugins, scriptRegistry, sync) {
216
220
  };
217
221
  }
218
222
  }
219
- exports.createLanguage = createLanguage;
220
223
  function* forEachEmbeddedCode(virtualCode) {
221
224
  yield virtualCode;
222
225
  if (virtualCode.embeddedCodes) {
@@ -225,5 +228,4 @@ function* forEachEmbeddedCode(virtualCode) {
225
228
  }
226
229
  }
227
230
  }
228
- exports.forEachEmbeddedCode = forEachEmbeddedCode;
229
231
  //# sourceMappingURL=index.js.map
@@ -1,120 +1,119 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveRenameEditText = exports.resolveRenameNewName = exports.shouldReportDiagnostics = exports.isSignatureHelpEnabled = exports.isAutoInsertEnabled = exports.isCompletionEnabled = exports.isFormattingEnabled = exports.isCodeActionsEnabled = exports.isDiagnosticsEnabled = exports.isDocumentLinkEnabled = exports.isColorEnabled = exports.isLinkedEditingEnabled = exports.isSelectionRangesEnabled = exports.isFoldingRangesEnabled = exports.isSymbolsEnabled = exports.isHighlightEnabled = exports.isImplementationEnabled = exports.isReferencesEnabled = exports.isTypeDefinitionEnabled = exports.isDefinitionEnabled = exports.isRenameEnabled = exports.isCallHierarchyEnabled = exports.isSemanticTokensEnabled = exports.isCodeLensEnabled = exports.isInlayHintsEnabled = exports.isHoverEnabled = void 0;
3
+ exports.isHoverEnabled = isHoverEnabled;
4
+ exports.isInlayHintsEnabled = isInlayHintsEnabled;
5
+ exports.isCodeLensEnabled = isCodeLensEnabled;
6
+ exports.isSemanticTokensEnabled = isSemanticTokensEnabled;
7
+ exports.isCallHierarchyEnabled = isCallHierarchyEnabled;
8
+ exports.isRenameEnabled = isRenameEnabled;
9
+ exports.isDefinitionEnabled = isDefinitionEnabled;
10
+ exports.isTypeDefinitionEnabled = isTypeDefinitionEnabled;
11
+ exports.isReferencesEnabled = isReferencesEnabled;
12
+ exports.isImplementationEnabled = isImplementationEnabled;
13
+ exports.isHighlightEnabled = isHighlightEnabled;
14
+ exports.isSymbolsEnabled = isSymbolsEnabled;
15
+ exports.isFoldingRangesEnabled = isFoldingRangesEnabled;
16
+ exports.isSelectionRangesEnabled = isSelectionRangesEnabled;
17
+ exports.isLinkedEditingEnabled = isLinkedEditingEnabled;
18
+ exports.isColorEnabled = isColorEnabled;
19
+ exports.isDocumentLinkEnabled = isDocumentLinkEnabled;
20
+ exports.isDiagnosticsEnabled = isDiagnosticsEnabled;
21
+ exports.isCodeActionsEnabled = isCodeActionsEnabled;
22
+ exports.isFormattingEnabled = isFormattingEnabled;
23
+ exports.isCompletionEnabled = isCompletionEnabled;
24
+ exports.isAutoInsertEnabled = isAutoInsertEnabled;
25
+ exports.isSignatureHelpEnabled = isSignatureHelpEnabled;
26
+ exports.shouldReportDiagnostics = shouldReportDiagnostics;
27
+ exports.resolveRenameNewName = resolveRenameNewName;
28
+ exports.resolveRenameEditText = resolveRenameEditText;
4
29
  function isHoverEnabled(info) {
5
30
  return !!info.semantic;
6
31
  }
7
- exports.isHoverEnabled = isHoverEnabled;
8
32
  function isInlayHintsEnabled(info) {
9
33
  return !!info.semantic;
10
34
  }
11
- exports.isInlayHintsEnabled = isInlayHintsEnabled;
12
35
  function isCodeLensEnabled(info) {
13
36
  return !!info.semantic;
14
37
  }
15
- exports.isCodeLensEnabled = isCodeLensEnabled;
16
38
  function isSemanticTokensEnabled(info) {
17
39
  return typeof info.semantic === 'object'
18
40
  ? info.semantic.shouldHighlight?.() ?? true
19
41
  : !!info.semantic;
20
42
  }
21
- exports.isSemanticTokensEnabled = isSemanticTokensEnabled;
22
43
  function isCallHierarchyEnabled(info) {
23
44
  return !!info.navigation;
24
45
  }
25
- exports.isCallHierarchyEnabled = isCallHierarchyEnabled;
26
46
  function isRenameEnabled(info) {
27
47
  return typeof info.navigation === 'object'
28
48
  ? info.navigation.shouldRename?.() ?? true
29
49
  : !!info.navigation;
30
50
  }
31
- exports.isRenameEnabled = isRenameEnabled;
32
51
  function isDefinitionEnabled(info) {
33
52
  return !!info.navigation;
34
53
  }
35
- exports.isDefinitionEnabled = isDefinitionEnabled;
36
54
  function isTypeDefinitionEnabled(info) {
37
55
  return !!info.navigation;
38
56
  }
39
- exports.isTypeDefinitionEnabled = isTypeDefinitionEnabled;
40
57
  function isReferencesEnabled(info) {
41
58
  return !!info.navigation;
42
59
  }
43
- exports.isReferencesEnabled = isReferencesEnabled;
44
60
  function isImplementationEnabled(info) {
45
61
  return !!info.navigation;
46
62
  }
47
- exports.isImplementationEnabled = isImplementationEnabled;
48
63
  function isHighlightEnabled(info) {
49
64
  return !!info.navigation;
50
65
  }
51
- exports.isHighlightEnabled = isHighlightEnabled;
52
66
  function isSymbolsEnabled(info) {
53
67
  return !!info.structure;
54
68
  }
55
- exports.isSymbolsEnabled = isSymbolsEnabled;
56
69
  function isFoldingRangesEnabled(info) {
57
70
  return !!info.structure;
58
71
  }
59
- exports.isFoldingRangesEnabled = isFoldingRangesEnabled;
60
72
  function isSelectionRangesEnabled(info) {
61
73
  return !!info.structure;
62
74
  }
63
- exports.isSelectionRangesEnabled = isSelectionRangesEnabled;
64
75
  function isLinkedEditingEnabled(info) {
65
76
  return !!info.structure;
66
77
  }
67
- exports.isLinkedEditingEnabled = isLinkedEditingEnabled;
68
78
  function isColorEnabled(info) {
69
79
  return !!info.structure;
70
80
  }
71
- exports.isColorEnabled = isColorEnabled;
72
81
  function isDocumentLinkEnabled(info) {
73
82
  return !!info.structure;
74
83
  }
75
- exports.isDocumentLinkEnabled = isDocumentLinkEnabled;
76
84
  function isDiagnosticsEnabled(info) {
77
85
  return !!info.verification;
78
86
  }
79
- exports.isDiagnosticsEnabled = isDiagnosticsEnabled;
80
87
  function isCodeActionsEnabled(info) {
81
88
  return !!info.verification;
82
89
  }
83
- exports.isCodeActionsEnabled = isCodeActionsEnabled;
84
90
  function isFormattingEnabled(info) {
85
91
  return !!info.format;
86
92
  }
87
- exports.isFormattingEnabled = isFormattingEnabled;
88
93
  function isCompletionEnabled(info) {
89
94
  return !!info.completion;
90
95
  }
91
- exports.isCompletionEnabled = isCompletionEnabled;
92
96
  function isAutoInsertEnabled(info) {
93
97
  return !!info.completion;
94
98
  }
95
- exports.isAutoInsertEnabled = isAutoInsertEnabled;
96
99
  function isSignatureHelpEnabled(info) {
97
100
  return !!info.completion;
98
101
  }
99
- exports.isSignatureHelpEnabled = isSignatureHelpEnabled;
100
102
  // should...
101
103
  function shouldReportDiagnostics(info) {
102
104
  return typeof info.verification === 'object'
103
105
  ? info.verification.shouldReport?.() ?? true
104
106
  : !!info.verification;
105
107
  }
106
- exports.shouldReportDiagnostics = shouldReportDiagnostics;
107
108
  // resolve...
108
109
  function resolveRenameNewName(newName, info) {
109
110
  return typeof info.navigation === 'object'
110
111
  ? info.navigation.resolveRenameNewName?.(newName) ?? newName
111
112
  : newName;
112
113
  }
113
- exports.resolveRenameNewName = resolveRenameNewName;
114
114
  function resolveRenameEditText(text, info) {
115
115
  return typeof info.navigation === 'object'
116
116
  ? info.navigation.resolveRenameEditText?.(text) ?? text
117
117
  : text;
118
118
  }
119
- exports.resolveRenameEditText = resolveRenameEditText;
120
119
  //# sourceMappingURL=editorFeatures.js.map
@@ -4,10 +4,10 @@ exports.LinkedCodeMap = void 0;
4
4
  const source_map_1 = require("@volar/source-map");
5
5
  class LinkedCodeMap extends source_map_1.SourceMap {
6
6
  *getLinkedOffsets(start) {
7
- for (const mapped of this.getGeneratedOffsets(start)) {
7
+ for (const mapped of this.toGeneratedLocation(start)) {
8
8
  yield mapped[0];
9
9
  }
10
- for (const mapped of this.getSourceOffsets(start)) {
10
+ for (const mapped of this.toSourceLocation(start)) {
11
11
  yield mapped[0];
12
12
  }
13
13
  }
package/lib/types.d.ts CHANGED
@@ -1,7 +1,16 @@
1
- import type { Mapping, SourceMap } from '@volar/source-map';
1
+ import type { Mapping } from '@volar/source-map';
2
2
  import type * as ts from 'typescript';
3
3
  import type { LinkedCodeMap } from './linkedCodeMap';
4
+ export interface Mapper {
5
+ mappings: Mapping<CodeInformation>[];
6
+ toSourceRange(start: number, end: number, fallbackToAnyMatch: boolean, filter?: (data: CodeInformation) => boolean): Generator<readonly [number, number, Mapping<CodeInformation>, Mapping<CodeInformation>]>;
7
+ toGeneratedRange(start: number, end: number, fallbackToAnyMatch: boolean, filter?: (data: CodeInformation) => boolean): Generator<readonly [number, number, Mapping<CodeInformation>, Mapping<CodeInformation>]>;
8
+ toSourceLocation(generatedOffset: number, filter?: (data: CodeInformation) => boolean): Generator<readonly [number, Mapping<CodeInformation>]>;
9
+ toGeneratedLocation(sourceOffset: number, filter?: (data: CodeInformation) => boolean): Generator<readonly [number, Mapping<CodeInformation>]>;
10
+ }
11
+ export type MapperFactory = (mappings: Mapping<CodeInformation>[]) => Mapper;
4
12
  export interface Language<T = unknown> {
13
+ mapperFactory: MapperFactory;
5
14
  plugins: LanguagePlugin<T>[];
6
15
  scripts: {
7
16
  get(id: T): SourceScript<T> | undefined;
@@ -10,8 +19,8 @@ export interface Language<T = unknown> {
10
19
  fromVirtualCode(virtualCode: VirtualCode): SourceScript<T>;
11
20
  };
12
21
  maps: {
13
- get(virtualCode: VirtualCode, sourceScript: SourceScript<T>, mappings?: Mapping<CodeInformation>[]): SourceMap<CodeInformation>;
14
- forEach(virtualCode: VirtualCode): Generator<[id: T, snapshot: ts.IScriptSnapshot, map: SourceMap<CodeInformation>]>;
22
+ get(virtualCode: VirtualCode, sourceScript: SourceScript<T>): Mapper;
23
+ forEach(virtualCode: VirtualCode): Generator<[sourceScript: SourceScript<T>, map: Mapper]>;
15
24
  };
16
25
  linkedCodeMaps: {
17
26
  get(virtualCode: VirtualCode): LinkedCodeMap | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-core",
3
- "version": "2.3.0-alpha.9",
3
+ "version": "2.3.1",
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.0-alpha.9"
15
+ "@volar/source-map": "2.3.1"
16
16
  },
17
- "gitHead": "3f741930343896dfc464a893ebe5f3619bb1a1aa"
17
+ "gitHead": "51742317a2950abd97e1a1a266b2c137bede4ad3"
18
18
  }