@volar/language-service 1.2.0-alpha.7 → 1.2.0-alpha.9

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 (49) hide show
  1. package/out/baseLanguageService.d.ts +3 -5
  2. package/out/baseLanguageService.js +6 -9
  3. package/out/documentFeatures/colorPresentations.d.ts +2 -2
  4. package/out/documentFeatures/documentColors.d.ts +2 -2
  5. package/out/documentFeatures/documentSymbols.d.ts +2 -2
  6. package/out/documentFeatures/foldingRanges.d.ts +2 -2
  7. package/out/documentFeatures/format.d.ts +2 -4
  8. package/out/documentFeatures/format.js +26 -123
  9. package/out/documentFeatures/linkedEditingRanges.d.ts +2 -2
  10. package/out/documentFeatures/selectionRanges.d.ts +2 -2
  11. package/out/index.d.ts +1 -1
  12. package/out/index.js +3 -3
  13. package/out/languageFeatures/autoInsert.d.ts +2 -2
  14. package/out/languageFeatures/callHierarchy.d.ts +2 -2
  15. package/out/languageFeatures/codeActionResolve.d.ts +2 -2
  16. package/out/languageFeatures/codeActionResolve.js +9 -3
  17. package/out/languageFeatures/codeActions.d.ts +5 -2
  18. package/out/languageFeatures/codeActions.js +17 -6
  19. package/out/languageFeatures/codeLens.d.ts +11 -4
  20. package/out/languageFeatures/codeLens.js +22 -14
  21. package/out/languageFeatures/codeLensResolve.d.ts +4 -2
  22. package/out/languageFeatures/codeLensResolve.js +19 -11
  23. package/out/languageFeatures/complete.d.ts +2 -2
  24. package/out/languageFeatures/completeResolve.d.ts +2 -2
  25. package/out/languageFeatures/definition.d.ts +2 -2
  26. package/out/languageFeatures/documentHighlights.d.ts +2 -2
  27. package/out/languageFeatures/documentLinks.d.ts +2 -2
  28. package/out/languageFeatures/documentSemanticTokens.d.ts +2 -2
  29. package/out/languageFeatures/executeCommand.d.ts +1 -2
  30. package/out/languageFeatures/executeCommand.js +1 -9
  31. package/out/languageFeatures/fileReferences.d.ts +2 -2
  32. package/out/languageFeatures/fileRename.d.ts +2 -2
  33. package/out/languageFeatures/fileRename.js +1 -1
  34. package/out/languageFeatures/hover.d.ts +2 -2
  35. package/out/languageFeatures/inlayHints.d.ts +2 -2
  36. package/out/languageFeatures/references.d.ts +2 -2
  37. package/out/languageFeatures/rename.d.ts +3 -3
  38. package/out/languageFeatures/rename.js +64 -44
  39. package/out/languageFeatures/renamePrepare.d.ts +2 -2
  40. package/out/languageFeatures/signatureHelp.d.ts +2 -2
  41. package/out/languageFeatures/validation.d.ts +4 -2
  42. package/out/languageFeatures/validation.js +41 -8
  43. package/out/languageFeatures/workspaceSymbols.d.ts +2 -2
  44. package/out/transformer/foldingRanges.js +6 -6
  45. package/out/types.d.ts +60 -34
  46. package/out/types.js +0 -1
  47. package/out/utils/featureWorkers.d.ts +4 -4
  48. package/out/utils/featureWorkers.js +17 -13
  49. package/package.json +6 -6
@@ -11,23 +11,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
12
  const shared = require("@volar/shared");
13
13
  const featureWorkers_1 = require("../utils/featureWorkers");
