@volar/language-service 1.0.24 → 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 (31) hide show
  1. package/out/baseLanguageService.d.ts +3 -11
  2. package/out/baseLanguageService.js +33 -23
  3. package/out/documentFeatures/documentSymbols.js +2 -4
  4. package/out/documentFeatures/format.js +4 -4
  5. package/out/languageFeatures/callHierarchy.d.ts +2 -2
  6. package/out/languageFeatures/callHierarchy.js +14 -17
  7. package/out/languageFeatures/codeActionResolve.js +3 -5
  8. package/out/languageFeatures/codeActions.d.ts +2 -2
  9. package/out/languageFeatures/codeActions.js +12 -4
  10. package/out/languageFeatures/codeLens.d.ts +4 -4
  11. package/out/languageFeatures/codeLens.js +16 -10
  12. package/out/languageFeatures/codeLensResolve.js +10 -4
  13. package/out/languageFeatures/complete.d.ts +2 -2
  14. package/out/languageFeatures/complete.js +23 -20
  15. package/out/languageFeatures/completeResolve.js +3 -5
  16. package/out/languageFeatures/executeCommand.d.ts +1 -1
  17. package/out/languageFeatures/executeCommand.js +1 -1
  18. package/out/languageFeatures/fileRename.js +2 -2
  19. package/out/languageFeatures/renamePrepare.js +1 -6
  20. package/out/languageFeatures/validation copy.d.ts +7 -0
  21. package/out/languageFeatures/validation copy.js +234 -0
  22. package/out/languageFeatures/validation.d.ts +6 -0
  23. package/out/languageFeatures/validation.js +116 -39
  24. package/out/languageFeatures/workspaceSymbols.js +1 -1
  25. package/out/types.d.ts +37 -6
  26. package/out/types.js +0 -1
  27. package/out/utils/common.d.ts +0 -2
  28. package/out/utils/common.js +1 -28
  29. package/out/utils/featureWorkers.d.ts +2 -1
  30. package/out/utils/featureWorkers.js +87 -5
  31. package/package.json +7 -7
