@volar/language-service 1.0.22 → 1.1.0-1.2.0-alpha.1.0

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 (67) hide show
  1. package/out/baseLanguageService.d.ts +3 -11
  2. package/out/baseLanguageService.js +34 -24
  3. package/out/documentFeatures/documentSymbols.js +3 -5
  4. package/out/documentFeatures/foldingRanges.js +2 -2
  5. package/out/documentFeatures/format.js +7 -7
  6. package/out/documentFeatures/selectionRanges.js +2 -2
  7. package/out/documents.d.ts +3 -3
  8. package/out/documents.js +17 -24
  9. package/out/index.d.ts +1 -0
  10. package/out/index.js +2 -1
  11. package/out/languageFeatures/callHierarchy.d.ts +2 -2
  12. package/out/languageFeatures/callHierarchy.js +18 -21
  13. package/out/languageFeatures/codeActionResolve.js +4 -6
  14. package/out/languageFeatures/codeActions.d.ts +2 -2
  15. package/out/languageFeatures/codeActions.js +14 -7
  16. package/out/languageFeatures/codeLens.d.ts +4 -4
  17. package/out/languageFeatures/codeLens.js +16 -10
  18. package/out/languageFeatures/codeLensResolve.js +10 -4
  19. package/out/languageFeatures/complete.d.ts +2 -2
  20. package/out/languageFeatures/complete.js +34 -35
  21. package/out/languageFeatures/completeResolve.js +5 -7
  22. package/out/languageFeatures/definition.js +1 -1
  23. package/out/languageFeatures/executeCommand.d.ts +1 -1
  24. package/out/languageFeatures/executeCommand.js +1 -1
  25. package/out/languageFeatures/fileReferences.js +1 -1
  26. package/out/languageFeatures/fileRename.js +4 -3
  27. package/out/languageFeatures/inlayHints.js +2 -2
  28. package/out/languageFeatures/references.js +1 -1
  29. package/out/languageFeatures/rename.js +5 -5
  30. package/out/languageFeatures/renamePrepare.js +1 -6
  31. package/out/languageFeatures/validation copy.d.ts +7 -0
  32. package/out/languageFeatures/validation copy.js +234 -0
  33. package/out/languageFeatures/validation.d.ts +6 -0
  34. package/out/languageFeatures/validation.js +118 -41
  35. package/out/languageFeatures/workspaceSymbols.js +4 -4
  36. package/out/transformer/completionItem.d.ts +2 -0
  37. package/out/transformer/completionItem.js +12 -0
  38. package/out/transformer/completionList.d.ts +2 -0
  39. package/out/transformer/completionList.js +23 -0
  40. package/out/transformer/foldingRanges.d.ts +2 -0
  41. package/out/transformer/foldingRanges.js +24 -0
  42. package/out/transformer/hover.d.ts +2 -0
  43. package/out/transformer/hover.js +13 -0
  44. package/out/transformer/index.d.ts +11 -0
  45. package/out/transformer/index.js +25 -0
  46. package/out/transformer/locationLike.d.ts +4 -0
  47. package/out/transformer/locationLike.js +10 -0
  48. package/out/transformer/locationsLike.d.ts +4 -0
  49. package/out/transformer/locationsLike.js +11 -0
  50. package/out/transformer/selectionRange.d.ts +2 -0
  51. package/out/transformer/selectionRange.js +14 -0
  52. package/out/transformer/selectionRanges.d.ts +2 -0
  53. package/out/transformer/selectionRanges.js +11 -0
  54. package/out/transformer/symbolInformation.d.ts +2 -0
  55. package/out/transformer/symbolInformation.js +10 -0
  56. package/out/transformer/symbolInformations.d.ts +2 -0
  57. package/out/transformer/symbolInformations.js +11 -0
  58. package/out/transformer/textEdit.d.ts +2 -0
  59. package/out/transformer/textEdit.js +57 -0
  60. package/out/types.d.ts +45 -9
  61. package/out/types.js +0 -1
  62. package/out/utils/common.d.ts +0 -2
  63. package/out/utils/common.js +1 -28
  64. package/out/utils/definePlugin.js +2 -1
  65. package/out/utils/featureWorkers.d.ts +2 -1
  66. package/out/utils/featureWorkers.js +89 -6
  67. package/package.json +7 -8
@@ -1,18 +1,10 @@
1
- import { createLanguageContext, LanguageServiceHost } from '@volar/language-core';
1
+ import { LanguageServiceHost } from '@volar/language-core';
2
2
  import * as executeCommand from './languageFeatures/executeCommand';
3
- import { LanguageServicePlugin, LanguageServicePluginInstance, LanguageServiceRuntimeContext } from './types';
3
+ import { LanguageServiceConfig, LanguageServiceRuntimeContext } from './types';
4
4
  import type * as ts from 'typescript/lib/tsserverlibrary';
5
5
  import type * as _ from 'vscode-languageserver-protocol';