14
- const executeCommand_1 = require("./executeCommand");
14
+ const vscode = require("vscode-languageserver-protocol");
15
15
  function register(context) {
16
16
  return (uri) => __awaiter(this, void 0, void 0, function* () {
17
- var _a;
18
- return (_a = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], (plugin, document) => __awaiter(this, void 0, void 0, function* () {
19
- var _b, _c;
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));
17
+ var _a, _b, _c;
18
+ const referencesCodeLendsEnabled = (_b = yield ((_a = context.env.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.codeLens.references'))) !== null && _b !== void 0 ? _b : true;
19
+ return (_c = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], (plugin, document) => __awaiter(this, void 0, void 0, function* () {
20
+ var _d, _e, _f, _g;
21
+ let codeLens = yield ((_e = (_d = plugin.codeLens) === null || _d === void 0 ? void 0 : _d.on) === null || _e === void 0 ? void 0 : _e.call(_d, document));
22
+ const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin);
21
23
  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
24
  codeLens.data = {
25
+ kind: 'normal',
31
26
  uri,
32
27
  original: {
33
28
  data: codeLens.data,
@@ -35,6 +30,19 @@ function register(context) {
35
30
  pluginId,
36
31
  };
37
32
  });
33
+ if (referencesCodeLendsEnabled) {
34
+ const referencesCodeLensLocs = yield ((_g = (_f = plugin.referencesCodeLens) === null || _f === void 0 ? void 0 : _f.on) === null || _g === void 0 ? void 0 : _g.call(_f, document));
35
+ const referencesCodeLens = referencesCodeLensLocs === null || referencesCodeLensLocs === void 0 ? void 0 : referencesCodeLensLocs.map(loc => vscode.CodeLens.create(loc.range, {
36
+ kind: 'references',
37
+ uri,
38
+ location: loc,
39
+ pluginId,
40
+ }));
41
+ codeLens = [
42
+ ...codeLens !== null && codeLens !== void 0 ? codeLens : [],
43
+ ...referencesCodeLens !== null && referencesCodeLens !== void 0 ? referencesCodeLens : [],
44
+ ];
45
+ }
38
46
  return codeLens;
39
47
  }), (data, map) => data.map(codeLens => {
40
48
  if (!map)
@@ -43,7 +51,7 @@ function register(context) {
43
51
  if (range) {
44
52
  return Object.assign(Object.assign({}, codeLens), { range });
45
53
  }
46
- }).filter(shared.notEmpty), arr => arr.flat())) !== null && _a !== void 0 ? _a : [];
54
+ }).filter(shared.notEmpty), arr => arr.flat())) !== null && _c !== void 0 ? _c : [];
47
55
  });
48
56
  }
49
57
  exports.register = register;
@@ -1,3 +1,5 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare const showReferencesCommand: string;
4
+ export type ShowReferencesCommandData = [string, vscode.Position, vscode.Location[]];
5
+ export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeLens) => Promise<vscode.CodeLens>;
@@ -8,27 +8,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.register = void 0;
12
- const executeCommand_1 = require("./executeCommand");
11
+ exports.register = exports.showReferencesCommand = void 0;
12
+ const references = require("./references");
13
+ exports.showReferencesCommand = `volar.${Math.random().toString(36).slice(2)}.show-references`;
13
14
  function register(context) {
15
+ const findReferences = references.register(context);
14
16
  return (item) => __awaiter(this, void 0, void 0, function* () {
15
- var _a;
17
+ var _a, _b, _c;
16
18
  const data = item.data;
17
- if (data) {
19
+ if ((data === null || data === void 0 ? void 0 : data.kind) === 'normal') {
18
20
  const plugin = context.plugins[data.pluginId];
19
21
  if (!((_a = plugin.codeLens) === null || _a === void 0 ? void 0 : _a.resolve))
20
22
  return item;
21
23
  Object.assign(item, data.original);
22
24
  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
25
  // item.range already transformed in codeLens request
31
26
  }
27
+ if ((data === null || data === void 0 ? void 0 : data.kind) === 'references') {
28
+ let references = (_b = yield findReferences(data.uri, item.range.start)) !== null && _b !== void 0 ? _b : [];
29
+ const plugin = context.plugins[data.pluginId];
30
+ const document = context.getTextDocument(data.uri);
31
+ if (document && ((_c = plugin.referencesCodeLens) === null || _c === void 0 ? void 0 : _c.resolve)) {
32
+ references = yield plugin.referencesCodeLens.resolve(document, data.location, references);
33
+ }
34
+ item.command = {
35
+ title: references.length === 1 ? '1 reference' : `${references.length} references`,
36
+ command: exports.showReferencesCommand,
37
+ arguments: [data.uri, data.location.range.start, references],
38
+ };
39
+ }
32
40
  return item;
33
41
  });
34
42
  }
@@ -1,5 +1,5 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
2
+ import type { LanguageServicePluginContext } from '../types';
3
3
  export interface PluginCompletionData {
4
4
  uri: string;
5
5
  original: Pick<vscode.CompletionItem, 'additionalTextEdits' | 'textEdit' | 'data'>;
@@ -8,4 +8,4 @@ export interface PluginCompletionData {
8
8
  embeddedDocumentUri: string;
9
9
  } | undefined;
10
10
  }
11
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext) => Promise<vscode.CompletionList>;
11
+ export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext) => Promise<vscode.CompletionList>;
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (item: vscode.CompletionItem) => Promise<vscode.CompletionItem>;
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (item: vscode.CompletionItem) => Promise<vscode.CompletionItem>;
@@ -1,4 +1,4 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
2
+ import type { LanguageServicePluginContext } from '../types';
3
3
  import { FileRangeCapabilities, MirrorBehaviorCapabilities } from '@volar/language-core';