@@ -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,
@@ -78,7 +90,7 @@ function createLanguageServiceContext(options) {
78
90
  function getTextDocument(uri) {
79
91
  var _a;
80
92
  const fileName = shared.uriToFileName(uri);
81
- const scriptSnapshot = options.host.getScriptSnapshot(fileName);
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
@@ -5,12 +5,10 @@ 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 ? transformer.asSymbolInformations(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
  };
@@ -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.updateSource(shared.uriToFileName(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.updateSource(shared.uriToFileName(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.updateSource(shared.uriToFileName(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,7 +155,7 @@ 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) {
@@ -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
47
  if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
49
- const _calls = yield plugin.callHierarchy.onIncomingCalls(originalItem);
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
86
  if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
90
- const _calls = yield plugin.callHierarchy.onOutgoingCalls(originalItem);
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)
@@ -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
23
  if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) {
26
- const resolvedItem = yield ((_b = plugin.codeAction) === null || _b === void 0 ? void 0 : _b.resolve(originalItem));
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;
@@ -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,
@@ -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
  });
@@ -2,8 +2,8 @@ import * as vscode from 'vscode-languageserver-protocol';
2
2
  import type { LanguageServiceRuntimeContext } from '../types';
3
3
  export interface PluginCompletionData {
4
4
  uri: string;
5
- originalItem: vscode.CompletionItem;
6
- pluginId: number;
5
+ originalData: any;
6
+ pluginId: string;
7
7
  map: {
8
8
  embeddedDocumentUri: string;
9
9
  } | undefined;
@@ -34,8 +34,8 @@ function register(context) {
34
34
  }
35
35
  cacheData.list = transformer.asCompletionList(embeddedCompletionList, range => map.toSourceRange(range), map.virtualFileDocument, (newItem, oldItem) => newItem.data = {
36
36
  uri,
37
- originalItem: oldItem,
38
- pluginId: context.plugins.indexOf(cacheData.plugin),
37
+ originalData: oldItem.data,
38
+ pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === cacheData.plugin),
39
39
  map: {
40
40
  embeddedDocumentUri: map.virtualFileDocument.uri,
41
41
  },
@@ -51,12 +51,14 @@ function register(context) {
51
51
  cacheData.list.isIncomplete = false;
52
52
  continue;
53
53
  }
54
- cacheData.list = Object.assign(Object.assign({}, completionList), { items: completionList.items.map(item => (Object.assign(Object.assign({}, item), { data: {
55
- uri,
56
- originalItem: item,
57
- pluginId: context.plugins.indexOf(cacheData.plugin),
58
- map: undefined,
59
- } }))) });
54
+ completionList.items.forEach(item => {
55
+ item.data = {
56
+ uri,
57
+ originalData: item.data,
58
+ pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === cacheData.plugin),
59
+ map: undefined,
60
+ };
61
+ });
60
62
  }
61
63
  }
62
64
  }
@@ -72,7 +74,7 @@ function register(context) {
72
74
  if (rootFile) {
73
75
  yield (0, definePlugin_1.visitEmbedded)(context.documents, rootFile, (_, map) => __awaiter(this, void 0, void 0, function* () {
74
76
  var _f, _g;
75
- const plugins = context.plugins.sort(sortPlugins);
77
+ const plugins = Object.values(context.plugins).sort(sortPlugins);
76
78
  let _data;
77
79
  for (const mapped of map.toGeneratedPositions(position, data => {
78
80
  _data = data;
@@ -102,8 +104,8 @@ function register(context) {
102
104
  }
103
105
  const completionList = transformer.asCompletionList(embeddedCompletionList, range => map.toSourceRange(range), map.virtualFileDocument, (newItem, oldItem) => newItem.data = {
104
106
  uri,
105
- originalItem: oldItem,
106
- pluginId: context.plugins.indexOf(plugin),
107
+ originalData: oldItem.data,
108
+ pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
107
109
  map: {
108
110
  embeddedDocumentUri: map.virtualFileDocument.uri,
109
111
  }
@@ -122,7 +124,7 @@ function register(context) {
122
124
  }));
123
125
  }
124
126
  if (document = context.getTextDocument(uri)) {
125
- const plugins = context.plugins.sort(sortPlugins);
127
+ const plugins = Object.values(context.plugins).sort(sortPlugins);
126
128
  for (const plugin of plugins) {
127
129
  if (!((_d = plugin.complete) === null || _d === void 0 ? void 0 : _d.on))
128
130
  continue;
@@ -141,17 +143,18 @@ function register(context) {
141
143
  if (!plugin.complete.isAdditional) {
142
144
  cache.mainCompletion = { documentUri: document.uri };
143
145
  }
146
+ completionList.items.forEach(item => {
147
+ item.data = {
148
+ uri,
149
+ originalData: item.data,
150
+ pluginId: Object.keys(context.plugins).find(key => context.plugins[key] === plugin),
151
+ map: undefined,
152
+ };
153
+ });
144
154
  cache.data.push({
145
155
  map: undefined,
146
156
  plugin,
147
- list: Object.assign(Object.assign({}, completionList), { items: completionList.items.map(item => {
148
- return Object.assign(Object.assign({}, item), { data: {
149
- uri,
150
- originalItem: item,
151
- pluginId: context.plugins.indexOf(plugin),
152
- sourceMap: undefined,
153
- } });
154
- }) }),
157
+ list: completionList,
155
158
  });
156
159
  }
157
160
  }
@@ -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.complete) === 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
23
  for (const [_, map] of context.documents.getMapsByVirtualFileUri(data.map.embeddedDocumentUri)) {
26
- const resolvedItem = yield plugin.complete.resolve(originalItem);
24
+ const resolvedItem = yield plugin.complete.resolve(item);
27
25
  // fix https://github.com/johnsoncodehk/volar/issues/916
28
26
  if (resolvedItem.additionalTextEdits) {
29
27
  for (const edit of resolvedItem.additionalTextEdits) {
@@ -45,7 +43,7 @@ function register(context) {
45
43
  }
46
44
  }
47
45
  else {
48
- item = yield plugin.complete.resolve(originalItem);
46
+ item = yield plugin.complete.resolve(item);
49
47
  }
50
48
  }
51
49
  // TODO: monkey fix import ts file icon
@@ -5,7 +5,7 @@ export declare const executePluginCommand: string;
5
5
  export type ExecutePluginCommandArgs = [
6
6
  string,
7
7
  // uri
8
- number | undefined,
8
+ string | undefined,
9
9
  vscode.Command
10
10
  ];
11
11
  export declare function register(context: LanguageServiceRuntimeContext): (command: string, args: ExecutePluginCommandArgs, executeCommandContext: ExecuteCommandContext) => Promise<void>;
@@ -21,7 +21,7 @@ function register(context) {
21
21
  yield ((_a = plugin === null || plugin === void 0 ? void 0 : plugin.doExecuteCommand) === null || _a === void 0 ? void 0 : _a.call(plugin, originalCommand.command, originalCommand.arguments, executeCommandContext));
22
22
  }
23
23
  else {
24
- for (const plugin of context.plugins) {
24
+ for (const plugin of Object.values(context.plugins)) {
25
25
  yield ((_b = plugin.doExecuteCommand) === null || _b === void 0 ? void 0 : _b.call(plugin, originalCommand.command, originalCommand.arguments, executeCommandContext));
26
26
  }
27
27
  }
@@ -19,7 +19,7 @@ function register(context) {
19
19
  if (rootFile) {
20
20
  let tsExt;
21
21
  (0, language_core_1.forEachEmbeddedFile)(rootFile, embedded => {
22
- if (embedded.kind && embedded.fileName.replace(rootFile.fileName, '').match(/^\.(js|ts)x?$/)) {
22
+ if (embedded.kind === language_core_1.FileKind.TypeScriptHostFile && embedded.fileName.replace(rootFile.fileName, '').match(/^\.(js|ts)x?$/)) {
23
23
  tsExt = embedded.fileName.substring(embedded.fileName.lastIndexOf('.'));
24
24
  }
25
25
  });
@@ -29,7 +29,7 @@ function register(context) {
29
29
  oldUri += tsExt;
30
30
  newUri += tsExt;
31
31
  }
32
- for (const plugin of context.plugins) {
32
+ for (const plugin of Object.values(context.plugins)) {
33
33
  if (!plugin.doFileRename)
34
34
  continue;
35
35
  const workspaceEdit = yield plugin.doFileRename(oldUri, newUri);
@@ -10,14 +10,10 @@ 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 vscode = require("vscode-languageserver-protocol");
13
- const common_1 = require("../utils/common");
14
13
  const featureWorkers_1 = require("../utils/featureWorkers");
15
- // https://github.com/microsoft/vscode/blob/dcf27391b7dd7c1cece483806af75b4f87188e70/extensions/html/language-configuration.json#L35
16
- const htmlWordPatterns = /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\\"\,\.\<\>\/\s]+)/g;
17
14
  function register(context) {
18
15
  return (uri, position) => __awaiter(this, void 0, void 0, function* () {
19
- const document = context.getTextDocument(uri);
20
- const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.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, map) => {
16
+ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.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, map) => {
21
17
  if (!map) {
22
18
  return item;
23
19
  }
@@ -32,7 +28,6 @@ function register(context) {
32
28
  }
33
29
  return prepares[0];
34
30
  });
35
- return result !== null && result !== void 0 ? result : (document ? (0, common_1.getWordRange)(htmlWordPatterns, position, document) : undefined);
36
31
  });
37
32
  }
38
33
  exports.register = register;
@@ -0,0 +1,7 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ import type { LanguageServiceRuntimeContext } from '../types';
3
+ export declare function updateRange(range: vscode.Range, change: {
4
+ range: vscode.Range;
5
+ newEnd: vscode.Position;
6
+ }): vscode.Range | undefined;
7
+ export declare function register(context: LanguageServiceRuntimeContext): (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;