@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
@@ -14,11 +14,7 @@ const featureWorkers_1 = require("../utils/featureWorkers");
14
14
  const dedupe = require("../utils/dedupe");
15
15
  function register(context) {
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, data => !!data.references)) {
19
- yield mappedRange.start;
20
- }
21
- }, (plugin, document, position, sourceMap, vueDocument) => __awaiter(this, void 0, void 0, function* () {
17
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, sourceMap) => sourceMap.toGeneratedPositions(position, data => !!data.references), (plugin, document, position, sourceMap, vueDocument) => __awaiter(this, void 0, void 0, function* () {
22
18
  const recursiveChecker = dedupe.createLocationSet();
23
19
  const result = [];
24
20
  yield withTeleports(document, position);
@@ -37,11 +33,13 @@ function register(context) {
37
33
  recursiveChecker.add({ uri: document.uri, range: { start: reference.range.start, end: reference.range.start } });
38
34
  const teleport = context.documents.teleportfromEmbeddedDocumentUri(document.uri);
39
35
  if (teleport) {
40
- for (const [teleRange] of teleport.findTeleports(reference.range.start, reference.range.end, sideData => !!sideData.references)) {
41
- if (recursiveChecker.has({ uri: teleport.document.uri, range: { start: teleRange.start, end: teleRange.start } }))
36
+ for (const mapped of teleport.findTeleports(reference.range.start)) {
37
+ if (!mapped[1].references)
38
+ continue;
39
+ if (recursiveChecker.has({ uri: teleport.document.uri, range: { start: mapped[0], end: mapped[0] } }))
42
40
  continue;
43
41
  foundTeleport = true;
44
- yield withTeleports(teleport.document, teleRange.start);
42
+ yield withTeleports(teleport.document, mapped[0]);
45
43
  }
46
44
  }
47
45
  if (!foundTeleport) {
@@ -51,10 +49,9 @@ function register(context) {
51
49
  });
52
50
  }
53
51
  }), (data, sourceMap) => data.map(highlisht => {
54
- var _a;
55
52
  if (!sourceMap)
56
53
  return highlisht;
57
- const range = (_a = sourceMap.getSourceRange(highlisht.range.start, highlisht.range.end)) === null || _a === void 0 ? void 0 : _a[0];
54
+ const range = sourceMap.toSourceRange(highlisht.range);
58
55
  if (range) {
59
56
  return Object.assign(Object.assign({}, highlisht), { range });
60
57
  }
@@ -15,10 +15,9 @@ function register(context) {
15
15
  return (uri) => __awaiter(this, void 0, void 0, function* () {
16
16
  var _a;
17
17
  const pluginLinks = (_a = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg, sourceMap) => [arg], (plugin, document, arg) => { var _a; return (_a = plugin.findDocumentLinks) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, sourceMap) => data.map(link => {
18
- var _a;
19
18
  if (!sourceMap)
20
19
  return link;
21
- const range = (_a = sourceMap.getSourceRange(link.range.start, link.range.end)) === null || _a === void 0 ? void 0 : _a[0];
20
+ const range = sourceMap.toSourceRange(link.range);
22
21
  if (range) {
23
22
  return Object.assign(Object.assign({}, link), { range });
24
23
  }
@@ -33,13 +32,13 @@ function register(context) {
33
32
  const result = [];
34
33
  const document = vueDocument.getDocument();
35
34
  for (const sourceMap of vueDocument.getSourceMaps()) {
36
- for (const mapped of sourceMap.base.mappings) {
35
+ for (const mapped of sourceMap.mappings) {
37
36
  if (!mapped.data.displayWithLink)
38
37
  continue;
39
38
  result.push({
40
39
  range: {
41
- start: document.positionAt(mapped.sourceRange.start),
42
- end: document.positionAt(mapped.sourceRange.end),
40
+ start: document.positionAt(mapped.sourceRange[0]),
41
+ end: document.positionAt(mapped.sourceRange[1]),
43
42
  },
44
43
  target: uri, // TODO
45
44
  });
@@ -8,29 +8,29 @@ function register(context) {
8
8
  const document = context.getTextDocument(uri);
9
9
  if (!document)
10
10
  return;
11
- const offsetRange = range ? {
12
- start: document.offsetAt(range.start),
13
- end: document.offsetAt(range.end),
14
- } : {
15
- start: 0,
16
- end: document.getText().length,
17
- };
11
+ const offsetRange = range ? [
12
+ document.offsetAt(range.start),
13
+ document.offsetAt(range.end),
14
+ ] : [
15
+ 0,
16
+ document.getText().length,
17
+ ];
18
18
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, offsetRange, function* (offsetRange, sourceMap) {
19
19
  if (cancleToken === null || cancleToken === void 0 ? void 0 : cancleToken.isCancellationRequested)
20
20
  return;
21
21
  let range;
22
- for (const mapping of sourceMap.base.mappings) {
22
+ for (const mapping of sourceMap.mappings) {
23
23
  if (cancleToken === null || cancleToken === void 0 ? void 0 : cancleToken.isCancellationRequested)
24
24
  return;
25
25
  if (mapping.data.semanticTokens
26
- && mapping.sourceRange.end > offsetRange.start
27
- && mapping.sourceRange.start < offsetRange.end) {
26
+ && mapping.sourceRange[1] > offsetRange[0]
27
+ && mapping.sourceRange[0] < offsetRange[1]) {
28
28
  if (!range) {
29
- range = Object.assign({}, mapping.mappedRange);
29
+ range = [...mapping.generatedRange];
30
30
  }
31
31
  else {
32
- range.start = Math.min(range.start, mapping.mappedRange.start);
33
- range.end = Math.max(range.end, mapping.mappedRange.end);
32
+ range[0] = Math.min(range[0], mapping.generatedRange[0]);
33
+ range[1] = Math.max(range[1], mapping.generatedRange[1]);
34
34
  }
35
35
  }
36
36
  }
@@ -39,19 +39,17 @@ function register(context) {
39
39
  }
40
40
  }, (plugin, document, offsetRange) => {
41
41
  var _a;
42
- return (_a = plugin.findDocumentSemanticTokens) === null || _a === void 0 ? void 0 : _a.call(plugin, document, vscode.Range.create(document.positionAt(offsetRange.start), document.positionAt(offsetRange.end)), cancleToken);
42
+ return (_a = plugin.findDocumentSemanticTokens) === null || _a === void 0 ? void 0 : _a.call(plugin, document, vscode.Range.create(document.positionAt(offsetRange[0]), document.positionAt(offsetRange[1])), cancleToken);
43
43
  }, (tokens, sourceMap) => tokens.map(_token => {
44
- var _a;
45
44
  if (!sourceMap)
46
45
  return _token;
47
- const _start = sourceMap.mappedDocument.offsetAt({ line: _token[0], character: _token[1] });
48
- const _end = sourceMap.mappedDocument.offsetAt({ line: _token[0], character: _token[1] + _token[2] });
49
- const range = (_a = sourceMap.getSourceRange(_start, _end, data => !!data.semanticTokens)) === null || _a === void 0 ? void 0 : _a[0];
50
- if (!range)
51
- return;
52
- const start = document.positionAt(range.start);
53
- const token = [start.line, start.character, range.end - range.start, _token[3], _token[4]];
54
- return token;
46
+ const range = sourceMap.toSourceRange({
47
+ start: { line: _token[0], character: _token[1] },
48
+ end: { line: _token[0], character: _token[1] + _token[2] },
49
+ }, data => !!data.semanticTokens);
50
+ if (range) {
51
+ return [range.start.line, range.start.character, _token[2], _token[3], _token[4]];
52
+ }
55
53
  }).filter(shared.notEmpty), tokens => tokens.flat(), reportProgress);
56
54
  };
57
55
  }
@@ -1,7 +1,7 @@
1
1
  import type { LanguageServiceRuntimeContext } from '../types';
2
2
  import { ExecuteCommandContext } from '@volar/language-service';
3
3
  import * as vscode from 'vscode-languageserver-protocol';
4
- export declare const executePluginCommand = "volar.executtePluginCommand";
4
+ export declare const executePluginCommand = "volar.executePluginCommand";
5
5
  export type ExecutePluginCommandArgs = [
6
6
  string,
7
7
  // uri
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = exports.executePluginCommand = void 0;
12
- exports.executePluginCommand = 'volar.executtePluginCommand';
12
+ exports.executePluginCommand = 'volar.executePluginCommand';
13
13
  function register(context) {
14
14
  return (command, args, executeCommandContext) => __awaiter(this, void 0, void 0, function* () {
15
15
  var _a, _b;
@@ -14,22 +14,24 @@ const featureWorkers_1 = require("../utils/featureWorkers");
14
14
  const dedupe = require("../utils/dedupe");
15
15
  function register(context) {
16
16
  return (uri) => {
17
- return (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, function* (_, sourceMap) {
17
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, function* (_) {
18
18
  yield _;
19
- }, (plugin, document, _, sourceMap, vueDocument) => __awaiter(this, void 0, void 0, function* () {
19
+ }, (plugin, document) => __awaiter(this, void 0, void 0, function* () {
20
20
  var _a, _b;
21
21
  return (_b = yield ((_a = plugin.findFileReferences) === null || _a === void 0 ? void 0 : _a.call(plugin, document))) !== null && _b !== void 0 ? _b : [];
22
22
  }), (data, sourceMap) => data.map(reference => {
23
- var _a;
24
- const referenceSourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(reference.uri);
25
- if (referenceSourceMap) {
26
- const range = (_a = referenceSourceMap.getSourceRange(reference.range.start, reference.range.end, data => !!data.references)) === null || _a === void 0 ? void 0 : _a[0];
27
- if (!range)
28
- return;
29
- reference.uri = referenceSourceMap.sourceDocument.uri;
30
- reference.range = range;
23
+ const map = context.documents.sourceMapFromEmbeddedDocumentUri(reference.uri);
24
+ if (!map) {
25
+ return reference;
26
+ }
27
+ if (map) {
28
+ const range = map.toSourceRange(reference.range);
29
+ if (range) {
30
+ reference.uri = map.sourceDocument.uri;
31
+ reference.range = range;
32
+ return reference;
33
+ }
31
34
  }
32
- return reference;
33
35
  }).filter(shared.notEmpty), arr => dedupe.withLocations(arr.flat()));
34
36
  };
35
37
  }
@@ -18,7 +18,7 @@ function register(context) {
18
18
  if (vueDocument) {
19
19
  let tsExt;
20
20
  (0, language_core_1.forEachEmbeddeds)(vueDocument.file.embeddeds, embedded => {
21
- if (embedded.isTsHostFile && embedded.fileName.replace(vueDocument.file.fileName, '').match(/^\.(js|ts)x?$/)) {
21
+ if (embedded.kind && embedded.fileName.replace(vueDocument.file.fileName, '').match(/^\.(js|ts)x?$/)) {
22
22
  tsExt = embedded.fileName.substring(embedded.fileName.lastIndexOf('.'));
23
23
  }
24
24
  });
@@ -5,20 +5,13 @@ const shared = require("@volar/shared");
5
5
  const featureWorkers_1 = require("../utils/featureWorkers");
6
6
  function register(context) {
7
7
  return (uri, position) => {
8
- return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, function* (position, sourceMap) {
9
- for (const [mappedRange] of sourceMap.getMappedRanges(position, position, data => !!data.hover)) {
10
- yield mappedRange.start;
11
- }
12
- }, (plugin, document, position) => { var _a; return (_a = plugin.doHover) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position); }, (data, sourceMap) => {
13
- var _a;
14
- if (!sourceMap)
15
- return data;
16
- if (!data.range)
17
- return data;
18
- const range = (_a = sourceMap.getSourceRange(data.range.start, data.range.end)) === null || _a === void 0 ? void 0 : _a[0];
8
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, sourceMap) => sourceMap.toGeneratedPositions(position, data => !!data.hover), (plugin, document, position) => { var _a; return (_a = plugin.doHover) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position); }, (item, sourceMap) => {
9
+ if (!sourceMap || !item.range)
10
+ return item;
11
+ const range = sourceMap.toSourceRange(item.range);
19
12
  if (range) {
20
- data.range = range;
21
- return data;
13
+ item.range = range;
14
+ return item;
22
15
  }
23
16
  }, hovers => {
24
17
  var _a, _b;
@@ -26,18 +26,19 @@ function register(context) {
26
26
  /**
27
27
  * copy from ./codeActions.ts
28
28
  */
29
- var _a;
30
- if (!sourceMap.embeddedFile.capabilities.inlayHints)
29
+ var _a, _b;
30
+ if (!sourceMap.embeddedFile.capabilities.inlayHint)
31
31
  return [];
32
32
  let minStart;
33
33
  let maxEnd;
34
- for (const mapping of sourceMap.base.mappings) {
35
- const overlapRange = shared.getOverlapRange2(offsetRange, mapping.sourceRange);
34
+ for (const mapping of sourceMap.mappings) {
35
+ const overlapRange = shared.getOverlapRange2(offsetRange.start, offsetRange.end, mapping.sourceRange[0], mapping.sourceRange[1]);
36
36
  if (overlapRange) {
37
- const embeddedRange = (_a = sourceMap.getMappedRange(overlapRange.start, overlapRange.end)) === null || _a === void 0 ? void 0 : _a[0];
38
- if (embeddedRange) {
39
- minStart = minStart === undefined ? embeddedRange.start : Math.min(embeddedRange.start, minStart);
40
- maxEnd = maxEnd === undefined ? embeddedRange.end : Math.max(embeddedRange.end, maxEnd);
37
+ const start = (_a = sourceMap.toGeneratedOffset(overlapRange.start)) === null || _a === void 0 ? void 0 : _a[0];
38
+ const end = (_b = sourceMap.toGeneratedOffset(overlapRange.end)) === null || _b === void 0 ? void 0 : _b[0];
39
+ if (start !== undefined && end !== undefined) {
40
+ minStart = minStart === undefined ? start : Math.min(start, minStart);
41
+ maxEnd = maxEnd === undefined ? end : Math.max(end, maxEnd);
41
42
  }
42
43
  }
43
44
  }
@@ -49,11 +50,11 @@ function register(context) {
49
50
  var _a, _b;
50
51
  return (_b = (_a = plugin.inlayHints) === null || _a === void 0 ? void 0 : _a.on) === null || _b === void 0 ? void 0 : _b.call(_a, document, arg);
51
52
  }, (inlayHints, sourceMap) => inlayHints.map(_inlayHint => {
52
- var _a, _b;
53
+ var _a;
53
54
  if (!sourceMap)
54
55
  return _inlayHint;
55
- const position = (_a = sourceMap.getSourceRange(_inlayHint.position, _inlayHint.position, data => !!data.completion)) === null || _a === void 0 ? void 0 : _a[0].start;
56
- const edits = (_b = _inlayHint.textEdits) === null || _b === void 0 ? void 0 : _b.map(textEdit => (0, transforms_1.transformTextEdit)(textEdit, range => { var _a; return (_a = sourceMap.getSourceRange(range.start, range.end)) === null || _a === void 0 ? void 0 : _a[0]; })).filter(shared.notEmpty);
56
+ const position = sourceMap.toSourcePosition(_inlayHint.position);
57
+ const edits = (_a = _inlayHint.textEdits) === null || _a === void 0 ? void 0 : _a.map(textEdit => (0, transforms_1.transformTextEdit)(textEdit, range => sourceMap.toSourceRange(range))).filter(shared.notEmpty);
57
58
  if (position) {
58
59
  return Object.assign(Object.assign({}, _inlayHint), { position,
59
60
  edits });
@@ -13,11 +13,7 @@ const featureWorkers_1 = require("../utils/featureWorkers");
13
13
  const dedupe = require("../utils/dedupe");
14
14
  function register(context) {
15
15
  return (uri, position) => {
16
- return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, function* (position, sourceMap) {
17
- for (const [mappedRange] of sourceMap.getMappedRanges(position, position, data => !!data.references)) {
18
- yield mappedRange.start;
19
- }
20
- }, (plugin, document, position, sourceMap, vueDocument) => __awaiter(this, void 0, void 0, function* () {
16
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, sourceMap) => sourceMap.toGeneratedPositions(position, data => !!data.references), (plugin, document, position, sourceMap, vueDocument) => __awaiter(this, void 0, void 0, function* () {
21
17
  const recursiveChecker = dedupe.createLocationSet();
22
18
  const result = [];
23
19
  yield withTeleports(document, position);
@@ -36,11 +32,13 @@ function register(context) {
36
32
  recursiveChecker.add({ uri: reference.uri, range: { start: reference.range.start, end: reference.range.start } });
37
33
  const teleport = context.documents.teleportfromEmbeddedDocumentUri(reference.uri);
38
34
  if (teleport) {
39
- for (const [teleRange] of teleport.findTeleports(reference.range.start, reference.range.end, sideData => !!sideData.references)) {
40
- if (recursiveChecker.has({ uri: teleport.document.uri, range: { start: teleRange.start, end: teleRange.start } }))
35
+ for (const mapped of teleport.findTeleports(reference.range.start)) {
36
+ if (!mapped[1].references)
37
+ continue;
38
+ if (recursiveChecker.has({ uri: teleport.document.uri, range: { start: mapped[0], end: mapped[0] } }))
41
39
  continue;
42
40
  foundTeleport = true;
43
- yield withTeleports(teleport.document, teleRange.start);
41
+ yield withTeleports(teleport.document, mapped[0]);
44
42
  }
45
43
  }
46
44
  if (!foundTeleport) {
@@ -52,16 +50,19 @@ function register(context) {
52
50
  }), (data, sourceMap) => {
53
51
  const results = [];
54
52
  for (const reference of data) {
55
- const referenceSourceMap = context.documents.sourceMapFromEmbeddedDocumentUri(reference.uri);
56
- if (referenceSourceMap) {
57
- for (const [range] of referenceSourceMap.getSourceRanges(reference.range.start, reference.range.end, data => !!data.references)) {
53
+ const map = context.documents.sourceMapFromEmbeddedDocumentUri(reference.uri);
54
+ if (map) {
55
+ const range = map.toSourceRange(reference.range, data => !!data.references);
56
+ if (range) {
58
57
  results.push({
59
- uri: referenceSourceMap.sourceDocument.uri,
58
+ uri: map.sourceDocument.uri,
60
59
  range,
61
60
  });
62
61
  }
63
62
  }
64
- results.push(reference);
63
+ else {
64
+ results.push(reference);
65
+ }
65
66
  }
66
67
  return results;
67
68
  }, arr => dedupe.withLocations(arr.flat()));
@@ -3,17 +3,4 @@ import type { LanguageServiceRuntimeContext } from '../types';
3
3
  import { SourceFileDocuments } from '../documents';
4
4
  export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
5
5
  export declare function mergeWorkspaceEdits(original: vscode.WorkspaceEdit, ...others: vscode.WorkspaceEdit[]): void;
6
- /**
7
- * TODO: rewrite this
8
- *
9
- * Start from Script LS
10
- * -> Access all results
11
- *
12
- * Start from template LS
13
- * -> Start from template content?
14
- * -> Access all results
15
- * -> Start from script content?
16
- * -> Yes: Only access template results
17
- * -> No: Access all results
18
- */
19
6
  export declare function embeddedEditToSourceEdit(tsResult: vscode.WorkspaceEdit, vueDocuments: SourceFileDocuments): vscode.WorkspaceEdit | undefined;
@@ -14,13 +14,19 @@ const featureWorkers_1 = require("../utils/featureWorkers");
14
14
  const dedupe = require("../utils/dedupe");
15
15
  function register(context) {
16
16
  return (uri, position, newName) => {
17
+ let _data;
17
18
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, newName }, function* (arg, sourceMap) {
18
- for (const [mappedRange, mappedData] of sourceMap.getMappedRanges(arg.position, arg.position, data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename)) {
19
+ for (const mapped of sourceMap.toGeneratedPositions(arg.position, data => {
20
+ _data = data;
21
+ return typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename;
22
+ })) {
19
23
  let newName = arg.newName;
20
- if (typeof mappedData.rename === 'object' && mappedData.rename.normalize)
21
- newName = mappedData.rename.normalize(arg.newName);
22
- yield { position: mappedRange.start, newName };
24
+ if (_data && typeof _data.rename === 'object' && _data.rename.normalize) {
25
+ newName = _data.rename.normalize(arg.newName);
26
+ }
27
+ yield { position: mapped, newName };
23
28
  }
29
+ ;
24
30
  }, (plugin, document, arg, sourceMap) => __awaiter(this, void 0, void 0, function* () {
25
31
  const recursiveChecker = dedupe.createLocationSet();
26
32
  let result;
@@ -47,11 +53,13 @@ function register(context) {
47
53
  recursiveChecker.add({ uri: editUri, range: { start: textEdit.range.start, end: textEdit.range.start } });
48
54
  const teleport = context.documents.teleportfromEmbeddedDocumentUri(editUri);
49
55
  if (teleport) {
50
- for (const [teleRange] of teleport.findTeleports(textEdit.range.start, textEdit.range.end, sideData => !!sideData.rename)) {
51
- if (recursiveChecker.has({ uri: teleport.document.uri, range: { start: teleRange.start, end: teleRange.start } }))
56
+ for (const mapped of teleport.findTeleports(textEdit.range.start)) {
57
+ if (!mapped[1].rename)
58
+ continue;
59
+ if (recursiveChecker.has({ uri: teleport.document.uri, range: { start: mapped[0], end: mapped[0] } }))
52
60
  continue;
53
61
  foundTeleport = true;
54
- yield withTeleports(teleport.document, teleRange.start, newName);
62
+ yield withTeleports(teleport.document, mapped[0], newName);
55
63
  }
56
64
  }
57
65
  if (!foundTeleport) {
@@ -123,19 +131,6 @@ function mergeWorkspaceEdits(original, ...others) {
123
131
  }
124
132
  }
125
133
  exports.mergeWorkspaceEdits = mergeWorkspaceEdits;
126
- /**
127
- * TODO: rewrite this
128
- *
129
- * Start from Script LS
130
- * -> Access all results
131
- *
132
- * Start from template LS
133
- * -> Start from template content?
134
- * -> Access all results
135
- * -> Start from script content?
136
- * -> Yes: Only access template results
137
- * -> No: Access all results
138
- */
139
134
  function embeddedEditToSourceEdit(tsResult, vueDocuments) {
140
135
  var _a, _b, _c, _d, _e, _f;
141
136
  const vueResult = {};
@@ -148,24 +143,31 @@ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
148
143
  vueResult.changeAnnotations[uri] = tsAnno;
149
144
  }
150
145
  for (const tsUri in tsResult.changes) {
146
+ if (!vueResult.changes) {
147
+ vueResult.changes = {};
148
+ }
149
+ const map = vueDocuments.sourceMapFromEmbeddedDocumentUri(tsUri);
150
+ if (!map) {
151
+ vueResult.changes[tsUri] = tsResult.changes[tsUri];
152
+ hasResult = true;
153
+ continue;
154
+ }
151
155
  const tsEdits = tsResult.changes[tsUri];
152
156
  for (const tsEdit of tsEdits) {
153
- for (const vueLoc of vueDocuments.fromEmbeddedLocation(tsUri, tsEdit.range.start, tsEdit.range.end, data => typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename)) {
154
- let newText_2 = tsEdit.newText;
155
- if (vueLoc.sourceMap && typeof vueLoc.data.rename === 'object' && vueLoc.data.rename.apply) {
156
- const vueDoc = vueLoc.sourceMap.sourceDocument;
157
- newText_2 = vueLoc.data.rename.apply(vueDoc.getText(vueLoc.range), tsEdit.newText);
157
+ let _data;
158
+ const range = map.toSourceRange(tsEdit.range, data => {
159
+ _data = data;
160
+ return typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename;
161
+ });
162
+ if (range) {
163
+ let newText = tsEdit.newText;
164
+ if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
165
+ newText = _data.rename.apply(tsEdit.newText);
158
166
  }
159
- if (!vueResult.changes) {
160
- vueResult.changes = {};
167
+ if (!vueResult.changes[map.sourceDocument.uri]) {
168
+ vueResult.changes[map.sourceDocument.uri] = [];
161
169
  }
162
- if (!vueResult.changes[vueLoc.uri]) {
163
- vueResult.changes[vueLoc.uri] = [];
164
- }
165
- vueResult.changes[vueLoc.uri].push({
166
- newText: newText_2,
167
- range: vueLoc.range,
168
- });
170
+ vueResult.changes[map.sourceDocument.uri].push({ newText, range });
169
171
  hasResult = true;
170
172
  }
171
173
  }
@@ -185,11 +187,21 @@ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
185
187
  version: null, // fix https://github.com/johnsoncodehk/volar/issues/1490
186
188
  }, []);
187
189
  for (const tsEdit of tsDocEdit.edits) {
188
- for (const [vueRange] of sourceMap.getSourceRanges(tsEdit.range.start, tsEdit.range.end, data => typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename)) {
190
+ let _data;
191
+ const range = sourceMap.toSourceRange(tsEdit.range, data => {
192
+ _data = data;
193
+ // fix https://github.com/johnsoncodehk/volar/issues/1091
194
+ return typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename;
195
+ });
196
+ if (range) {
197
+ let newText = tsEdit.newText;
198
+ if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
199
+ newText = _data.rename.apply(tsEdit.newText);
200
+ }
189
201
  vueDocEdit.edits.push({
190
202
  annotationId: vscode.AnnotatedTextEdit.is(tsEdit.range) ? tsEdit.range.annotationId : undefined,
191
- newText: tsEdit.newText,
192
- range: vueRange,
203
+ newText,
204
+ range,
193
205
  });
194
206
  }
195
207
  }
@@ -17,15 +17,13 @@ const htmlWordPatterns = /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|
17
17
  function register(context) {
18
18
  return (uri, position) => __awaiter(this, void 0, void 0, function* () {
19
19
  const document = context.getTextDocument(uri);
20
- const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, function* (position, sourceMap) {
21
- for (const [mappedRange] of sourceMap.getMappedRanges(position, position, data => typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename)) {
22
- yield mappedRange.start;
20
+ const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, sourceMap) => sourceMap.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename), (plugin, document, position) => { var _a, _b; return (_b = (_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.prepare) === null || _b === void 0 ? void 0 : _b.call(_a, document, position); }, (item, sourceMap) => {
21
+ if (!sourceMap) {
22
+ return item;
23
+ }
24
+ if (vscode.Range.is(item)) {
25
+ return sourceMap.toSourceRange(item);
23
26
  }
24
- }, (plugin, document, position) => { var _a, _b; return (_b = (_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.prepare) === null || _b === void 0 ? void 0 : _b.call(_a, document, position); }, (data, sourceMap) => {
25
- var _a;
26
- if (sourceMap && vscode.Range.is(data))
27
- return (_a = sourceMap.getSourceRange(data.start, data.end)) === null || _a === void 0 ? void 0 : _a[0];
28
- return data;
29
27
  }, prepares => {
30
28
  for (const prepare of prepares) {
31
29
  if (vscode.Range.is(prepare)) {
@@ -3,11 +3,7 @@ exports.register = void 0;
3
3
  const featureWorkers_1 = require("../utils/featureWorkers");
4
4
  function register(context) {
5
5
  return (uri, position, signatureHelpContext) => {
6
- return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, function* (position, sourceMap) {
7
- for (const [mappedRange] of sourceMap.getMappedRanges(position, position, data => !!data.completion)) {
8
- yield mappedRange.start;
9
- }
10
- }, (plugin, document, position) => { var _a; return (_a = plugin.getSignatureHelp) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, signatureHelpContext); }, (data, sourceMap) => data);
6
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, sourceMap) => sourceMap.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => { var _a; return (_a = plugin.getSignatureHelp) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, signatureHelpContext); }, (data, sourceMap) => data);
11
7
  };
12
8
  }
13
9
  exports.register = register;