4
- export declare function register(context: LanguageServiceRuntimeContext, api: 'findDefinition' | 'findTypeDefinition' | 'findImplementations', isValidMapping: (data: FileRangeCapabilities) => boolean, isValidMirrorPosition: (mirrorData: MirrorBehaviorCapabilities) => boolean): (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
4
+ export declare function register(context: LanguageServicePluginContext, api: 'findDefinition' | 'findTypeDefinition' | 'findImplementations', isValidMapping: (data: FileRangeCapabilities) => boolean, isValidMirrorPosition: (mirrorData: MirrorBehaviorCapabilities) => boolean): (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>;
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position) => Promise<vscode.DocumentHighlight[] | undefined>;
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<vscode.DocumentHighlight[] | undefined>;
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string) => Promise<vscode.DocumentLink[]>;
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.DocumentLink[]>;
@@ -1,4 +1,4 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
2
  import { SemanticToken } from '@volar/language-service';
3
- import type { LanguageServiceRuntimeContext } from '../types';
4
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, range: vscode.Range | undefined, legend: vscode.SemanticTokensLegend, cancelToken: vscode.CancellationToken, reportProgress?: ((tokens: SemanticToken[]) => void) | undefined) => Promise<SemanticToken[] | undefined> | undefined;
3
+ import type { LanguageServicePluginContext } from '../types';
4
+ export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range | undefined, legend: vscode.SemanticTokensLegend, cancelToken: vscode.CancellationToken, reportProgress?: ((tokens: SemanticToken[]) => void) | undefined) => Promise<SemanticToken[] | undefined> | undefined;
@@ -4,8 +4,7 @@ import * as vscode from 'vscode-languageserver-protocol';
4
4
  export declare const executePluginCommand: string;
5
5
  export type ExecutePluginCommandArgs = [
6
6
  string,
7
- // uri
8
- string | undefined,
7
+ string,
9
8
  vscode.Command
10
9
  ];
11
10
  export declare function register(context: LanguageServiceRuntimeContext): (command: string, args: ExecutePluginCommandArgs, executeCommandContext: ExecuteCommandContext) => Promise<void>;
@@ -16,15 +16,7 @@ function register(context) {
16
16
  var _a, _b;
17
17
  if (command === exports.executePluginCommand) {
18
18
  const [_uri, pluginId, originalCommand] = args;
19
- if (pluginId !== undefined) {
20
- const plugin = context.plugins[pluginId];
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
- }
23
- else {
24
- for (const plugin of Object.values(context.plugins)) {
25
- yield ((_b = plugin.doExecuteCommand) === null || _b === void 0 ? void 0 : _b.call(plugin, originalCommand.command, originalCommand.arguments, executeCommandContext));
26
- }
27
- }
19
+ yield ((_b = (_a = context.plugins[pluginId]) === null || _a === void 0 ? void 0 : _a.doExecuteCommand) === null || _b === void 0 ? void 0 : _b.call(_a, originalCommand.command, originalCommand.arguments, executeCommandContext));
28
20
  }
29
21
  });
