@volar/language-service 1.0.0-beta.1 → 1.0.0-beta.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.
Files changed (41) hide show
  1. package/out/baseDocumentService.js +1 -1
  2. package/out/baseLanguageService.d.ts +1 -1
  3. package/out/baseLanguageService.js +2 -2
  4. package/out/documentFeatures/autoInsert.js +2 -9
  5. package/out/documentFeatures/colorPresentations.js +7 -14
  6. package/out/documentFeatures/documentColors.js +1 -4
  7. package/out/documentFeatures/documentSymbols.js +3 -6
  8. package/out/documentFeatures/foldingRanges.js +1 -6
  9. package/out/documentFeatures/format.js +23 -30
  10. package/out/documentFeatures/linkedEditingRanges.js +2 -11
  11. package/out/documentFeatures/selectionRanges.js +3 -8
  12. package/out/documents.d.ts +23 -49
  13. package/out/documents.js +105 -73
  14. package/out/languageFeatures/autoInsert.js +20 -21
  15. package/out/languageFeatures/callHierarchy.js +17 -13
  16. package/out/languageFeatures/codeActions.js +10 -9
  17. package/out/languageFeatures/codeLens.js +1 -2
  18. package/out/languageFeatures/complete.js +11 -7
  19. package/out/languageFeatures/completeResolve.d.ts +1 -1
  20. package/out/languageFeatures/completeResolve.js +8 -8
  21. package/out/languageFeatures/definition.js +17 -20
  22. package/out/languageFeatures/documentHighlights.js +7 -10
  23. package/out/languageFeatures/documentLinks.js +4 -5
  24. package/out/languageFeatures/documentSemanticTokens.js +21 -23
  25. package/out/languageFeatures/executeCommand.d.ts +1 -1
  26. package/out/languageFeatures/executeCommand.js +1 -1
  27. package/out/languageFeatures/fileReferences.js +13 -11
  28. package/out/languageFeatures/fileRename.js +1 -1
  29. package/out/languageFeatures/hover.js +6 -13
  30. package/out/languageFeatures/inlayHints.js +12 -11
  31. package/out/languageFeatures/references.js +14 -13
  32. package/out/languageFeatures/rename.d.ts +0 -13
  33. package/out/languageFeatures/rename.js +49 -37
  34. package/out/languageFeatures/renamePrepare.js +6 -8
  35. package/out/languageFeatures/signatureHelp.js +1 -5
  36. package/out/languageFeatures/validation.js +31 -33
  37. package/out/languageFeatures/workspaceSymbols.js +9 -2
  38. package/out/plugin.d.ts +1 -1
  39. package/out/utils/featureWorkers.d.ts +2 -2
  40. package/out/utils/featureWorkers.js +1 -4
  41. package/package.json +7 -7
package/out/documents.js CHANGED
@@ -5,53 +5,114 @@ const shared = require("@volar/shared");
5
5
  const source_map_1 = require("@volar/source-map");
6
6
  const reactivity_1 = require("@vue/reactivity");
7
7
  const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