6
6
  export type LanguageService = ReturnType<typeof createLanguageService>;
7
- export declare function createLanguageServiceContext(options: {
8
- host: LanguageServiceHost;
9
- context: ReturnType<typeof createLanguageContext>;
10
- getPlugins(): (LanguageServicePlugin | LanguageServicePluginInstance)[];
11
- env: LanguageServiceRuntimeContext['env'];
12
- documentRegistry: ts.DocumentRegistry | undefined;
13
- getLanguageService: () => LanguageService;
14
- }): LanguageServiceRuntimeContext<LanguageServiceHost>;
15
- export declare function createLanguageService(context: LanguageServiceRuntimeContext): {
7
+ export declare function createLanguageService(host: LanguageServiceHost, config: LanguageServiceConfig, env: LanguageServiceRuntimeContext['env'], documentRegistry?: ts.DocumentRegistry): {
16
8
  format: (uri: string, options: _.FormattingOptions, range?: _.Range | undefined, onTypeParams?: {
17
9
  ch: string;
18
10
  position: _.Position;
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.createLanguageService = exports.createLanguageServiceContext = void 0;
2
+ exports.createLanguageService = void 0;
3
+ const language_core_1 = require("@volar/language-core");
3
4
  const shared = require("@volar/shared");
4
5
  const tsFaster = require("@volar/typescript-faster");
5
6
  const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
@@ -34,41 +35,52 @@ const foldingRanges = require("./documentFeatures/foldingRanges");
34
35
  const format = require("./documentFeatures/format");
35
36
  const linkedEditingRanges = require("./documentFeatures/linkedEditingRanges");
36
37
  const selectionRanges = require("./documentFeatures/selectionRanges");
37
- function createLanguageServiceContext(options) {
38
- const ts = options.host.getTypeScriptModule();
39
- const tsLs = ts === null || ts === void 0 ? void 0 : ts.createLanguageService(options.context.typescript.languageServiceHost, options.documentRegistry);
38
+ function createLanguageService(host, config, env, documentRegistry) {
39
+ var _a;
40
+ const languageContext = (0, language_core_1.createLanguageContext)(host, Object.values((_a = config.languages) !== null && _a !== void 0 ? _a : {}).filter(shared.notEmpty));
41
+ const context = createLanguageServiceContext(host, languageContext, config, env, () => languageService, documentRegistry);
42
+ const languageService = createLanguageServiceBase(context);
43
+ return languageService;
44
+ }
45
+ exports.createLanguageService = createLanguageService;
46
+ function createLanguageServiceContext(host, languageContext, config, env, getLanguageService, documentRegistry) {
47
+ var _a, _b;
48
+ const ts = (_a = host.getTypeScriptModule) === null || _a === void 0 ? void 0 : _a.call(host);
49
+ const tsLs = ts === null || ts === void 0 ? void 0 : ts.createLanguageService(languageContext.typescript.languageServiceHost, documentRegistry);
40
50
  if (ts && tsLs) {
41
- tsFaster.decorate(ts, options.context.typescript.languageServiceHost, tsLs);
51
+ tsFaster.decorate(ts, languageContext.typescript.languageServiceHost, tsLs);
42
52
  }
43
53
  let plugins;
44
- const textDocumentMapper = (0, documents_1.createDocumentsAndSourceMaps)(options.context.virtualFiles);
54
+ const textDocumentMapper = (0, documents_1.createDocumentsAndSourceMaps)(languageContext.virtualFiles);
45
55
  const documents = new WeakMap();
46
56
  const documentVersions = new Map();
47
57
  const context = {
48
- host: options.host,
49
- core: options.context,
50
- env: options.env,
58
+ host,
59
+ core: languageContext,
60
+ env: env,
51
61
  get plugins() {
62
+ var _a, _b, _c, _d, _e;
52
63
  if (!plugins) {
53
- plugins = []; // avoid infinite loop
54
- plugins = options.getPlugins().map(plugin => {
55
- var _a, _b;
64
+ plugins = {}; // avoid infinite loop
65
+ for (let pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) {
66
+ const plugin = (_b = config.plugins) === null || _b === void 0 ? void 0 : _b[pluginId];
56
67
  if (plugin instanceof Function) {
57
- const _plugin = plugin(this, options.getLanguageService());
58
- (_a = _plugin.setup) === null || _a === void 0 ? void 0 : _a.call(_plugin, this);
59
- return _plugin;
68
+ const _plugin = plugin(this, getLanguageService());
69
+ (_c = _plugin.setup) === null || _c === void 0 ? void 0 : _c.call(_plugin, this);
70
+ plugins[pluginId] = _plugin;
60
71
  }
61
72
  else {
62
- (_b = plugin.setup) === null || _b === void 0 ? void 0 : _b.call(plugin, this);
63
- return plugin;
73
+ (_e = (_d = plugin).setup) === null || _e === void 0 ? void 0 : _e.call(_d, this);
74
+ plugins[pluginId] = plugin;
64
75
  }
65
- });
76
+ }
66
77
  }
67
78
  return plugins;
68
79
  },
80
+ rules: (_b = config.rules) !== null && _b !== void 0 ? _b : {},
69
81
  typescript: ts && tsLs ? {
70
82
  module: ts,
71
- languageServiceHost: options.context.typescript.languageServiceHost,
83
+ languageServiceHost: languageContext.typescript.languageServiceHost,
72
84
  languageService: tsLs,
73
85
  } : undefined,
74
86
  documents: textDocumentMapper,
@@ -77,8 +89,8 @@ function createLanguageServiceContext(options) {
77
89
  return context;
78
90
  function getTextDocument(uri) {
79
91
  var _a;
80
- const fileName = shared.getPathOfUri(uri);
81
- const scriptSnapshot = options.host.getScriptSnapshot(fileName);
92
+ const fileName = shared.uriToFileName(uri);
93
+ const scriptSnapshot = host.getScriptSnapshot(fileName);
82
94
  if (scriptSnapshot) {
83
95
  let document = documents.get(scriptSnapshot);
84
96
  if (!document) {
@@ -91,8 +103,7 @@ function createLanguageServiceContext(options) {
91
103
  }
92
104
  }
93
105
  }
94
- exports.createLanguageServiceContext = createLanguageServiceContext;
95
- function createLanguageService(context) {
106
+ function createLanguageServiceBase(context) {
96
107
  return {
97
108
  format: format.register(context),
98
109
  getFoldingRanges: foldingRanges.register(context),
@@ -130,5 +141,4 @@ function createLanguageService(context) {
130
141
  context,
131
142
  };
132
143
  }
133
- exports.createLanguageService = createLanguageService;
134
144
  //# sourceMappingURL=baseLanguageService.js.map
@@ -1,16 +1,14 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
2
  exports.register = void 0;
3
3
  const featureWorkers_1 = require("../utils/featureWorkers");
4
- const transforms_1 = require("@volar/transforms");
4
+ const transformer = require("../transformer");
5
5
  const vscode = require("vscode-languageserver-protocol");
6
6
  function register(context) {
7
7
  return (uri) => {
8
- return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, // TODO: add color capabilitie setting
9
- (plugin, document) => { var _a; return (_a = plugin.findDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => map ? (0, transforms_1.transformSymbolInformations)(data, location => {
8
+ return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => { var _a; return (_a = plugin.findDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => map ? transformer.asSymbolInformations(data, location => {
10
9
  const range = map.toSourceRange(location.range);
11
10
  if (range) {
12
- // use document.uri instead of map.sourceDocument.uri to fix https://github.com/johnsoncodehk/volar/issues/1925
13
- return vscode.Location.create(uri, range);
11
+ return vscode.Location.create(map.sourceFileDocument.uri, range);
14
12
  }
15
13
  }) : data, arr => arr.flat());
16
14
  };
@@ -1,10 +1,10 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
2
  exports.register = void 0;
3
3
  const featureWorkers_1 = require("../utils/featureWorkers");
4
- const transforms_1 = require("@volar/transforms");
4
+ const transformer = require("../transformer");
5
5
  function register(context) {
6
6
  return (uri) => {
7
- return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.foldingRange, (plugin, document) => { var _a; return (_a = plugin.getFoldingRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => map ? (0, transforms_1.transformFoldingRanges)(data, range => map.toSourceRange(range)) : data, arr => arr.flat());
7
+ return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.foldingRange, (plugin, document) => { var _a; return (_a = plugin.getFoldingRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => map ? transformer.asFoldingRanges(data, range => map.toSourceRange(range)) : data, arr => arr.flat());
8
8
  };
9
9
  }
10
10
  exports.register = register;
@@ -26,8 +26,8 @@ function register(context) {
26
26
  ? yield tryFormat(document, onTypeParams.position, undefined, onTypeParams.ch)
27
27
  : yield tryFormat(document, range, undefined);
28
28
  }
29
- const originalSnapshot = source[0];
30
- const rootVirtualFile = source[1];
29
+ const originalSnapshot = source.snapshot;
30
+ const rootVirtualFile = source.root;
31
31
  const originalDocument = document;
32
32
  const initialIndentLanguageId = (_b = yield ((_a = context.env.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.format.initialIndent'))) !== null && _b !== void 0 ? _b : { html: true };
33
33
  let level = 0;
@@ -90,7 +90,7 @@ function register(context) {
90
90
  if (edits.length > 0) {
91
91
  const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
92
92
  document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
93
- context.core.virtualFiles.update(shared.getPathOfUri(document.uri), (0, common_1.stringToSnapshot)(document.getText()));
93
+ context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
94
94
  edited = true;
95
95
  }
96
96
  if (toPatchIndent) {
@@ -99,7 +99,7 @@ function register(context) {
99
99
  if (indentEdits.length > 0) {
100
100
  const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
101
101
  document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
102
- context.core.virtualFiles.update(shared.getPathOfUri(document.uri), (0, common_1.stringToSnapshot)(document.getText()));
102
+ context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
103
103
  edited = true;
104
104
  }
105
105
  }
@@ -107,7 +107,7 @@ function register(context) {
107
107
  }
108
108
  if (edited) {
109
109
  // recover
110
- context.core.virtualFiles.update(shared.getPathOfUri(document.uri), originalSnapshot);
110
+ context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), originalSnapshot, undefined);
111
111
  }
112
112
  if (document.getText() === originalDocument.getText())
113
113
  return;
@@ -155,11 +155,11 @@ function register(context) {
155
155
  }
156
156
  }
157
157
  }
158
- for (const plugin of context.plugins) {
158
+ for (const plugin of Object.values(context.plugins)) {
159
159
  let edits;
160
160
  let recover;
161
161
  if (formatDocument !== document && isTsDocument(formatDocument) && context.typescript) {
162
- const formatFileName = shared.getPathOfUri(formatDocument.uri);
162
+ const formatFileName = shared.uriToFileName(formatDocument.uri);
163
163
  const formatSnapshot = (0, common_1.stringToSnapshot)(formatDocument.getText());
164
164
  const host = context.typescript.languageServiceHost;
165
165
  const original = {
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
2
  exports.register = void 0;
3
3
  const featureWorkers_1 = require("../utils/featureWorkers");
4
- const transforms_1 = require("@volar/transforms");
4
+ const transformer = require("../transformer");
5
5
  const shared = require("@volar/shared");
6
6
  function register(context) {
7
7
  return (uri, positions) => {
@@ -15,7 +15,7 @@ function register(context) {
15
15
  }
16
16
  }
17
17
  return [];
18
- }, (plugin, document, positions) => { var _a; return (_a = plugin.getSelectionRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, positions); }, (item, map) => map ? (0, transforms_1.transformSelectionRanges)(item, range => map.toSourceRange(range)) : item, results => {
18
+ }, (plugin, document, positions) => { var _a; return (_a = plugin.getSelectionRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, positions); }, (item, map) => map ? transformer.asSelectionRanges(item, range => map.toSourceRange(range)) : item, results => {
19
19
  for (let i = 0; i < results[0].length; i++) {
20
20
  const first = results[0][i];
21
21
  let lastParent = first;
@@ -30,9 +30,9 @@ export declare class MirrorMapWithDocument extends SourceMapWithDocuments<[Mirro
30
30
  findMirrorPositions(start: vscode.Position): Generator<readonly [import("vscode-languageserver-textdocument").Position, MirrorBehaviorCapabilities], void, unknown>;
31
31
  }
32
32
  export declare function createDocumentsAndSourceMaps(mapper: VirtualFiles): {
33
- getSourceByUri(sourceFileUri: string): readonly [ts.IScriptSnapshot, VirtualFile] | undefined;
34
- getRootFileBySourceFileUri(sourceFileUri: string): VirtualFile | undefined;
35
- getVirtualFileByUri(virtualFileUri: string): VirtualFile | undefined;
33
+ getSourceByUri(sourceFileUri: string): import("@volar/language-core").Source | undefined;
34
+ hasVirtualFileByUri(virtualFileUri: string): boolean;
35
+ getVirtualFileByUri(virtualFileUri: string): readonly [VirtualFile, import("@volar/language-core").Source] | readonly [undefined, undefined];
36
36
  getMirrorMapByUri(virtualFileUri: string): [VirtualFile, MirrorMapWithDocument] | undefined;
37
37
  getMapsBySourceFileUri(uri: string): {
38
38
  snapshot: ts.IScriptSnapshot;
package/out/documents.js CHANGED
@@ -123,24 +123,17 @@ function createDocumentsAndSourceMaps(mapper) {
123
123
  const _documents = new WeakMap();
124
124
  return {
125
125
  getSourceByUri(sourceFileUri) {
126
- const fileName = shared.getPathOfUri(sourceFileUri);
127
- return mapper.get(fileName);
126
+ return mapper.getSource(shared.uriToFileName(sourceFileUri));
128
127
  },
129
- getRootFileBySourceFileUri(sourceFileUri) {
130
- const fileName = shared.getPathOfUri(sourceFileUri);
131
- const rootFile = mapper.get(fileName);
132
- if (rootFile) {
133
- return rootFile[1];
134
- }
128
+ hasVirtualFileByUri(virtualFileUri) {
129
+ return mapper.hasVirtualFile(shared.uriToFileName(virtualFileUri));
135
130
  },
136
131
  getVirtualFileByUri(virtualFileUri) {
137
- var _a;
138
- return (_a = mapper.getSourceByVirtualFileName(shared.getPathOfUri(virtualFileUri))) === null || _a === void 0 ? void 0 : _a[2];
132
+ return mapper.getVirtualFile(shared.uriToFileName(virtualFileUri));
139
133
  },
140
134
  getMirrorMapByUri(virtualFileUri) {
141
- var _a;
142
- const fileName = shared.getPathOfUri(virtualFileUri);
143
- const virtualFile = (_a = mapper.getSourceByVirtualFileName(fileName)) === null || _a === void 0 ? void 0 : _a[2];
135
+ const fileName = shared.uriToFileName(virtualFileUri);
136
+ const [virtualFile] = mapper.getVirtualFile(fileName);
144
137
  if (virtualFile) {
145
138
  const map = mapper.getMirrorMap(virtualFile);
146
139
  if (map) {
@@ -152,19 +145,19 @@ function createDocumentsAndSourceMaps(mapper) {
152
145
  }
153
146
  },
154
147
  getMapsBySourceFileUri(uri) {
155
- return this.getMapsBySourceFileName(shared.getPathOfUri(uri));
148
+ return this.getMapsBySourceFileName(shared.uriToFileName(uri));
156
149
  },
157
150
  getMapsBySourceFileName(fileName) {
158
- const source = mapper.get(fileName);
151
+ const source = mapper.getSource(fileName);
159
152
  if (source) {
160
153
  const result = [];
161
- (0, language_core_1.forEachEmbeddedFile)(source[1], (embedded) => {
154
+ (0, language_core_1.forEachEmbeddedFile)(source.root, (embedded) => {
162
155
  for (const [sourceFileName, map] of mapper.getMaps(embedded)) {
163
156
  if (sourceFileName === fileName) {
164
157
  if (!_maps.has(map)) {
165
158
  _maps.set(map, [
166
159
  embedded,
167
- new SourceMapWithDocuments(getDocumentByFileName(source[0], sourceFileName), getDocumentByFileName(embedded.snapshot, fileName), map)
160
+ new SourceMapWithDocuments(getDocumentByFileName(source.snapshot, sourceFileName), getDocumentByFileName(embedded.snapshot, fileName), map)
168
161
  ]);
169
162
  }
170
163
  if (_maps.has(map)) {
@@ -174,21 +167,21 @@ function createDocumentsAndSourceMaps(mapper) {
174
167
  }
175
168
  });
176
169
  return {
177
- snapshot: source[0],
170
+ snapshot: source.snapshot,
178
171
  maps: result,
179
172
  };
180
173
  }
181
174
  },
182
175
  getMapsByVirtualFileUri(virtualFileUri) {
183
- return this.getMapsByVirtualFileName(shared.getPathOfUri(virtualFileUri));
176
+ return this.getMapsByVirtualFileName(shared.uriToFileName(virtualFileUri));
184
177
  },
185
178
  *getMapsByVirtualFileName(virtualFileName) {
186
- var _a, _b;
187
- const virtualFile = (_a = mapper.getSourceByVirtualFileName(virtualFileName)) === null || _a === void 0 ? void 0 : _a[2];
179
+ var _a;
180
+ const [virtualFile] = mapper.getVirtualFile(virtualFileName);
188
181
  if (virtualFile) {
189
182
  for (const [sourceFileName, map] of mapper.getMaps(virtualFile)) {
190
183
  if (!_maps.has(map)) {
191
- const sourceSnapshot = (_b = mapper.get(sourceFileName)) === null || _b === void 0 ? void 0 : _b[0];
184
+ const sourceSnapshot = (_a = mapper.getSource(sourceFileName)) === null || _a === void 0 ? void 0 : _a.snapshot;
192
185
  if (sourceSnapshot) {
193
186
  _maps.set(map, [virtualFile, new SourceMapWithDocuments(getDocumentByFileName(sourceSnapshot, sourceFileName), getDocumentByFileName(virtualFile.snapshot, virtualFileName), map)]);
194
187
  }
@@ -200,7 +193,7 @@ function createDocumentsAndSourceMaps(mapper) {
200
193
  }
201
194
  },
202
195
  getDocumentByUri(snapshot, uri) {
203
- return this.getDocumentByFileName(snapshot, shared.getPathOfUri(uri));
196
+ return this.getDocumentByFileName(snapshot, shared.uriToFileName(uri));
204
197
  },
205
198
  getDocumentByFileName,
206
199
  };
@@ -210,7 +203,7 @@ function createDocumentsAndSourceMaps(mapper) {
210
203
  }
211
204
  const map = _documents.get(snapshot);
212
205
  if (!map.has(fileName)) {
213
- map.set(fileName, vscode_languageserver_textdocument_1.TextDocument.create(shared.getUriByPath(fileName), shared.syntaxToLanguageId(fileName.substring(fileName.lastIndexOf('.') + 1)), version++, snapshot.getText(0, snapshot.getLength())));
206
+ map.set(fileName, vscode_languageserver_textdocument_1.TextDocument.create(shared.fileNameToUri(fileName), shared.syntaxToLanguageId(fileName.substring(fileName.lastIndexOf('.') + 1)), version++, snapshot.getText(0, snapshot.getLength())));
214
207
  }
215
208
  return map.get(fileName);
216
209
  }
package/out/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export * from './documents';
4
4
  export { executePluginCommand, ExecutePluginCommandArgs } from './languageFeatures/executeCommand';
5
5
  export { mergeWorkspaceEdits } from './languageFeatures/rename';
6
6
  export * from './types';
7
+ export * as transformer from './transformer';
package/out/index.js CHANGED
@@ -13,7 +13,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
13
13
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.mergeWorkspaceEdits = exports.executePluginCommand = void 0;
16
+ exports.transformer = exports.mergeWorkspaceEdits = exports.executePluginCommand = void 0;
17
17
  __exportStar(require("@volar/language-core"), exports);
18
18
  __exportStar(require("./baseLanguageService"), exports);
19
19
  __exportStar(require("./documents"), exports);
@@ -22,4 +22,5 @@ Object.defineProperty(exports, "executePluginCommand", { enumerable: true, get:
22
22
  var rename_1 = require("./languageFeatures/rename");
23
23
  Object.defineProperty(exports, "mergeWorkspaceEdits", { enumerable: true, get: function () { return rename_1.mergeWorkspaceEdits; } });
24
24
  __exportStar(require("./types"), exports);
25
+ exports.transformer = require("./transformer");
25
26
  //# sourceMappingURL=index.js.map
@@ -2,8 +2,8 @@ import type * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServiceRuntimeContext } from '../types';
3
3
  export interface PluginCallHierarchyData {
4
4
  uri: string;
5
- originalItem: vscode.CallHierarchyItem;
6
- pluginId: number;
5
+ originalData: any;
6
+ pluginId: string;
7
7
  map: {
8
8
  embeddedDocumentUri: string;
9
9
  } | undefined;
@@ -19,16 +19,17 @@ function register(context) {
19
19
  return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), (plugin, document, position, map) => __awaiter(this, void 0, void 0, function* () {
20
20
  var _a;
21
21
  const items = yield ((_a = plugin.callHierarchy) === null || _a === void 0 ? void 0 : _a.prepare(document, position));
22
- return items === null || items === void 0 ? void 0 : items.map(item => {
23
- return Object.assign(Object.assign({}, item), { data: {
24
- uri,
25
- originalItem: item,
26
- pluginId: context.plugins.indexOf(plugin),
27
- map: map ? {
28
- embeddedDocumentUri: map.virtualFileDocument.uri,
29
- } : undefined,
30
- } });
22
+ items === null || items === void 0 ? void 0 : items.forEach(item => {
23
+ item.data = {
24
+ uri,
25
+ originalData: item.data,
26
+ pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
27
+ map: map ? {
28
+ embeddedDocumentUri: map.virtualFileDocument.uri,
29
+ } : undefined,
30
+ };
31
31
  });
32
+ return items;
32
33
  }), (data, sourceMap) => !sourceMap ? data : data
33
34
  .map(item => { var _a; return (_a = transformCallHierarchyItem(item, [])) === null || _a === void 0 ? void 0 : _a[0]; })
34
35
  .filter(shared.notEmpty), arr => dedupe.withLocations(arr.flat()));
@@ -39,14 +40,12 @@ function register(context) {
39
40
  let incomingItems = [];
40
41
  if (data) {
41
42
  const plugin = context.plugins[data.pluginId];
42
- if (!plugin)
43
- return incomingItems;
44
43
  if (!plugin.callHierarchy)
45
44
  return incomingItems;
46
- const originalItem = data.originalItem;
45
+ item.data = data.originalData;
47
46
  if (data.map) {
48
- if (context.documents.getVirtualFileByUri(data.map.embeddedDocumentUri)) {
49
- const _calls = yield plugin.callHierarchy.onIncomingCalls(originalItem);
47
+ if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
48
+ const _calls = yield plugin.callHierarchy.onIncomingCalls(item);
50
49
  for (const _call of _calls) {
51
50
  const calls = transformCallHierarchyItem(_call.from, _call.fromRanges);
52
51
  if (!calls)
@@ -80,14 +79,12 @@ function register(context) {
80
79
  let items = [];
81
80
  if (data) {
82
81
  const plugin = context.plugins[data.pluginId];
83
- if (!plugin)
84
- return items;
85
82
  if (!plugin.callHierarchy)
86
83
  return items;
87
- const originalItem = data.originalItem;
84
+ item.data = data.originalData;
88
85
  if (data.map) {
89
- if (context.documents.getVirtualFileByUri(data.map.embeddedDocumentUri)) {
90
- const _calls = yield plugin.callHierarchy.onOutgoingCalls(originalItem);
86
+ if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
87
+ const _calls = yield plugin.callHierarchy.onOutgoingCalls(item);
91
88
  for (const call of _calls) {
92
89
  const calls = transformCallHierarchyItem(call.to, call.fromRanges);
93
90
  if (!calls)
@@ -117,7 +114,7 @@ function register(context) {
117
114
  },
118
115
  };
119
116
  function transformCallHierarchyItem(tsItem, tsRanges) {
120
- if (!context.documents.getVirtualFileByUri(tsItem.uri))
117
+ if (!context.documents.hasVirtualFileByUri(tsItem.uri))
121
118
  return [tsItem, tsRanges];
122
119
  for (const [_, map] of context.documents.getMapsByVirtualFileUri(tsItem.uri)) {
123
120
  let range = map.toSourceRange(tsItem.range);
@@ -132,7 +129,7 @@ function register(context) {
132
129
  if (!selectionRange)
133
130
  continue;
134
131
  const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(shared.notEmpty);
135
- const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === path_1.posix.basename(shared.getPathOfUri(map.virtualFileDocument.uri)) ? path_1.posix.basename(shared.getPathOfUri(map.sourceFileDocument.uri)) : tsItem.name, uri: map.sourceFileDocument.uri,
132
+ const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === path_1.posix.basename(shared.uriToFileName(map.virtualFileDocument.uri)) ? path_1.posix.basename(shared.uriToFileName(map.sourceFileDocument.uri)) : tsItem.name, uri: map.sourceFileDocument.uri,
136
133
  // TS Bug: `range: range` not works
137
134
  range: {
138
135
  start: range.start,
@@ -16,14 +16,12 @@ function register(context) {
16
16
  const data = item.data;
17
17
  if (data) {
18
18
  const plugin = context.plugins[data.pluginId];
19
- if (!plugin)
20
- return item;
21
19
  if (!((_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.resolve))
22
20
  return item;
23
- const originalItem = data.originalItem;
21
+ item.data = data.originalData;
24
22
  if (data.map) {
25
- if (context.documents.getVirtualFileByUri(data.map.embeddedDocumentUri)) {
26
- const resolvedItem = yield ((_b = plugin.codeAction) === null || _b === void 0 ? void 0 : _b.resolve(originalItem));
23
+ if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
24
+ const resolvedItem = yield ((_b = plugin.codeAction) === null || _b === void 0 ? void 0 : _b.resolve(item));
27
25
  if (resolvedItem.edit) {
28
26
  const edit = (0, rename_1.embeddedEditToSourceEdit)(resolvedItem.edit, context.documents);
29
27
  if (edit) {
@@ -34,7 +32,7 @@ function register(context) {
34
32
  }
35
33
  }
36
34
  else {
37
- return yield ((_c = plugin.codeAction) === null || _c === void 0 ? void 0 : _c.resolve(originalItem));
35
+ return yield ((_c = plugin.codeAction) === null || _c === void 0 ? void 0 : _c.resolve(item));
38
36
  }
39
37
  }
40
38
  return item;
@@ -2,8 +2,8 @@ import * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServiceRuntimeContext } from '../types';
3
3
  export interface PluginCodeActionData {
4
4
  uri: string;
5
- originalItem: vscode.CodeAction;
6
- pluginId: number;
5
+ originalData: any;
6
+ pluginId: string;
7
7
  map: {
8
8
  embeddedDocumentUri: string;
9
9
  } | undefined;
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
12
  const shared = require("@volar/shared");
13
- const transforms_1 = require("@volar/transforms");
13
+ const transformer = require("../transformer");
14
14
  const vscode = require("vscode-languageserver-protocol");
15
15
  const common_1 = require("../utils/common");
16
16
  const dedupe = require("../utils/dedupe");
@@ -30,7 +30,7 @@ function register(context) {
30
30
  if (!file.capabilities.codeAction)
31
31
  return [];
32
32
  const _codeActionContext = {
33
- diagnostics: (0, transforms_1.transformLocations)(codeActionContext.diagnostics, range => map.toGeneratedRange(range)),
33
+ diagnostics: transformer.asLocations(codeActionContext.diagnostics, range => map.toGeneratedRange(range)),
34
34
  only: codeActionContext.only,
35
35
  };
36
36
  let minStart;
@@ -53,14 +53,22 @@ function register(context) {
53
53
  }];
54
54
  }
55
55
  return [];
56
- }, (plugin, document, arg, map) => __awaiter(this, void 0, void 0, function* () {
56
+ }, (plugin, document, { range, codeActionContext }, map) => __awaiter(this, void 0, void 0, function* () {
57
57
  var _a, _b;
58
- const codeActions = yield ((_b = (_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.on) === null || _b === void 0 ? void 0 : _b.call(_a, document, arg.range, arg.codeActionContext));
58
+ const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
59
+ const diagnostics = codeActionContext.diagnostics.filter(diagnostic => {
60
+ const data = diagnostic.data;
61
+ return (data === null || data === void 0 ? void 0 : data.type) === 'plugin' && (data === null || data === void 0 ? void 0 : data.pluginOrRuleId) === pluginId;
62
+ }).map(diagnostic => {
63
+ const data = diagnostic.data;
64
+ return Object.assign(Object.assign({}, diagnostic), { data: data.originalData });
65
+ });
66
+ const codeActions = yield ((_b = (_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.on) === null || _b === void 0 ? void 0 : _b.call(_a, document, range, Object.assign(Object.assign({}, codeActionContext), { diagnostics })));
59
67
  return codeActions === null || codeActions === void 0 ? void 0 : codeActions.map(_codeAction => {
60
68
  return Object.assign(Object.assign({}, _codeAction), { data: {
61
69
  uri,
62
- originalItem: _codeAction,
63
- pluginId: context.plugins.indexOf(plugin),
70
+ originalData: _codeAction.data,
71
+ pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
64
72
  map: map ? {
65
73
  embeddedDocumentUri: map.virtualFileDocument.uri,
66
74
  } : undefined,
@@ -81,7 +89,6 @@ function register(context) {
81
89
  }
82
90
  }).filter(shared.notEmpty), arr => arr.flat());
83
91
  if (codeActions) {
84
- codeActions = codeActions.filter(codeAction => codeAction.title.indexOf('__VLS_') === -1);
85
92
  return dedupe.withCodeAction(codeActions);
86
93
  }
87
94
  });
@@ -1,8 +1,8 @@
1
- import * as vscode from 'vscode-languageserver-protocol';
2
1
  import type { LanguageServiceRuntimeContext } from '../types';
2
+ import type * as _ from 'vscode-languageserver-protocol';
3
3
  export interface PluginCodeLensData {
4
4
  uri: string;
5
- originalItem: vscode.CodeLens;
6
- pluginId: number;
5
+ originalData: any;
6
+ pluginId: string;
7
7
  }
8
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string) => Promise<vscode.CodeLens[]>;
8
+ export declare function register(context: LanguageServiceRuntimeContext): (uri: string) => Promise<_.CodeLens[]>;
@@ -18,16 +18,22 @@ function register(context) {
18
18
  return (_a = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], (plugin, document) => __awaiter(this, void 0, void 0, function* () {
19
19
  var _b, _c;
20
20
  const codeLens = yield ((_c = (_b = plugin.codeLens) === null || _b === void 0 ? void 0 : _b.on) === null || _c === void 0 ? void 0 : _c.call(_b, document));
21
- if (codeLens) {
22
- return codeLens.map(item => {
23
- const commandArgs = item.command ? [uri, context.plugins.indexOf(plugin), item.command] : undefined;
24
- return Object.assign(Object.assign({}, item), { command: item.command && commandArgs ? Object.assign(Object.assign({}, item.command), { command: executeCommand_1.executePluginCommand, arguments: commandArgs }) : undefined, data: {
25
- uri,
26
- originalItem: item,
27
- pluginId: context.plugins.indexOf(plugin),
28
- } });
29
- });
30
- }
21
+ codeLens === null || codeLens === void 0 ? void 0 : codeLens.forEach(codeLens => {
22
+ const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
23
+ if (codeLens.command) {
24
+ codeLens.command = {
25
+ title: codeLens.command.title,
26
+ command: executeCommand_1.executePluginCommand,
27
+ arguments: [uri, pluginId, codeLens.command],
28
+ };
29
+ }
30
+ codeLens.data = {
31
+ uri,
32
+ originalData: codeLens.data,
33
+ pluginId,
34
+ };
35
+ });
36
+ return codeLens;
31
37
  }), (data, map) => data.map(codeLens => {
32
38
  if (!map)
33
39
  return codeLens;
@@ -16,12 +16,18 @@ function register(context) {
16
16
  const data = item.data;
17
17
  if (data) {
18
18
  const plugin = context.plugins[data.pluginId];
19
- if (!plugin)
20
- return item;
21
19
  if (!((_a = plugin.codeLens) === null || _a === void 0 ? void 0 : _a.resolve))
22
20
  return item;
23
- const resolvedOriginalItem = yield plugin.codeLens.resolve(data.originalItem);
24
- item = Object.assign(Object.assign({}, resolvedOriginalItem), { command: resolvedOriginalItem.command ? Object.assign(Object.assign({}, resolvedOriginalItem.command), { command: executeCommand_1.executePluginCommand, arguments: [data.uri, context.plugins.indexOf(plugin), resolvedOriginalItem.command] }) : undefined, range: item.range });
21
+ item.data = data.originalData;
22
+ item = yield plugin.codeLens.resolve(item);
23
+ if (item.command) {
24
+ item.command = {
25
+ title: item.command.title,
26
+ command: executeCommand_1.executePluginCommand,
27
+ arguments: [data.uri, data.pluginId, item.command],
28
+ };
29
+ }
30
+ // item.range already transformed in codeLens request
25
31
  }
26
32
  return item;
27
33
  });