30
22
  }
@@ -1,4 +1,4 @@
1
- import type { LanguageServiceRuntimeContext } from '../types';
1
+ import type { LanguageServicePluginContext } from '../types';
2
2
  import * as vscode from 'vscode-languageserver-protocol';
3
3
  import { NullableResult } from '@volar/language-service';
4
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string) => NullableResult<vscode.Location[]>;
4
+ export declare function register(context: LanguageServicePluginContext): (uri: string) => NullableResult<vscode.Location[]>;
@@ -1,3 +1,3 @@
1
- import type { LanguageServiceRuntimeContext } from '../types';
1
+ import type { LanguageServicePluginContext } from '../types';
2
2
  import type * as _ from 'vscode-languageserver-protocol';
3
- export declare function register(context: LanguageServiceRuntimeContext): (oldUri: string, newUri: string) => Promise<_.WorkspaceEdit | undefined>;
3
+ export declare function register(context: LanguageServicePluginContext): (oldUri: string, newUri: string) => Promise<_.WorkspaceEdit | undefined>;
@@ -34,7 +34,7 @@ function register(context) {
34
34
  continue;
35
35
  const workspaceEdit = yield plugin.doFileRename(oldUri, newUri);
36
36
  if (workspaceEdit) {
37
- const result = (0, rename_1.embeddedEditToSourceEdit)(workspaceEdit, context.documents);
37
+ const result = (0, rename_1.embeddedEditToSourceEdit)(workspaceEdit, context.documents, 'fileName');
38
38
  if (result === null || result === void 0 ? void 0 : result.documentChanges) {
39
39
  result.documentChanges = dedupe.withDocumentChanges(result.documentChanges);
40
40
  }
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position) => Promise<vscode.Hover | undefined>;
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<vscode.Hover | undefined>;
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, range: vscode.Range) => Promise<vscode.InlayHint[] | undefined>;
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range) => Promise<vscode.InlayHint[] | undefined>;
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position) => Promise<vscode.Location[] | undefined>;
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<vscode.Location[] | undefined>;
@@ -1,6 +1,6 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
2
+ import type { LanguageServicePluginContext } from '../types';
3
3
  import { DocumentsAndSourceMaps } from '../documents';
4
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
4
+ export declare function register(context: LanguageServicePluginContext): (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
- export declare function embeddedEditToSourceEdit(tsResult: vscode.WorkspaceEdit, vueDocuments: DocumentsAndSourceMaps): vscode.WorkspaceEdit | undefined;
6
+ export declare function embeddedEditToSourceEdit(tsResult: vscode.WorkspaceEdit, documents: DocumentsAndSourceMaps, mode: 'fileName' | 'rename' | 'codeAction' | 'format', versions?: Record<string, number>): vscode.WorkspaceEdit | undefined;
@@ -87,7 +87,7 @@ function register(context) {
87
87
  });
88
88
  }
89
89
  }), (data) => {
90
- return embeddedEditToSourceEdit(data, context.documents);
90
+ return embeddedEditToSourceEdit(data, context.documents, 'rename');
91
91
  }, (workspaceEdits) => {
92
92
  const mainEdit = workspaceEdits[0];
93
93
  const otherEdits = workspaceEdits.slice(1);
@@ -131,18 +131,19 @@ function mergeWorkspaceEdits(original, ...others) {
131
131
  }
132
132
  }
133
133
  exports.mergeWorkspaceEdits = mergeWorkspaceEdits;