8
- class SourceMap {
9
- constructor(sourceDocument, mappedDocument, base = new source_map_1.SourceMapBase()) {
8
+ class SourceMap extends source_map_1.SourceMapBase {
9
+ constructor(sourceDocument, mappedDocument, mappings) {
10
+ super(mappings);
10
11
  this.sourceDocument = sourceDocument;
11
12
  this.mappedDocument = mappedDocument;
12
- this.base = base;
13
+ this.mappings = mappings;
13
14
  }
14
- getSourceRange(start, end, filter) {
15
- for (const mapped of this.getRanges(start, end !== null && end !== void 0 ? end : start, false, filter)) {
15
+ // Range APIs
16
+ toSourceRange(range, filter = () => true) {
17
+ for (const result of this.toSourceRanges(range, filter)) {
18
+ return result;
19
+ }
20
+ }
21
+ toGeneratedRange(range, filter = () => true) {
22
+ for (const result of this.toGeneratedRanges(range, filter)) {
23
+ return result;
24
+ }
25
+ }
26
+ *toSourceRanges(range, filter = () => true) {
27
+ for (const result of this.toRanges(range, filter, 'toSourcePositionsBase', 'matchSourcePosition')) {
28
+ yield result;
29
+ }
30
+ }
31
+ *toGeneratedRanges(range, filter = () => true) {
32
+ for (const result of this.toRanges(range, filter, 'toGeneratedPositionsBase', 'matchGeneratedPosition')) {
33
+ yield result;
34
+ }
35
+ }
36
+ *toRanges(range, filter, api, api2) {
37
+ const failedLookUps = [];
38
+ for (const mapped of this[api](range.start, filter, 'left')) {
39
+ const end = this[api2](range.end, mapped[1], 'right');
40
+ if (end) {
41
+ yield { start: mapped[0], end };
42
+ }
43
+ else {
44
+ failedLookUps.push(mapped);
45
+ }
46
+ }
47
+ for (const failedLookUp of failedLookUps) {
48
+ for (const mapped of this[api](range.end, filter, 'right')) {
49
+ yield { start: failedLookUp[0], end: mapped[0] };
50
+ }
51
+ }
52
+ }
53
+ // Position APIs
54
+ toSourcePosition(position, filter = () => true, baseOffset = 'left') {
55
+ for (const mapped of this.toSourcePositions(position, filter, baseOffset)) {
16
56
  return mapped;
17
57
  }
18
58
  }
19
- getMappedRange(start, end, filter) {
20
- for (const mapped of this.getRanges(start, end !== null && end !== void 0 ? end : start, true, filter)) {
59
+ toGeneratedPosition(position, filter = () => true, baseOffset = 'left') {
60
+ for (const mapped of this.toGeneratedPositions(position, filter, baseOffset)) {
21
61
  return mapped;
22
62
  }
23
63
  }
24
- getSourceRanges(start, end, filter) {
25
- return this.getRanges(start, end !== null && end !== void 0 ? end : start, false, filter);
64
+ *toSourcePositions(position, filter = () => true, baseOffset = 'left') {
65
+ for (const mapped of this.toSourcePositionsBase(position, filter, baseOffset)) {
66
+ yield mapped[0];
67
+ }
26
68
  }
27
- getMappedRanges(start, end, filter) {
28
- return this.getRanges(start, end !== null && end !== void 0 ? end : start, true, filter);
69
+ *toGeneratedPositions(position, filter = () => true, baseOffset = 'left') {
70
+ for (const mapped of this.toGeneratedPositionsBase(position, filter, baseOffset)) {
71
+ yield mapped[0];
72
+ }
73
+ }
74
+ toSourcePositionsBase(position, filter = () => true, baseOffset = 'left') {
75
+ return this.toPositions(position, filter, this.mappedDocument, this.sourceDocument, 'generatedRange', 'sourceRange', baseOffset);
29
76
  }
30
- *getRanges(start, end, sourceToTarget, filter) {
31
- const startIsNumber = typeof start === 'number';
32
- const endIsNumber = typeof end === 'number';
33
- const toDoc = sourceToTarget ? this.mappedDocument : this.sourceDocument;
34
- const fromDoc = sourceToTarget ? this.sourceDocument : this.mappedDocument;
35
- const startOffset = startIsNumber ? start : fromDoc.offsetAt(start);
36
- const endOffset = endIsNumber ? end : fromDoc.offsetAt(end);
37
- for (const mapped of this.base.getRanges(startOffset, endOffset, sourceToTarget, filter)) {
38
- yield getMapped(mapped);
77
+ toGeneratedPositionsBase(position, filter = () => true, baseOffset = 'left') {
78
+ return this.toPositions(position, filter, this.sourceDocument, this.mappedDocument, 'sourceRange', 'generatedRange', baseOffset);
79
+ }
80
+ *toPositions(position, filter, fromDoc, toDoc, from, to, baseOffset) {
81
+ for (const mapped of this.matcing(fromDoc.offsetAt(position), from, to)) {
82
+ if (!filter(mapped[1].data)) {
83
+ continue;
84
+ }
85
+ let offset = mapped[0];
86
+ const mapping = mapped[1];
87
+ if (baseOffset === 'right') {
88
+ offset += (mapping.sourceRange[1] - mapping.sourceRange[0]) - (mapping.generatedRange[1] - mapping.generatedRange[0]);
89
+ }
90
+ yield [toDoc.positionAt(offset), mapping];
39
91
  }
40
- function getMapped(mapped) {
41
- if (startIsNumber) {
42
- return mapped;
92
+ }
93
+ matchSourcePosition(position, mapping, baseOffset) {
94
+ let offset = this.matchOffset(this.mappedDocument.offsetAt(position), mapping['generatedRange'], mapping['sourceRange']);
95
+ if (offset !== undefined) {
96
+ if (baseOffset === 'right') {
97
+ offset += (mapping.sourceRange[1] - mapping.sourceRange[0]) - (mapping.generatedRange[1] - mapping.generatedRange[0]);
43
98
  }
44
- return [{
45
- start: toDoc.positionAt(mapped[0].start),
46
- end: toDoc.positionAt(mapped[0].end),
47
- }, mapped[1]];
99
+ return this.sourceDocument.positionAt(offset);
100
+ }
101
+ }
102
+ matchGeneratedPosition(position, mapping, baseOffset) {
103
+ let offset = this.matchOffset(this.sourceDocument.offsetAt(position), mapping['sourceRange'], mapping['generatedRange']);
104
+ if (offset !== undefined) {
105
+ if (baseOffset === 'right') {
106
+ offset += (mapping.generatedRange[1] - mapping.generatedRange[0]) - (mapping.sourceRange[1] - mapping.sourceRange[0]);
107
+ }
108
+ return this.mappedDocument.positionAt(offset);
48
109
  }
49
110
  }
50
111
  }
51
112
  exports.SourceMap = SourceMap;
52
113
  class EmbeddedDocumentSourceMap extends SourceMap {
53
- constructor(embeddedFile, sourceDocument, mappedDocument, _sourceMap) {
54
- super(sourceDocument, mappedDocument, _sourceMap);
114
+ constructor(embeddedFile, sourceDocument, mappedDocument, mappings) {
115
+ super(sourceDocument, mappedDocument, mappings);
55
116
  this.embeddedFile = embeddedFile;
56
117
  this.sourceDocument = sourceDocument;
57
118
  this.mappedDocument = mappedDocument;
@@ -59,17 +120,17 @@ class EmbeddedDocumentSourceMap extends SourceMap {
59
120
  }
60
121
  exports.EmbeddedDocumentSourceMap = EmbeddedDocumentSourceMap;
61
122
  class TeleportSourceMap extends SourceMap {
62
- constructor(embeddedFile, document, teleport) {
63
- super(document, document, teleport);
123
+ constructor(embeddedFile, document, mappings) {
124
+ super(document, document, mappings);
64
125
  this.embeddedFile = embeddedFile;
65
126
  this.document = document;
66
127
  }
67
- *findTeleports(start, end, filter) {
68
- for (const [teleRange, data] of this.getMappedRanges(start, end, filter ? data => filter(data.toGenedCapabilities) : undefined)) {
69
- yield [teleRange, data.toGenedCapabilities];
128
+ *findTeleports(start) {
129
+ for (const mapped of this.toGeneratedPositionsBase(start)) {
130
+ yield [mapped[0], mapped[1].data.toGenedCapabilities];
70
131
  }
71
- for (const [teleRange, data] of this.getSourceRanges(start, end, filter ? data => filter(data.toSourceCapabilities) : undefined)) {
72
- yield [teleRange, data.toSourceCapabilities];
132
+ for (const mapped of this.toSourcePositionsBase(start)) {
133
+ yield [mapped[0], mapped[1].data.toSourceCapabilities];
73
134
  }
74
135
  }
75
136
  }
@@ -86,7 +147,7 @@ function parseSourceFileDocuments(rootUri, mapper) {
86
147
  }
87
148
  return map;
88
149
  });
89
- const embeddedDocumentsMapLsType = (0, reactivity_1.computed)(() => {
150
+ const embeddedDocumentMaps = (0, reactivity_1.computed)(() => {
90
151
  const map = new Map();
91
152
  for (const vueDocument of getAll()) {
92
153
  for (const sourceMap of vueDocument.getSourceMaps()) {
@@ -95,7 +156,7 @@ function parseSourceFileDocuments(rootUri, mapper) {
95
156
  }
96
157
  return map;
97
158
  });
98
- const teleportsMapLsType = (0, reactivity_1.computed)(() => {
159
+ const teleports = (0, reactivity_1.computed)(() => {
99
160
  const map = new Map();
100
161
  for (const vueDocument of getAll()) {
101
162
  for (const teleport of vueDocument.getTeleports()) {
@@ -117,45 +178,16 @@ function parseSourceFileDocuments(rootUri, mapper) {
117
178
  return embeddedDocumentsMap.value.get(document);
118
179
  },
119
180
  sourceMapFromEmbeddedDocumentUri: (uri) => {
120
- return embeddedDocumentsMapLsType.value.get(uri);
181
+ return embeddedDocumentMaps.value.get(uri);
121
182
  },
122
183
  teleportfromEmbeddedDocumentUri: (uri) => {
123
- return teleportsMapLsType.value.get(uri);
124
- },
125
- fromEmbeddedLocation: function* (uri, start, end, filter, sourceMapFilter) {
126
- if (uri.endsWith('/__VLS_types.ts')) { // TODO: monkey fix
127
- return;
128
- }
129
- if (end === undefined)
130
- end = start;
131
- const sourceMap = embeddedDocumentsMapLsType.value.get(uri);
132
- if (sourceMap) {
133
- if (sourceMapFilter && !sourceMapFilter(sourceMap.base))
134
- return;
135
- for (const vueRange of sourceMap.getSourceRanges(start, end, filter)) {
136
- yield {
137
- uri: sourceMap.sourceDocument.uri,
138
- range: vueRange[0],
139
- sourceMap,
140
- data: vueRange[1],
141
- };
142
- }
143
- }
144
- else {
145
- yield {
146
- uri,
147
- range: {
148
- start,
149
- end,
150
- },
151
- };
152
- }
184
+ return teleports.value.get(uri);
153
185
  },
154
186
  };
155
187
  function get(sourceFile) {
156
188
  let vueDocument = _sourceFiles.get(sourceFile);
157
189
  if (!vueDocument) {
158
- vueDocument = parseSourceFileDocument(rootUri, sourceFile, mapper);
190
+ vueDocument = parseSourceFileDocument(rootUri, sourceFile);
159
191
  _sourceFiles.set(sourceFile, vueDocument);
160
192
  }
161
193
  return vueDocument;
@@ -165,7 +197,7 @@ function parseSourceFileDocuments(rootUri, mapper) {
165
197
  }
166
198
  }
167
199
  exports.parseSourceFileDocuments = parseSourceFileDocuments;
168
- function parseSourceFileDocument(rootUri, sourceFile, mapper) {
200
+ function parseSourceFileDocument(rootUri, sourceFile) {
169
201
  let documentVersion = 0;
170
202
  const embeddedDocumentVersions = new Map();
171
203
  const embeddedDocuments = new WeakMap();
@@ -184,7 +216,7 @@ function parseSourceFileDocument(rootUri, sourceFile, mapper) {
184
216
  (0, language_core_1.forEachEmbeddeds)(sourceFile.embeddeds, embedded => {
185
217
  if (embedded.teleportMappings) {
186
218
  const embeddedDocument = getEmbeddedDocument(embedded);
187
- const sourceMap = new TeleportSourceMap(embedded, embeddedDocument, mapper.getTeleportSourceMap(sourceFile, embedded.teleportMappings));
219
+ const sourceMap = new TeleportSourceMap(embedded, embeddedDocument, embedded.teleportMappings);
188
220
  result.push(sourceMap);
189
221
  }
190
222
  });
@@ -204,7 +236,7 @@ function parseSourceFileDocument(rootUri, sourceFile, mapper) {
204
236
  if (!cache || cache[0] !== document.value.version) {
205
237
  cache = [
206
238
  document.value.version,
207
- new EmbeddedDocumentSourceMap(embedded, document.value, getEmbeddedDocument(embedded), mapper.getSourceMap(sourceFile, embedded.mappings))
239
+ new EmbeddedDocumentSourceMap(embedded, document.value, getEmbeddedDocument(embedded), embedded.mappings)
208
240
  ];
209
241
  sourceMaps.set(embedded, cache);
210
242
  }
@@ -4,29 +4,28 @@ const featureWorkers_1 = require("../utils/featureWorkers");
4
4
  function register(context) {
5
5
  return (uri, position, autoInsertContext) => {
6
6
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, autoInsertContext }, function* (arg, sourceMap) {
7
- var _a, _b, _c;
8
- const position = (_a = sourceMap.getMappedRange(arg.position, arg.position, data => !!data.completion)) === null || _a === void 0 ? void 0 : _a[0].start;
9
- const rangeOffset = (_b = sourceMap.getMappedRange(arg.autoInsertContext.lastChange.rangeOffset, arg.autoInsertContext.lastChange.rangeOffset, data => !!data.completion)) === null || _b === void 0 ? void 0 : _b[0].start;
10
- const range = (_c = sourceMap.getMappedRange(arg.autoInsertContext.lastChange.range.start, arg.autoInsertContext.lastChange.range.end, data => !!data.completion)) === null || _c === void 0 ? void 0 : _c[0];
11
- if (position && rangeOffset !== undefined && range) {
12
- yield {
13
- position,
14
- autoInsertContext: {
15
- lastChange: Object.assign(Object.assign({}, arg.autoInsertContext.lastChange), { rangeOffset,
16
- range }),
17
- },
18
- };
19
- }
20
- }, (plugin, document, arg) => { var _a; return (_a = plugin.doAutoInsert) === null || _a === void 0 ? void 0 : _a.call(plugin, document, arg.position, arg.autoInsertContext); }, (data, sourceMap) => {
21
7
  var _a;
22
- if (!sourceMap)
23
- return data;
24
- if (typeof data === 'string')
25
- return data;
26
- const range = (_a = sourceMap.getSourceRange(data.range.start, data.range.end)) === null || _a === void 0 ? void 0 : _a[0];
8
+ for (const position of sourceMap.toGeneratedPositions(arg.position, data => !!data.completion)) {
9
+ const rangeOffset = (_a = sourceMap.toGeneratedOffset(arg.autoInsertContext.lastChange.rangeOffset)) === null || _a === void 0 ? void 0 : _a[0];
10
+ const range = sourceMap.toGeneratedRange(arg.autoInsertContext.lastChange.range);
11
+ if (rangeOffset !== undefined && range) {
12
+ yield {
13
+ position,
14
+ autoInsertContext: {
15
+ lastChange: Object.assign(Object.assign({}, arg.autoInsertContext.lastChange), { rangeOffset,
16
+ range }),
17
+ },
18
+ };
19
+ break;
20
+ }
21
+ }
22
+ }, (plugin, document, arg) => { var _a; return (_a = plugin.doAutoInsert) === null || _a === void 0 ? void 0 : _a.call(plugin, document, arg.position, arg.autoInsertContext); }, (item, sourceMap) => {
23
+ if (!sourceMap || typeof item === 'string')
24
+ return item;
25
+ const range = sourceMap.toSourceRange(item.range);
27
26
  if (range) {
28
- data.range = range;
29
- return data;
27
+ item.range = range;
28
+ return item;
30
29
  }
31
30
  });
32
31
  };
@@ -16,11 +16,7 @@ const featureWorkers_1 = require("../utils/featureWorkers");
16
16
  function register(context) {
17
17
  return {
18
18
  doPrepare(uri, position) {
19
- return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, function* (position, sourceMap) {
20
- for (const [mappedRange] of sourceMap.getMappedRanges(position, position, data => !!data.references)) {
21
- yield mappedRange.start;
22
- }
23
- }, (plugin, document, position, sourceMap) => __awaiter(this, void 0, void 0, function* () {
19
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, sourceMap) => sourceMap.toGeneratedPositions(position, data => !!data.references), (plugin, document, position, sourceMap) => __awaiter(this, void 0, void 0, function* () {
24
20
  var _a;
25
21
  const items = yield ((_a = plugin.callHierarchy) === null || _a === void 0 ? void 0 : _a.prepare(document, position));
26
22
  return items === null || items === void 0 ? void 0 : items.map(item => {
@@ -123,23 +119,31 @@ function register(context) {
123
119
  },
124
120
  };
125
121
  function transformCallHierarchyItem(tsItem, tsRanges) {
126
- var _a, _b;
127
122
  const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(tsItem.uri);
128
123
  if (!sourceMap)
129
124
  return [tsItem, tsRanges]; // not virtual file
130
- let vueRange = (_a = sourceMap.getSourceRange(tsItem.range.start, tsItem.range.end)) === null || _a === void 0 ? void 0 : _a[0];
131
- if (!vueRange) {
125
+ let range = sourceMap.toSourceRange(tsItem.range);
126
+ if (!range) {
132
127
  // TODO: <script> range
133
- vueRange = {
128
+ range = {
134
129
  start: sourceMap.sourceDocument.positionAt(0),
135
130
  end: sourceMap.sourceDocument.positionAt(sourceMap.sourceDocument.getText().length),
136
131
  };
137
132
  }
138
- const vueSelectionRange = (_b = sourceMap.getSourceRange(tsItem.selectionRange.start, tsItem.selectionRange.end)) === null || _b === void 0 ? void 0 : _b[0];
139
- if (!vueSelectionRange)
133
+ const selectionRange = sourceMap.toSourceRange(tsItem.selectionRange);
134
+ if (!selectionRange)
140
135
  return;
141
- const vueRanges = tsRanges.map(tsRange => { var _a; return (_a = sourceMap.getSourceRange(tsRange.start, tsRange.end)) === null || _a === void 0 ? void 0 : _a[0]; }).filter(shared.notEmpty);
142
- const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === upath.basename(shared.getPathOfUri(sourceMap.mappedDocument.uri)) ? upath.basename(shared.getPathOfUri(sourceMap.sourceDocument.uri)) : tsItem.name, uri: sourceMap.sourceDocument.uri, range: vueRange, selectionRange: vueSelectionRange });
136
+ const vueRanges = tsRanges.map(tsRange => sourceMap.toSourceRange(tsRange)).filter(shared.notEmpty);
137
+ const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === upath.basename(shared.getPathOfUri(sourceMap.mappedDocument.uri)) ? upath.basename(shared.getPathOfUri(sourceMap.sourceDocument.uri)) : tsItem.name, uri: sourceMap.sourceDocument.uri,
138
+ // TS Bug: `range: range` not works
139
+ range: {
140
+ start: range.start,
141
+ end: range.end,
142
+ }, selectionRange: {
143
+ start: selectionRange.start,
144
+ end: selectionRange.end,
145
+ } });
146
+ selectionRange.end;
143
147
  return [vueItem, vueRanges];
144
148
  }
145
149
  }
@@ -25,22 +25,23 @@ function register(context) {
25
25
  end: document.offsetAt(range.end),
26
26
  };
27
27
  let codeActions = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, { range, codeActionContext }, (arg, sourceMap) => {
28
- var _a;
29
- if (!sourceMap.embeddedFile.capabilities.codeActions)
28
+ var _a, _b;
29
+ if (!sourceMap.embeddedFile.capabilities.codeAction)
30
30
  return [];
31
31
  const _codeActionContext = {
32
- diagnostics: (0, transforms_1.transformLocations)(codeActionContext.diagnostics, range => { var _a; return (_a = sourceMap.getMappedRange(range.start, range.end)) === null || _a === void 0 ? void 0 : _a[0]; }),
32
+ diagnostics: (0, transforms_1.transformLocations)(codeActionContext.diagnostics, range => sourceMap.toGeneratedRange(range)),
33
33
  only: codeActionContext.only,
34
34
  };
35
35
  let minStart;
36
36
  let maxEnd;
37
- for (const mapping of sourceMap.base.mappings) {
38
- const overlapRange = shared.getOverlapRange2(offsetRange, mapping.sourceRange);
37
+ for (const mapping of sourceMap.mappings) {
38
+ const overlapRange = shared.getOverlapRange2(offsetRange.start, offsetRange.end, mapping.sourceRange[0], mapping.sourceRange[1]);
39
39
  if (overlapRange) {
40
- const embeddedRange = (_a = sourceMap.getMappedRange(overlapRange.start, overlapRange.end)) === null || _a === void 0 ? void 0 : _a[0];
41
- if (embeddedRange) {
42
- minStart = minStart === undefined ? embeddedRange.start : Math.min(embeddedRange.start, minStart);
43
- maxEnd = maxEnd === undefined ? embeddedRange.end : Math.max(embeddedRange.end, maxEnd);
40
+ const start = (_a = sourceMap.toGeneratedOffset(overlapRange.start)) === null || _a === void 0 ? void 0 : _a[0];
41
+ const end = (_b = sourceMap.toGeneratedOffset(overlapRange.end)) === null || _b === void 0 ? void 0 : _b[0];
42
+ if (start !== undefined && end !== undefined) {
43
+ minStart = minStart === undefined ? start : Math.min(start, minStart);
44
+ maxEnd = maxEnd === undefined ? end : Math.max(end, maxEnd);
44
45
  }
45
46
  }
46
47
  }
@@ -29,10 +29,9 @@ function register(context) {
29
29
  });
30
30
  }
31
31
  }), (data, sourceMap) => data.map(codeLens => {
32
- var _a;
33
32
  if (!sourceMap)
34
33
  return codeLens;
35
- const range = (_a = sourceMap.getSourceRange(codeLens.range.start, codeLens.range.end)) === null || _a === void 0 ? void 0 : _a[0];
34
+ const range = sourceMap.toSourceRange(codeLens.range);
36
35
  if (range) {
37
36
  return Object.assign(Object.assign({}, codeLens), { range });
38
37
  }
@@ -26,16 +26,16 @@ function register(context) {
26
26
  const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(cacheData.sourceMap.embeddedDocumentUri);
27
27
  if (!sourceMap)
28
28
  continue;
29
- for (const [embeddedRange] of sourceMap.getMappedRanges(position, position, data => !!data.completion)) {
29
+ for (const mapped of sourceMap.toGeneratedPositions(position, data => !!data.completion)) {
30
30
  if (!((_a = cacheData.plugin.complete) === null || _a === void 0 ? void 0 : _a.on))
31
31
  continue;
32
- const embeddedCompletionList = yield cacheData.plugin.complete.on(sourceMap.mappedDocument, embeddedRange.start, completionContext);
32
+ const embeddedCompletionList = yield cacheData.plugin.complete.on(sourceMap.mappedDocument, mapped, completionContext);
33
33
  if (!embeddedCompletionList) {
34
34
  cacheData.list.isIncomplete = false;
35
35
  continue;
36
36
  }
37
37
  cacheData.list = Object.assign(Object.assign({}, embeddedCompletionList), { items: embeddedCompletionList.items.map(item => {
38
- return Object.assign(Object.assign({}, (0, transforms_1.transformCompletionItem)(item, embeddedRange => { var _a; return (_a = sourceMap.getSourceRange(embeddedRange.start, embeddedRange.end)) === null || _a === void 0 ? void 0 : _a[0]; })), { data: {
38
+ return Object.assign(Object.assign({}, (0, transforms_1.transformCompletionItem)(item, embeddedRange => sourceMap.toSourceRange(embeddedRange))), { data: {
39
39
  uri,
40
40
  originalItem: item,
41
41
  pluginId: context.plugins.indexOf(cacheData.plugin),
@@ -78,7 +78,11 @@ function register(context) {
78
78
  yield (0, definePlugin_1.visitEmbedded)(vueDocument, (sourceMap) => __awaiter(this, void 0, void 0, function* () {
79
79
  var _e, _f;
80
80
  const plugins = context.plugins.sort(sortPlugins);
81
- for (const [embeddedRange, data] of sourceMap.getMappedRanges(position, position, data => !!data.completion)) {
81
+ let _data;
82
+ for (const mapped of sourceMap.toGeneratedPositions(position, data => {
83
+ _data = data;
84
+ return !!data.completion;
85
+ })) {
82
86
  for (const plugin of plugins) {
83
87
  if (!((_e = plugin.complete) === null || _e === void 0 ? void 0 : _e.on))
84
88
  continue;
@@ -86,20 +90,20 @@ function register(context) {
86
90
  continue;
87
91
  if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_f = plugin.complete.triggerCharacters) === null || _f === void 0 ? void 0 : _f.includes(completionContext.triggerCharacter)))
88
92
  continue;
89
- const isAdditional = typeof data.completion === 'object' && data.completion.additional || plugin.complete.isAdditional;
93
+ const isAdditional = _data && typeof _data.completion === 'object' && _data.completion.additional || plugin.complete.isAdditional;
90
94
  if (cache.mainCompletion && (!isAdditional || (cache === null || cache === void 0 ? void 0 : cache.mainCompletion.documentUri) !== sourceMap.mappedDocument.uri))
91
95
  continue;
92
96
  // avoid duplicate items with .vue and .vue.html
93
97
  if (plugin.complete.isAdditional && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin)))
94
98
  continue;
95
- const embeddedCompletionList = yield plugin.complete.on(sourceMap.mappedDocument, embeddedRange.start, completionContext);
99
+ const embeddedCompletionList = yield plugin.complete.on(sourceMap.mappedDocument, mapped, completionContext);
96
100
  if (!embeddedCompletionList || !embeddedCompletionList.items.length)
97
101
  continue;
98
102
  if (!isAdditional) {
99
103
  cache.mainCompletion = { documentUri: sourceMap.mappedDocument.uri };
100
104
  }
101
105
  const completionList = Object.assign(Object.assign({}, embeddedCompletionList), { items: embeddedCompletionList.items.map(item => {
102
- return Object.assign(Object.assign({}, (0, transforms_1.transformCompletionItem)(item, embeddedRange => { var _a; return (_a = sourceMap.getSourceRange(embeddedRange.start, embeddedRange.end)) === null || _a === void 0 ? void 0 : _a[0]; })), { data: {
106
+ return Object.assign(Object.assign({}, (0, transforms_1.transformCompletionItem)(item, embeddedRange => sourceMap.toSourceRange(embeddedRange))), { data: {
103
107
  uri,
104
108
  originalItem: item,
105
109
  pluginId: context.plugins.indexOf(plugin),
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (item: vscode.CompletionItem, newPosition?: vscode.Position) => Promise<vscode.CompletionItem>;
3
+ export declare function register(context: LanguageServiceRuntimeContext): (item: vscode.CompletionItem) => Promise<vscode.CompletionItem>;
@@ -11,8 +11,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
12
  const transforms_1 = require("@volar/transforms");
13
13
  function register(context) {
14
- return (item, newPosition) => __awaiter(this, void 0, void 0, function* () {
15
- var _a, _b;
14
+ return (item) => __awaiter(this, void 0, void 0, function* () {
15
+ var _a;
16
16
  const data = item.data;
17
17
  if (data) {
18
18
  const plugin = context.plugins[data.pluginId];
@@ -24,10 +24,7 @@ function register(context) {
24
24
  if (data.sourceMap) {
25
25
  const sourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(data.sourceMap.embeddedDocumentUri);
26
26
  if (sourceMap) {
27
- const newPosition_2 = newPosition
28
- ? (_b = sourceMap.getMappedRange(newPosition, newPosition, data => !!data.completion)) === null || _b === void 0 ? void 0 : _b[0].start
29
- : undefined;
30
- const resolvedItem = yield plugin.complete.resolve(originalItem, newPosition_2);
27
+ const resolvedItem = yield plugin.complete.resolve(originalItem);
31
28
  // fix https://github.com/johnsoncodehk/volar/issues/916
32
29
  if (resolvedItem.additionalTextEdits) {
33
30
  for (const edit of resolvedItem.additionalTextEdits) {
@@ -40,8 +37,11 @@ function register(context) {
40
37
  }
41
38
  }
42
39
  item = (0, transforms_1.transformCompletionItem)(resolvedItem, embeddedRange => {
43
- var _a, _b, _c;
44
- return (_b = (_a = plugin.resolveEmbeddedRange) === null || _a === void 0 ? void 0 : _a.call(plugin, embeddedRange)) !== null && _b !== void 0 ? _b : (_c = sourceMap.getSourceRange(embeddedRange.start, embeddedRange.end)) === null || _c === void 0 ? void 0 : _c[0];
40
+ var _a;
41
+ let range = (_a = plugin.resolveEmbeddedRange) === null || _a === void 0 ? void 0 : _a.call(plugin, embeddedRange);
42
+ if (range)
43
+ return range;
44
+ return sourceMap.toSourceRange(embeddedRange);
45
45
  });
46
46
  }
47
47
  }
@@ -14,11 +14,7 @@ const featureWorkers_1 = require("../utils/featureWorkers");
14
14
  const dedupe = require("../utils/dedupe");
15
15
  function register(context, api, isValidMappingData, isValidTeleportSideData) {
16
16
  return (uri, position) => {
17
- return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, function* (position, sourceMap) {
18
- for (const [mappedRange] of sourceMap.getMappedRanges(position, position, isValidMappingData)) {
19
- yield mappedRange.start;
20
- }
21
- }, (plugin, document, position, sourceMap) => __awaiter(this, void 0, void 0, function* () {
17
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, sourceMap) => sourceMap.toGeneratedPositions(position, isValidMappingData), (plugin, document, position, sourceMap) => __awaiter(this, void 0, void 0, function* () {
22
18
  const recursiveChecker = dedupe.createLocationSet();
23
19
  const result = [];
24
20
  yield withTeleports(document, position, undefined);
@@ -41,11 +37,13 @@ function register(context, api, isValidMappingData, isValidTeleportSideData) {
41
37
  recursiveChecker.add({ uri: definition.targetUri, range: { start: definition.targetRange.start, end: definition.targetRange.start } });
42
38
  const teleport = context.documents.teleportfromEmbeddedDocumentUri(definition.targetUri);
43
39
  if (teleport) {
44
- for (const [teleRange] of teleport.findTeleports(definition.targetSelectionRange.start, definition.targetSelectionRange.end, isValidTeleportSideData)) {
45
- if (recursiveChecker.has({ uri: teleport.document.uri, range: { start: teleRange.start, end: teleRange.start } }))
40
+ for (const mapped of teleport.findTeleports(definition.targetSelectionRange.start)) {
41
+ if (!isValidTeleportSideData(mapped[1]))
42
+ continue;
43
+ if (recursiveChecker.has({ uri: teleport.document.uri, range: { start: mapped[0], end: mapped[0] } }))
46
44
  continue;
47
45
  foundTeleport = true;
48
- yield withTeleports(teleport.document, teleRange.start, originDefinition !== null && originDefinition !== void 0 ? originDefinition : definition);
46
+ yield withTeleports(teleport.document, mapped[0], originDefinition !== null && originDefinition !== void 0 ? originDefinition : definition);
49
47
  }
50
48
  }
51
49
  if (!foundTeleport) {
@@ -60,21 +58,21 @@ function register(context, api, isValidMappingData, isValidTeleportSideData) {
60
58
  });
61
59
  }
62
60
  }), (data, sourceMap) => data.map(link => {
63
- var _a, _b;
64
61
  if (link.originSelectionRange && sourceMap) {
65
- const originSelectionRange = getSourceRangePreferSurroundedPosition(sourceMap, link.originSelectionRange, position);
62
+ const originSelectionRange = toSourcePositionPreferSurroundedPosition(sourceMap, link.originSelectionRange, position);
66
63
  if (!originSelectionRange)
67
64
  return;
68
65
  link.originSelectionRange = originSelectionRange;
69
66
  }
70
67
  const targetSourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(link.targetUri);
71
68
  if (targetSourceMap) {
72
- const targetRange = (_a = targetSourceMap.getSourceRange(link.targetRange.start, link.targetRange.end)) === null || _a === void 0 ? void 0 : _a[0];
73
- const targetSelectionRange = (_b = targetSourceMap.getSourceRange(link.targetSelectionRange.start, link.targetSelectionRange.end)) === null || _b === void 0 ? void 0 : _b[0];
69
+ const targetSelectionRange = targetSourceMap.toSourceRange(link.targetSelectionRange);
74
70
  if (!targetSelectionRange)
75
71
  return;
72
+ let targetRange = targetSourceMap.toSourceRange(link.targetRange);
76
73
  link.targetUri = targetSourceMap.sourceDocument.uri;
77
- link.targetRange = targetRange !== null && targetRange !== void 0 ? targetRange : targetSelectionRange; // loose range mapping to for template slots, slot properties
74
+ // loose range mapping to for template slots, slot properties
75
+ link.targetRange = targetRange !== null && targetRange !== void 0 ? targetRange : targetSelectionRange;
78
76
  link.targetSelectionRange = targetSelectionRange;
79
77
  }
80
78
  return link;
@@ -82,16 +80,15 @@ function register(context, api, isValidMappingData, isValidTeleportSideData) {
82
80
  };
83
81
  }
84
82
  exports.register = register;
85
- function getSourceRangePreferSurroundedPosition(sourceMap, mappedRange, position) {
83
+ function toSourcePositionPreferSurroundedPosition(sourceMap, mappedRange, position) {
86
84
  let result;
87
- for (const [sourceRange] of sourceMap.getSourceRanges(mappedRange.start, mappedRange.end)) {
85
+ for (const range of sourceMap.toSourceRanges(mappedRange)) {
88
86
  if (!result) {
89
- result = sourceRange;
87
+ result = range;
90
88
  }
91
- if ((sourceRange.start.line < position.line || (sourceRange.start.line === position.line && sourceRange.start.character <= position.character))
92
- && (sourceRange.end.line > position.line || (sourceRange.end.line === position.line && sourceRange.end.character >= position.character))) {
93
- result = sourceRange;
94
- break;
89
+ if ((range.start.line < position.line || (range.start.line === position.line && range.start.character <= position.character))
90
+ && (range.end.line > position.line || (range.end.line === position.line && range.end.character >= position.character))) {
91
+ return range;
95
92
  }
96
93
  }
97
94
  return result;