134
- function embeddedEditToSourceEdit(tsResult, vueDocuments) {
135
- var _a, _b, _c;
134
+ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
135
+ var _a, _b, _c, _d, _e, _f;
136
+ var _g, _h, _j, _k;
136
137
  const sourceResult = {};
137
138
  let hasResult = false;
138
139
  for (const tsUri in tsResult.changeAnnotations) {
139
140
  (_a = sourceResult.changeAnnotations) !== null && _a !== void 0 ? _a : (sourceResult.changeAnnotations = {});
140
141
  const tsAnno = tsResult.changeAnnotations[tsUri];
141
- if (!vueDocuments.hasVirtualFileByUri(tsUri)) {
142
+ if (!documents.hasVirtualFileByUri(tsUri)) {
142
143
  sourceResult.changeAnnotations[tsUri] = tsAnno;
143
144
  }
144
145
  else {
145
- for (const [_, map] of vueDocuments.getMapsByVirtualFileUri(tsUri)) {
146
+ for (const [_, map] of documents.getMapsByVirtualFileUri(tsUri)) {
146
147
  // TODO: check capability?
147
148
  const uri = map.sourceFileDocument.uri;
148
149
  sourceResult.changeAnnotations[uri] = tsAnno;
@@ -151,62 +152,81 @@ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
151
152
  }
152
153
  for (const tsUri in tsResult.changes) {
153
154
  (_b = sourceResult.changes) !== null && _b !== void 0 ? _b : (sourceResult.changes = {});
154
- if (!vueDocuments.hasVirtualFileByUri(tsUri)) {
155
+ if (!documents.hasVirtualFileByUri(tsUri)) {
155
156
  sourceResult.changes[tsUri] = tsResult.changes[tsUri];
156
157
  hasResult = true;
157
158
  continue;
158
159
  }
159
- for (const [_, map] of vueDocuments.getMapsByVirtualFileUri(tsUri)) {
160
+ for (const [_, map] of documents.getMapsByVirtualFileUri(tsUri)) {
160
161
  const tsEdits = tsResult.changes[tsUri];
161
162
  for (const tsEdit of tsEdits) {
162
- let _data;
163
- const range = map.toSourceRange(tsEdit.range, data => {
164
- _data = data;
165
- return typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename;
166
- });
167
- if (range) {
168
- let newText = tsEdit.newText;
169
- if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
170
- newText = _data.rename.apply(tsEdit.newText);
163
+ if (mode === 'rename') {
164
+ let _data;
165
+ const range = map.toSourceRange(tsEdit.range, data => {
166
+ _data = data;
167
+ return typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename;
168
+ });
169
+ if (range) {
170
+ let newText = tsEdit.newText;
171
+ if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
172
+ newText = _data.rename.apply(tsEdit.newText);
173
+ }
174
+ (_c = (_g = sourceResult.changes)[_h = map.sourceFileDocument.uri]) !== null && _c !== void 0 ? _c : (_g[_h] = []);
175
+ sourceResult.changes[map.sourceFileDocument.uri].push({ newText, range });
176
+ hasResult = true;
171
177
  }
172
- if (!sourceResult.changes[map.sourceFileDocument.uri]) {
173
- sourceResult.changes[map.sourceFileDocument.uri] = [];
178
+ }
179
+ else {
180
+ const range = map.toSourceRange(tsEdit.range);
181
+ if (range) {
182
+ (_d = (_j = sourceResult.changes)[_k = map.sourceFileDocument.uri]) !== null && _d !== void 0 ? _d : (_j[_k] = []);
183
+ sourceResult.changes[map.sourceFileDocument.uri].push({ newText: tsEdit.newText, range });
184
+ hasResult = true;
174
185
  }
175
- sourceResult.changes[map.sourceFileDocument.uri].push({ newText, range });
176
- hasResult = true;
177
186
  }
178
187
  }
179
188
  }
180
189
  }
181
190
  if (tsResult.documentChanges) {
182
191
  for (const tsDocEdit of tsResult.documentChanges) {
183
- (_c = sourceResult.documentChanges) !== null && _c !== void 0 ? _c : (sourceResult.documentChanges = []);
192
+ (_e = sourceResult.documentChanges) !== null && _e !== void 0 ? _e : (sourceResult.documentChanges = []);
184
193
  let sourceEdit;
185
194
  if (vscode.TextDocumentEdit.is(tsDocEdit)) {
186
- if (vueDocuments.hasVirtualFileByUri(tsDocEdit.textDocument.uri)) {
187
- for (const [_, map] of vueDocuments.getMapsByVirtualFileUri(tsDocEdit.textDocument.uri)) {
195
+ if (documents.hasVirtualFileByUri(tsDocEdit.textDocument.uri)) {
196
+ for (const [_, map] of documents.getMapsByVirtualFileUri(tsDocEdit.textDocument.uri)) {
188
197
  sourceEdit = vscode.TextDocumentEdit.create({
189
198
  uri: map.sourceFileDocument.uri,
190
- // version: map.sourceDocument.version,
191
- version: null, // fix https://github.com/johnsoncodehk/volar/issues/1490
199
+ version: (_f = versions[map.sourceFileDocument.uri]) !== null && _f !== void 0 ? _f : null,
192
200
  }, []);
193
201
  for (const tsEdit of tsDocEdit.edits) {
194
- let _data;
195
- const range = map.toSourceRange(tsEdit.range, data => {
196
- _data = data;
197
- // fix https://github.com/johnsoncodehk/volar/issues/1091
198
- return typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename;
199
- });
200
- if (range) {
201
- let newText = tsEdit.newText;
202
- if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
203
- newText = _data.rename.apply(tsEdit.newText);
204
- }
205
- sourceEdit.edits.push({
206
- annotationId: vscode.AnnotatedTextEdit.is(tsEdit.range) ? tsEdit.range.annotationId : undefined,
207
- newText,
208
- range,
202
+ if (mode === 'rename') {
203
+ let _data;
204
+ const range = map.toSourceRange(tsEdit.range, data => {
205
+ _data = data;
206
+ // fix https://github.com/johnsoncodehk/volar/issues/1091
207
+ return typeof data.rename === 'object' ? !!data.rename.apply : !!data.rename;
209
208
  });
209
+ if (range) {
210
+ let newText = tsEdit.newText;
211
+ if (_data && typeof _data.rename === 'object' && _data.rename.apply) {
212
+ newText = _data.rename.apply(tsEdit.newText);
213
+ }
214
+ sourceEdit.edits.push({
215
+ annotationId: vscode.AnnotatedTextEdit.is(tsEdit.range) ? tsEdit.range.annotationId : undefined,
216
+ newText,
217
+ range,
218
+ });
219
+ }
220
+ }
221
+ else {
222
+ const range = map.toSourceRange(tsEdit.range);
223
+ if (range) {
224
+ sourceEdit.edits.push({
225
+ annotationId: vscode.AnnotatedTextEdit.is(tsEdit.range) ? tsEdit.range.annotationId : undefined,
226
+ newText: tsEdit.newText,
227
+ range,
228
+ });
229
+ }
210
230
  }
211
231
  }
212
232
  if (!sourceEdit.edits.length) {
@@ -222,22 +242,22 @@ function embeddedEditToSourceEdit(tsResult, vueDocuments) {
222
242
  sourceEdit = tsDocEdit; // TODO: remove .ts?
223
243
  }
224
244
  else if (vscode.RenameFile.is(tsDocEdit)) {
225
- if (!vueDocuments.hasVirtualFileByUri(tsDocEdit.oldUri)) {
245
+ if (!documents.hasVirtualFileByUri(tsDocEdit.oldUri)) {
226
246
  sourceEdit = tsDocEdit;
227
247
  }
228
248
  else {
229
- for (const [_, map] of vueDocuments.getMapsByVirtualFileUri(tsDocEdit.oldUri)) {
249
+ for (const [_, map] of documents.getMapsByVirtualFileUri(tsDocEdit.oldUri)) {
230
250
  // TODO: check capability?
231
251
  sourceEdit = vscode.RenameFile.create(map.sourceFileDocument.uri, tsDocEdit.newUri /* TODO: remove .ts? */, tsDocEdit.options, tsDocEdit.annotationId);
232
252
  }
233
253
  }
234
254
  }
235
255
  else if (vscode.DeleteFile.is(tsDocEdit)) {
236
- if (!vueDocuments.hasVirtualFileByUri(tsDocEdit.uri)) {
256
+ if (!documents.hasVirtualFileByUri(tsDocEdit.uri)) {
237
257
  sourceEdit = tsDocEdit;
238
258
  }
239
259
  else {
240
- for (const [_, map] of vueDocuments.getMapsByVirtualFileUri(tsDocEdit.uri)) {
260
+ for (const [_, map] of documents.getMapsByVirtualFileUri(tsDocEdit.uri)) {
241
261
  // TODO: check capability?
242
262
  sourceEdit = vscode.DeleteFile.create(map.sourceFileDocument.uri, tsDocEdit.options, tsDocEdit.annotationId);
243
263
  }
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>;
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>;
@@ -1,3 +1,3 @@
1
1
  import type * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext) => Promise<vscode.SignatureHelp | undefined>;
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext) => Promise<vscode.SignatureHelp | undefined>;
@@ -1,15 +1,17 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
2
+ import type { LanguageServicePluginContext } from '../types';
3
3
  export declare function updateRange(range: vscode.Range, change: {
4
4
  range: vscode.Range;
5
5
  newEnd: vscode.Position;
6
6
  }): vscode.Range | undefined;
7
7
  export interface PluginDiagnosticData {
8
8
  uri: string;
9
+ version: number;
9
10
  original: Pick<vscode.Diagnostic, 'data'>;
10
11
  type: 'plugin' | 'rule';
12
+ isFormat: boolean;
11
13
  pluginOrRuleId: string;
12
14
  ruleFixIndex: number;
13
15
  documentUri: string;
14
16
  }
15
- export declare function register(context: LanguageServiceRuntimeContext): (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
17
+ export declare function register(context: LanguageServicePluginContext): (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>;
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = exports.updateRange = void 0;
12
12
  const shared = require("@volar/shared");
13
+ const vscode = require("vscode-languageserver-protocol");
13
14
  const dedupe = require("../utils/dedupe");
14
15
  const featureWorkers_1 = require("../utils/featureWorkers");
15
16
  function updateRange(range, change) {
@@ -97,6 +98,10 @@ function register(context) {
97
98
  };
98
99
  return (uri, token, response) => __awaiter(this, void 0, void 0, function* () {
99
100
  var _a;
101
+ const newDocument = context.getTextDocument(uri);
102
+ if (!newDocument) {
103
+ return [];
104
+ }
100
105
  const lastResponse = (_a = lastResponses.get(uri)) !== null && _a !== void 0 ? _a : lastResponses.set(uri, {
101
106
  semantic: { errors: [] },
102
107
  declaration: { errors: [] },
@@ -107,7 +112,6 @@ function register(context) {
107
112
  format_rules: { errors: [] },
108
113
  }).get(uri);
109
114
  const newSnapshot = context.host.getScriptSnapshot(shared.uriToFileName(uri));
110
- const newDocument = context.getTextDocument(uri);
111
115
  let updateCacheRangeFailed = false;
112
116
  let errorsUpdated = false;
113
117
  let lastCheckCancelAt = 0;
@@ -185,18 +189,27 @@ function register(context) {
185
189
  }
186
190
  const reportResults = [];
187
191
  ruleCtx.report = (error, ...fixes) => {
192
+ var _a, _b;
193
+ if (!vscode.Diagnostic.is(error)) {
194
+ console.warn('[volar/rules-api] report() error must be a Diagnostic.');
195
+ return;
196
+ }
197
+ error.message || (error.message = 'No message.');
188
198
  error.source || (error.source = 'rules');
189
199
  error.code || (error.code = ruleCtx.ruleId);
200
+ const severity = (_b = (_a = context.config.lint) === null || _a === void 0 ? void 0 : _a.severities) === null || _b === void 0 ? void 0 : _b[ruleCtx.ruleId];
201
+ if (severity !== undefined) {
202
+ error.severity = severity;
203
+ }
190
204
  reportResults.push([error, ...fixes]);
191
205
  };
192
- if (typeof rule === 'function') {
193
- if (api === 'onSyntax') {
194
- yield rule(ruleCtx);
195
- }
196
- }
197
- else {
206
+ try {
198
207
  yield ((_d = rule[api]) === null || _d === void 0 ? void 0 : _d.call(rule, ruleCtx));
199
208
  }
209
+ catch (err) {
210
+ console.warn(`[volar/rules-api] ${ruleName} ${api} error.`);
211
+ console.warn(err);
212
+ }
200
213
  (_e = context.ruleFixes) !== null && _e !== void 0 ? _e : (context.ruleFixes = {});
201
214
  (_f = (_h = context.ruleFixes)[_j = ruleCtx.document.uri]) !== null && _f !== void 0 ? _f : (_h[_j] = {});
202
215
  (_g = (_k = context.ruleFixes[ruleCtx.document.uri])[_l = ruleCtx.ruleId]) !== null && _g !== void 0 ? _g : (_k[_l] = {});
@@ -204,7 +217,9 @@ function register(context) {
204
217
  context.ruleFixes[ruleCtx.document.uri][ruleCtx.ruleId][index] = [error, fixes];
205
218
  error.data = {
206
219
  uri,
220
+ version: newDocument.version,
207
221
  type: 'rule',
222
+ isFormat: api === 'onFormat',
208
223
  pluginOrRuleId: ruleCtx.ruleId,
209
224
  original: {
210
225
  data: error.data,
@@ -221,7 +236,7 @@ function register(context) {
221
236
  tsProjectVersion,
222
237
  });
223
238
  return errors;
224
- }), transformErrorRange, arr => arr.flat());
239
+ }), api === 'onFormat' ? transformFormatErrorRange : transformErrorRange, arr => arr.flat());
225
240
  if (result) {
226
241
  cache.errors = result;
227
242
  cache.snapshot = newSnapshot;
@@ -263,8 +278,10 @@ function register(context) {
263
278
  errors === null || errors === void 0 ? void 0 : errors.forEach(error => {
264
279
  error.data = {
265
280
  uri,
281
+ version: newDocument.version,
266
282
  type: 'plugin',
267
283
  pluginOrRuleId: pluginId,
284
+ isFormat: false,
268
285
  original: {
269
286
  data: error.data,
270
287
  },
@@ -287,6 +304,22 @@ function register(context) {
287
304
  });
288
305
  }
289
306
  });
307
+ function transformFormatErrorRange(errors, map) {
308
+ const result = [];
309
+ for (const error of errors) {
310
+ // clone it to avoid modify cache
311
+ let _error = Object.assign({}, error);
312
+ if (map) {
313
+ const range = map.toSourceRange(error.range);
314
+ if (!range) {
315
+ continue;
316
+ }
317
+ _error.range = range;
318
+ }
319
+ result.push(_error);
320
+ }
321
+ return result;
322
+ }
290
323
  function transformErrorRange(errors, map) {
291
324
  const result = [];
292
325
  for (const error of errors) {
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
- import type { LanguageServiceRuntimeContext } from '../types';
3
- export declare function register(context: LanguageServiceRuntimeContext): (query: string) => Promise<vscode.SymbolInformation[]>;
2
+ import type { LanguageServicePluginContext } from '../types';
3
+ export declare function register(context: LanguageServicePluginContext): (query: string) => Promise<vscode.SymbolInformation[]>;
@@ -4,17 +4,17 @@ function transform(ranges, getOtherRange) {
4
4
  var _a, _b;
5
5
  const result = [];
6
6
  for (const range of ranges) {
7
- const vueRange = getOtherRange({
7
+ const otherRange = getOtherRange({
8
8
  start: { line: range.startLine, character: (_a = range.startCharacter) !== null && _a !== void 0 ? _a : 0 },
9
9
  end: { line: range.endLine, character: (_b = range.endCharacter) !== null && _b !== void 0 ? _b : 0 },
10
10
  });
11
- if (vueRange) {
12
- range.startLine = vueRange.start.line;
13
- range.endLine = vueRange.end.line;
11
+ if (otherRange) {
12
+ range.startLine = otherRange.start.line;
13
+ range.endLine = otherRange.end.line;
14
14
  if (range.startCharacter !== undefined)
15
- range.startCharacter = vueRange.start.character;
15
+ range.startCharacter = otherRange.start.character;
16
16
  if (range.endCharacter !== undefined)
17
- range.endCharacter = vueRange.end.character;
17
+ range.endCharacter = otherRange.end.character;
18
18
  result.push(range);
19
19
  }
20
20
  }