@volar/language-service 1.2.0-alpha.8 → 1.3.0-alpha.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 (60) hide show
  1. package/out/baseLanguageService.d.ts +6 -7
  2. package/out/baseLanguageService.js +7 -10
  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/documentSymbols.js +34 -6
  7. package/out/documentFeatures/foldingRanges.d.ts +2 -2
  8. package/out/documentFeatures/format.d.ts +2 -4
  9. package/out/documentFeatures/format.js +113 -151
  10. package/out/documentFeatures/linkedEditingRanges.d.ts +2 -2
  11. package/out/documentFeatures/selectionRanges.d.ts +2 -2
  12. package/out/index.d.ts +1 -1
  13. package/out/index.js +3 -3
  14. package/out/languageFeatures/autoInsert.d.ts +2 -2
  15. package/out/languageFeatures/callHierarchy.d.ts +2 -2
  16. package/out/languageFeatures/codeActionResolve.d.ts +2 -2
  17. package/out/languageFeatures/codeActionResolve.js +9 -3
  18. package/out/languageFeatures/codeActions.d.ts +5 -2
  19. package/out/languageFeatures/codeActions.js +17 -6
  20. package/out/languageFeatures/codeLens.d.ts +11 -4
  21. package/out/languageFeatures/codeLens.js +22 -14
  22. package/out/languageFeatures/codeLensResolve.d.ts +4 -2
  23. package/out/languageFeatures/codeLensResolve.js +19 -11
  24. package/out/languageFeatures/complete.d.ts +2 -2
  25. package/out/languageFeatures/completeResolve.d.ts +2 -2
  26. package/out/languageFeatures/definition.d.ts +2 -2
  27. package/out/languageFeatures/documentHighlights.d.ts +2 -2
  28. package/out/languageFeatures/documentLinks.d.ts +2 -2
  29. package/out/languageFeatures/documentLinks.js +1 -1
  30. package/out/languageFeatures/documentSemanticTokens.d.ts +2 -2
  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/inlayHints.js +2 -3
  37. package/out/languageFeatures/references.d.ts +2 -2
  38. package/out/languageFeatures/rename.d.ts +3 -3
  39. package/out/languageFeatures/rename.js +54 -34
  40. package/out/languageFeatures/renamePrepare.d.ts +2 -2
  41. package/out/languageFeatures/renamePrepare.js +9 -13
  42. package/out/languageFeatures/signatureHelp.d.ts +2 -2
  43. package/out/languageFeatures/validation.d.ts +4 -2
  44. package/out/languageFeatures/validation.js +42 -9
  45. package/out/languageFeatures/workspaceSymbols.d.ts +2 -2
  46. package/out/languageFeatures/workspaceSymbols.js +3 -2
  47. package/out/transformer/documentSymbol.d.ts +2 -0
  48. package/out/transformer/documentSymbol.js +18 -0
  49. package/out/transformer/index.d.ts +2 -2
  50. package/out/transformer/index.js +5 -5
  51. package/out/transformer/workspaceSymbol.d.ts +2 -0
  52. package/out/transformer/workspaceSymbol.js +15 -0
  53. package/out/types.d.ts +65 -43
  54. package/out/utils/dedupe.d.ts +0 -1
  55. package/out/utils/dedupe.js +1 -13
  56. package/out/utils/featureWorkers.d.ts +4 -4
  57. package/out/utils/featureWorkers.js +27 -17
  58. package/package.json +9 -9
  59. package/out/languageFeatures/executeCommand.d.ts +0 -11
  60. package/out/languageFeatures/executeCommand.js +0 -32
@@ -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;
@@ -158,7 +162,7 @@ function register(context) {
158
162
  }
159
163
  function lintWorker(api, cacheMap, cache) {
160
164
  return __awaiter(this, void 0, void 0, function* () {
161
- const result = yield (0, featureWorkers_1.ruleWorker)(context, uri, file => api === 'onFormat' ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, (ruleName, rule, ruleCtx) => __awaiter(this, void 0, void 0, function* () {
165
+ const result = yield (0, featureWorkers_1.ruleWorker)(context, api, uri, file => api === 'onFormat' ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, (ruleName, rule, ruleCtx) => __awaiter(this, void 0, void 0, function* () {
162
166
  var _a, _b, _c, _d, _e, _f, _g;
163
167
  var _h, _j, _k, _l;
164
168
  if (token) {
@@ -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.WorkspaceSymbol[]>;
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
12
  const transformer = require("../transformer");
13
13
  const vscode = require("vscode-languageserver-protocol");
14
+ const shared = require("@volar/shared");
14
15
  function register(context) {
15
16
  return (query) => __awaiter(this, void 0, void 0, function* () {
16
17
  const symbolsList = [];
@@ -20,7 +21,7 @@ function register(context) {
20
21
  const embeddedSymbols = yield plugin.findWorkspaceSymbols(query);
21
22
  if (!embeddedSymbols)
22
23
  continue;
23
- const symbols = transformer.asSymbolInformations(embeddedSymbols, loc => {
24
+ const symbols = embeddedSymbols.map(symbol => transformer.asWorkspaceSymbol(symbol, loc => {
24
25
  if (context.documents.hasVirtualFileByUri(loc.uri)) {
25
26
  for (const [_, map] of context.documents.getMapsByVirtualFileUri(loc.uri)) {
26
27
  const range = map.toSourceRange(loc.range);
@@ -32,7 +33,7 @@ function register(context) {
32
33
  else {
33
34
  return loc;
34
35
  }
35
- });
36
+ })).filter(shared.notEmpty);
36
37
  symbolsList.push(symbols);
37
38
  }
38
39
  return symbolsList.flat();
@@ -0,0 +1,2 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ export declare function transform(symbol: vscode.DocumentSymbol, getOtherRange: (range: vscode.Range) => vscode.Range | undefined): vscode.DocumentSymbol | undefined;
@@ -0,0 +1,18 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.transform = void 0;
3
+ const shared = require("@volar/shared");
4
+ function transform(symbol, getOtherRange) {
5
+ var _a;
6
+ const range = getOtherRange(symbol.range);
7
+ if (!range) {
8
+ return;
9
+ }
10
+ const selectionRange = getOtherRange(symbol.selectionRange);
11
+ if (!selectionRange) {
12
+ return;
13
+ }
14
+ return Object.assign(Object.assign({}, symbol), { range,
15
+ selectionRange, children: (_a = symbol.children) === null || _a === void 0 ? void 0 : _a.map(child => transform(child, getOtherRange)).filter(shared.notEmpty) });
16
+ }
17
+ exports.transform = transform;
18
+ //# sourceMappingURL=documentSymbol.js.map
@@ -6,6 +6,6 @@ export { transform as asLocation } from './locationLike';
6
6
  export { transform as asLocations } from './locationsLike';
7
7
  export { transform as asSelectionRange } from './selectionRange';
8
8
  export { transform as asSelectionRanges } from './selectionRanges';
9
- export { transform as asSymbolInformation } from './symbolInformation';
10
- export { transform as asSymbolInformations } from './symbolInformations';
11
9
  export { transform as asTextEdit } from './textEdit';
10
+ export { transform as asDocumentSymbol } from './documentSymbol';
11
+ export { transform as asWorkspaceSymbol } from './workspaceSymbol';
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.asTextEdit = exports.asSymbolInformations = exports.asSymbolInformation = exports.asSelectionRanges = exports.asSelectionRange = exports.asLocations = exports.asLocation = exports.asHover = exports.asFoldingRanges = exports.asCompletionList = exports.asCompletionItem = void 0;
2
+ exports.asWorkspaceSymbol = exports.asDocumentSymbol = exports.asTextEdit = exports.asSelectionRanges = exports.asSelectionRange = exports.asLocations = exports.asLocation = exports.asHover = exports.asFoldingRanges = exports.asCompletionList = exports.asCompletionItem = void 0;
3
3
  var completionItem_1 = require("./completionItem");
4
4
  Object.defineProperty(exports, "asCompletionItem", { enumerable: true, get: function () { return completionItem_1.transform; } });
5
5
  var completionList_1 = require("./completionList");
@@ -16,10 +16,10 @@ var selectionRange_1 = require("./selectionRange");
16
16
  Object.defineProperty(exports, "asSelectionRange", { enumerable: true, get: function () { return selectionRange_1.transform; } });
17
17
  var selectionRanges_1 = require("./selectionRanges");
18
18
  Object.defineProperty(exports, "asSelectionRanges", { enumerable: true, get: function () { return selectionRanges_1.transform; } });
19
- var symbolInformation_1 = require("./symbolInformation");
20
- Object.defineProperty(exports, "asSymbolInformation", { enumerable: true, get: function () { return symbolInformation_1.transform; } });
21
- var symbolInformations_1 = require("./symbolInformations");
22
- Object.defineProperty(exports, "asSymbolInformations", { enumerable: true, get: function () { return symbolInformations_1.transform; } });
23
19
  var textEdit_1 = require("./textEdit");
24
20
  Object.defineProperty(exports, "asTextEdit", { enumerable: true, get: function () { return textEdit_1.transform; } });
21
+ var documentSymbol_1 = require("./documentSymbol");
22
+ Object.defineProperty(exports, "asDocumentSymbol", { enumerable: true, get: function () { return documentSymbol_1.transform; } });
23
+ var workspaceSymbol_1 = require("./workspaceSymbol");
24
+ Object.defineProperty(exports, "asWorkspaceSymbol", { enumerable: true, get: function () { return workspaceSymbol_1.transform; } });
25
25
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import * as vscode from 'vscode-languageserver-protocol';
2
+ export declare function transform(symbol: vscode.WorkspaceSymbol, getOtherLocation: (location: vscode.Location) => vscode.Location | undefined): vscode.WorkspaceSymbol | undefined;
@@ -0,0 +1,15 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.transform = void 0;
3
+ const vscode = require("vscode-languageserver-protocol");
4
+ function transform(symbol, getOtherLocation) {
5
+ if (!vscode.Location.is(symbol.location)) {
6
+ return symbol;
7
+ }
8
+ const loc = getOtherLocation(symbol.location);
9
+ if (!loc) {
10
+ return;
11
+ }
12
+ return Object.assign(Object.assign({}, symbol), { location: loc });
13
+ }
14
+ exports.transform = transform;
15
+ //# sourceMappingURL=workspaceSymbol.js.map
package/out/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { LanguageContext, LanguageModule, LanguageServiceHost } from '@volar/language-core';
2
- import { LanguageService } from '@volar/language-service';
3
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
4
3
  import type { DocumentContext, FileSystemProvider } from 'vscode-html-languageservice';
5
4
  import type { SchemaRequestService } from 'vscode-json-languageservice';
@@ -8,7 +7,8 @@ import type { TextDocument } from 'vscode-languageserver-textdocument';
8
7
  import { URI } from 'vscode-uri';
9
8
  import { DocumentsAndSourceMaps } from './documents';
10
9
  export * from 'vscode-languageserver-protocol';
11
- export interface LanguageServiceRuntimeContext<Host extends LanguageServiceHost = LanguageServiceHost> {
10
+ export interface LanguageServicePluginContext {
11
+ config: Config;
12
12
  typescript: {
13
13
  module: typeof import('typescript/lib/tsserverlibrary');
14
14
  languageServiceHost: ts.LanguageServiceHost;
@@ -18,14 +18,14 @@ export interface LanguageServiceRuntimeContext<Host extends LanguageServiceHost
18
18
  rootUri: URI;
19
19
  locale?: string;
20
20
  configurationHost?: ConfigurationHost;
21
- documentContext: DocumentContext;
21
+ documentContext?: DocumentContext;
22
22
  fileSystemProvider?: FileSystemProvider;
23
23
  schemaRequestService?: SchemaRequestService;
24
24
  };
25
25
  uriToFileName(uri: string): string;
26
26
  fileNameToUri(fileName: string): string;
27
27
  /** @private */
28
- host: Host;
28
+ host: LanguageServiceHost;
29
29
  /** @private */
30
30
  core: LanguageContext;
31
31
  /** @private */
@@ -35,12 +35,6 @@ export interface LanguageServiceRuntimeContext<Host extends LanguageServiceHost
35
35
  [id: string]: LanguageServicePluginInstance;
36
36
  };
37
37
  /** @private */
38
- rules: {
39
- [id: string]: Rule | undefined;
40
- };
41
- /** @private */
42
- rulesSettings: RulesSettings;
43
- /** @private */
44
38
  getTextDocument(uri: string): TextDocument | undefined;
45
39
  /** @private */
46
40
  ruleFixes?: {
@@ -61,28 +55,15 @@ export interface ConfigurationHost {
61
55
  export type NotNullableResult<T> = T | Thenable<T>;
62
56
  export type NullableResult<T> = NotNullableResult<T | undefined | null>;
63
57
  export type SemanticToken = [number, number, number, number, number];
64
- export interface ExecuteCommandContext {
65
- token: vscode.CancellationToken;
66
- workDoneProgress: {
67
- begin(title: string, percentage?: number, message?: string, cancellable?: boolean): void;
68
- report(percentage: number): void;
69
- report(message: string): void;
70
- report(percentage: number, message: string): void;
71
- done(): void;
72
- };
73
- showReferences(params: {
74
- textDocument: vscode.TextDocumentIdentifier;
75
- position: vscode.Position;
76
- references: vscode.Location[];
77
- }): Promise<void>;
78
- applyEdit(paramOrEdit: vscode.ApplyWorkspaceEditParams | vscode.WorkspaceEdit): Promise<vscode.ApplyWorkspaceEditResult>;
79
- }
80
58
  export interface LanguageServicePlugin<T = {}> {
81
- (context: LanguageServiceRuntimeContext, service: LanguageService): LanguageServicePluginInstance & T;
59
+ (context: LanguageServicePluginContext): LanguageServicePluginInstance & T;
82
60
  }
83
61
  export interface LanguageServicePluginInstance {
84
62
  rules?: {
85
- prepare?(context: RuleContext): NotNullableResult<RuleContext>;
63
+ onAny?(context: RuleContext): NotNullableResult<RuleContext>;
64
+ onFormat?(context: RuleContext): NotNullableResult<RuleContext>;
65
+ onSyntax?(context: RuleContext): NotNullableResult<RuleContext>;
66
+ onSemantic?(context: RuleContext): NotNullableResult<RuleContext>;
86
67
  };
87
68
  validation?: {
88
69
  onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
@@ -96,10 +77,9 @@ export interface LanguageServicePluginInstance {
96
77
  findFileReferences?(document: TextDocument): NullableResult<vscode.Location[]>;
97
78
  findDocumentHighlights?(document: TextDocument, position: vscode.Position): NullableResult<vscode.DocumentHighlight[]>;
98
79
  findDocumentLinks?(document: TextDocument): NullableResult<vscode.DocumentLink[]>;
99
- findDocumentSymbols?(document: TextDocument): NullableResult<vscode.SymbolInformation[]>;
80
+ findDocumentSymbols?(document: TextDocument): NullableResult<vscode.DocumentSymbol[]>;
100
81
  findDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend): NullableResult<SemanticToken[]>;
101
- findWorkspaceSymbols?(query: string): NullableResult<vscode.SymbolInformation[]>;
102
- doExecuteCommand?(command: string, args: any[] | undefined, context: ExecuteCommandContext): NotNullableResult<void>;
82
+ findWorkspaceSymbols?(query: string): NullableResult<vscode.WorkspaceSymbol[]>;
103
83
  findDocumentColors?(document: TextDocument): NullableResult<vscode.ColorInformation[]>;
104
84
  getColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range): NullableResult<vscode.ColorPresentation[]>;
105
85
  doFileRename?(oldUri: string, newUri: string): NullableResult<vscode.WorkspaceEdit>;
@@ -108,6 +88,7 @@ export interface LanguageServicePluginInstance {
108
88
  getSignatureHelp?(document: TextDocument, position: vscode.Position, context?: vscode.SignatureHelpContext): NullableResult<vscode.SignatureHelp>;
109
89
  format?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;
110
90
  formatOnType?(document: TextDocument, position: vscode.Position, key: string, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>;
91
+ getIndentSensitiveLines?(document: TextDocument): NullableResult<number[]>;
111
92
  definition?: {
112
93
  on?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
113
94
  onType?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>;
@@ -130,6 +111,10 @@ export interface LanguageServicePluginInstance {
130
111
  on?(document: TextDocument): NullableResult<vscode.CodeLens[]>;
131
112
  resolve?(codeLens: vscode.CodeLens): NotNullableResult<vscode.CodeLens>;
132
113
  };
114
+ referencesCodeLens?: {
115
+ on?(document: TextDocument): NullableResult<vscode.Location[]>;
116
+ resolve?(document: TextDocument, location: vscode.Location, references: vscode.Location[]): NotNullableResult<vscode.Location[]>;
117
+ };
133
118
  callHierarchy?: {
134
119
  prepare(document: TextDocument, position: vscode.Position): NullableResult<vscode.CallHierarchyItem[]>;
135
120
  onIncomingCalls(item: vscode.CallHierarchyItem): NotNullableResult<vscode.CallHierarchyIncomingCall[]>;
@@ -152,30 +137,62 @@ export interface LanguageServicePluginInstance {
152
137
  */
153
138
  resolveEmbeddedRange?(range: vscode.Range): vscode.Range | undefined;
154
139
  }
155
- export type Rule = _Rule | NonNullable<_Rule['onSyntax']>;
156
- export interface _Rule {
140
+ export interface Rule {
157
141
  onFormat?(ctx: RuleContext): void;
158
142
  onSyntax?(ctx: RuleContext): void;
159
143
  onSemantic?(ctx: RuleContext): void;
160
144
  }
161
145
  export interface RuleContext {
146
+ /**
147
+ * Shared modules.
148
+ */
149
+ modules: {
150
+ typescript?: typeof import('typescript/lib/tsserverlibrary');
151
+ };
152
+ /**
153
+ * IDE or user define locale.
154
+ * You can use it to localize your rule.
155
+ */
162
156
  locale?: string;
157
+ /**
158
+ * Project root path.
159
+ */
160
+ rootUri: URI;
163
161
  uriToFileName(uri: string): string;
164
162
  fileNameToUri(fileName: string): string;
165
- rootUri: URI;
166
- getConfiguration?: ConfigurationHost['getConfiguration'];
167
- onDidChangeConfiguration?: ConfigurationHost['onDidChangeConfiguration'];
168
- settings: RulesSettings;
163
+ /**
164
+ * Get configuration from IDE.
165
+ *
166
+ * For VSCode, it's .vscode/settings.json
167
+ */
168
+ getConfiguration?: <T>(section: string) => Promise<T | undefined>;
169
+ onDidChangeConfiguration?: (cb: () => void) => void;
170
+ /**
171
+ * Global settings from config.
172
+ */
173
+ settings: any;
169
174
  ruleId: string;
170
175
  document: TextDocument;
171
176
  report(error: vscode.Diagnostic, ...fixes: RuleFix[]): void;
172
177
  }
173
- export interface RulesSettings {
174
- }
175
178
  export interface RuleFix {
176
- kinds?: ('' | 'quickfix' | 'refactor' | 'refactor.extract' | 'refactor.inline' | 'refactor.rewrite' | 'source' | 'source.organizeImports' | 'source.fixAll')[];
179
+ /**
180
+ * Code action kind, like `quickfix` or `refactor`.
181
+ *
182
+ * See https://code.visualstudio.com/api/references/vscode-api#CodeActionKind
183
+ */
184
+ kinds?: vscode.CodeActionKind[];
185
+ /**
186
+ * Title of the code action.
187
+ */
177
188
  title?: string;
189
+ /**
190
+ * Edit to apply to the document.
191
+ */
178
192
  getEdits?(diagnostic: vscode.Diagnostic): NullableResult<vscode.TextEdit[]>;
193
+ /**
194
+ * Cross-file edits to apply to the workspace.
195
+ */
179
196
  getWorkspaceEdit?(diagnostic: vscode.Diagnostic): NullableResult<vscode.WorkspaceEdit>;
180
197
  }
181
198
  export interface Config {
@@ -185,8 +202,13 @@ export interface Config {
185
202
  plugins?: {
186
203
  [id: string]: LanguageServicePlugin | LanguageServicePluginInstance | undefined;
187
204
  };
188
- rules?: {
189
- [id: string]: Rule | undefined;
205
+ lint?: {
206
+ rules?: {
207
+ [id: string]: Rule | undefined;
208
+ };
209
+ severities?: {
210
+ [id: string]: vscode.DiagnosticSeverity;
211
+ };
212
+ settings?: any;
190
213
  };
191
- rulesSettings?: RulesSettings;
192
214
  }
@@ -7,7 +7,6 @@ export declare function withCodeAction<T extends vscode.CodeAction>(items: T[]):
7
7
  export declare function withTextEdits<T extends vscode.TextEdit>(items: T[]): T[];
8
8
  export declare function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>): (vscode.TextDocumentEdit | vscode.CreateFile | vscode.RenameFile | vscode.DeleteFile)[];
9
9
  export declare function withDiagnostics<T extends vscode.Diagnostic>(items: T[]): T[];
10
- export declare function withSymbolInformations<T extends vscode.SymbolInformation>(items: T[]): T[];
11
10
  export declare function withLocations<T extends vscode.Location>(items: T[]): T[];
12
11
  export declare function withLocationLinks<T extends vscode.LocationLink>(items: T[]): T[];
13
12
  export declare function withCallHierarchyIncomingCalls<T extends vscode.CallHierarchyIncomingCall>(items: T[]): T[];
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.withRanges = exports.withCallHierarchyOutgoingCalls = exports.withCallHierarchyIncomingCalls = exports.withLocationLinks = exports.withLocations = exports.withSymbolInformations = exports.withDiagnostics = exports.withDocumentChanges = exports.withTextEdits = exports.withCodeAction = exports.createLocationSet = void 0;
2
+ exports.withRanges = exports.withCallHierarchyOutgoingCalls = exports.withCallHierarchyIncomingCalls = exports.withLocationLinks = exports.withLocations = exports.withDiagnostics = exports.withDocumentChanges = exports.withTextEdits = exports.withCodeAction = exports.createLocationSet = void 0;
3
3
  function createLocationSet() {
4
4
  const set = new Set();
5
5
  return {
@@ -60,18 +60,6 @@ function withDiagnostics(items) {
60
60
  ].join(':'));
61
61
  }
62
62
  exports.withDiagnostics = withDiagnostics;
63
- function withSymbolInformations(items) {
64
- return dedupe(items, item => [
65
- item.name,
66
- item.kind,
67
- item.location.uri,
68
- item.location.range.start.line,
69
- item.location.range.start.character,
70
- item.location.range.end.line,
71
- item.location.range.end.character,
72
- ].join(':'));
73
- }
74
- exports.withSymbolInformations = withSymbolInformations;
75
63
  function withLocations(items) {
76
64
  return dedupe(items, item => [
77
65
  item.uri,
@@ -1,7 +1,7 @@
1
1
  import type { TextDocument } from 'vscode-languageserver-textdocument';
2
- import type { LanguageServicePluginInstance, LanguageServiceRuntimeContext, Rule, RuleContext } from '../types';
2
+ import type { LanguageServicePluginInstance, LanguageServicePluginContext, Rule, RuleContext } from '../types';
3
3
  import { FileRangeCapabilities, VirtualFile } from '@volar/language-service';
4
4
  import { SourceMapWithDocuments } from '../documents';
5
- export declare function documentFeatureWorker<T>(context: LanguageServiceRuntimeContext, uri: string, isValidSourceMap: (file: VirtualFile, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => boolean, worker: (plugin: LanguageServicePluginInstance, document: TextDocument) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
6
- export declare function languageFeatureWorker<T, K>(context: LanguageServiceRuntimeContext, uri: string, arg: K, transformArg: (arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>, file: VirtualFile) => Generator<K> | K[], worker: (plugin: LanguageServicePluginInstance, document: TextDocument, arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined, file: VirtualFile | undefined) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
7
- export declare function ruleWorker<T>(context: LanguageServiceRuntimeContext, uri: string, isValidSourceMap: (file: VirtualFile) => boolean, worker: (ruleName: string, rule: Rule, ruleCtx: RuleContext) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
5
+ export declare function documentFeatureWorker<T>(context: LanguageServicePluginContext, uri: string, isValidSourceMap: (file: VirtualFile, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>) => boolean, worker: (plugin: LanguageServicePluginInstance, document: TextDocument) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>): Promise<NonNullable<Awaited<T>> | undefined>;
6
+ export declare function languageFeatureWorker<T, K>(context: LanguageServicePluginContext, uri: string, arg: K, transformArg: (arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities>, file: VirtualFile) => Generator<K> | K[], worker: (plugin: LanguageServicePluginInstance, document: TextDocument, arg: K, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined, file: VirtualFile | undefined) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
7
+ export declare function ruleWorker<T>(context: LanguageServicePluginContext, api: 'onSyntax' | 'onSemantic' | 'onFormat', uri: string, isValidSourceMap: (file: VirtualFile) => boolean, worker: (ruleName: string, rule: Rule, ruleCtx: RuleContext) => T, transform: (result: NonNullable<Awaited<T>>, sourceMap: SourceMapWithDocuments<FileRangeCapabilities> | undefined) => Awaited<T> | undefined, combineResult?: (results: NonNullable<Awaited<T>>[]) => NonNullable<Awaited<T>>, reportProgress?: (result: NonNullable<Awaited<T>>) => void): Promise<NonNullable<Awaited<T>> | undefined>;
@@ -76,39 +76,44 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
76
76
  });
77
77
  }
78
78
  exports.languageFeatureWorker = languageFeatureWorker;
79
- function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) {
80
- var _a, _b, _c, _d, _e;
79
+ function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) {
80
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
81
81
  return __awaiter(this, void 0, void 0, function* () {
82
82
  const document = context.getTextDocument(uri);
83
83
  const virtualFile = (_a = context.documents.getSourceByUri(uri)) === null || _a === void 0 ? void 0 : _a.root;
84
84
  let results = [];
85
85
  if (virtualFile) {
86
86
  yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () {
87
- var _f, _g, _h;
87
+ var _l, _m, _o, _p, _q, _r, _s, _t, _u;
88
88
  if (!isValidSourceMap(file)) {
89
89
  return true;
90
90
  }
91
91
  let ruleCtx = {
92
92
  // project context
93
+ modules: { typescript: (_l = context.typescript) === null || _l === void 0 ? void 0 : _l.module },
93
94
  uriToFileName: shared.uriToFileName,
94
95
  fileNameToUri: shared.fileNameToUri,
95
96
  rootUri: context.env.rootUri,
96
97
  locale: context.env.locale,
97
- getConfiguration: (_f = context.env.configurationHost) === null || _f === void 0 ? void 0 : _f.getConfiguration,
98
- onDidChangeConfiguration: (_g = context.env.configurationHost) === null || _g === void 0 ? void 0 : _g.onDidChangeConfiguration,
99
- settings: context.rulesSettings,
98
+ getConfiguration: (_m = context.env.configurationHost) === null || _m === void 0 ? void 0 : _m.getConfiguration,
99
+ onDidChangeConfiguration: (_o = context.env.configurationHost) === null || _o === void 0 ? void 0 : _o.onDidChangeConfiguration,
100
+ settings: (_q = (_p = context.config.lint) === null || _p === void 0 ? void 0 : _p.settings) !== null && _q !== void 0 ? _q : {},
100
101
  // document context
101
102
  ruleId: '',
102
103
  document: map.virtualFileDocument,
103
104
  report: () => { },
104
105
  };
105
106
  for (const plugin of Object.values(context.plugins)) {
106
- if ((_h = plugin.rules) === null || _h === void 0 ? void 0 : _h.prepare) {
107
- ruleCtx = yield plugin.rules.prepare(ruleCtx);
107
+ const fn = (_r = plugin.rules) === null || _r === void 0 ? void 0 : _r[api];
108
+ if (fn) {
109
+ ruleCtx = yield fn(ruleCtx);
110
+ }
111
+ else if ((_s = plugin.rules) === null || _s === void 0 ? void 0 : _s.onAny) {
112
+ ruleCtx = yield plugin.rules.onAny(ruleCtx);
108
113
  }
109
114
  }
110
- for (const ruleName in context.rules) {
111
- const rule = context.rules[ruleName];
115
+ for (const ruleName in (_t = context.config.lint) === null || _t === void 0 ? void 0 : _t.rules) {
116
+ const rule = (_u = context.config.lint) === null || _u === void 0 ? void 0 : _u.rules[ruleName];
112
117
  if (!rule) {
113
118
  continue;
114
119
  }
@@ -133,25 +138,30 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
133
138
  else if (document) {
134
139
  let ruleCtx = {
135
140
  // project context
141
+ modules: { typescript: (_b = context.typescript) === null || _b === void 0 ? void 0 : _b.module },
136
142
  uriToFileName: shared.uriToFileName,
137
143
  fileNameToUri: shared.fileNameToUri,
138
144
  rootUri: context.env.rootUri,
139
145
  locale: context.env.locale,
140
- getConfiguration: (_b = context.env.configurationHost) === null || _b === void 0 ? void 0 : _b.getConfiguration,
141
- onDidChangeConfiguration: (_c = context.env.configurationHost) === null || _c === void 0 ? void 0 : _c.onDidChangeConfiguration,
142
- settings: context.rulesSettings,
146
+ getConfiguration: (_c = context.env.configurationHost) === null || _c === void 0 ? void 0 : _c.getConfiguration,
147
+ onDidChangeConfiguration: (_d = context.env.configurationHost) === null || _d === void 0 ? void 0 : _d.onDidChangeConfiguration,
148
+ settings: (_f = (_e = context.config.lint) === null || _e === void 0 ? void 0 : _e.settings) !== null && _f !== void 0 ? _f : {},
143
149
  // document context
144
150
  ruleId: '',
145
151
  document,
146
152
  report: () => { },
147
153
  };
148
154
  for (const plugin of Object.values(context.plugins)) {
149
- if ((_d = plugin.rules) === null || _d === void 0 ? void 0 : _d.prepare) {
150
- ruleCtx = yield ((_e = plugin.rules) === null || _e === void 0 ? void 0 : _e.prepare(ruleCtx));
155
+ const fn = (_g = plugin.rules) === null || _g === void 0 ? void 0 : _g[api];
156
+ if (fn) {
157
+ ruleCtx = yield fn(ruleCtx);
158
+ }
159
+ else if ((_h = plugin.rules) === null || _h === void 0 ? void 0 : _h.onAny) {
160
+ ruleCtx = yield plugin.rules.onAny(ruleCtx);
151
161
  }
152
162
  }
153
- for (const ruleName in context.rules) {
154
- const rule = context.rules[ruleName];
163
+ for (const ruleName in (_j = context.config.lint) === null || _j === void 0 ? void 0 : _j.rules) {
164
+ const rule = (_k = context.config.lint) === null || _k === void 0 ? void 0 : _k.rules[ruleName];
155
165
  if (!rule) {
156
166
  continue;
157
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-service",
3
- "version": "1.2.0-alpha.8",
3
+ "version": "1.3.0-alpha.0",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,15 +13,15 @@
13
13
  "directory": "packages/language-service"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "1.2.0-alpha.8",
17
- "@volar/shared": "1.2.0-alpha.8",
18
- "@volar/source-map": "1.2.0-alpha.8",
19
- "@volar/typescript-faster": "1.2.0-alpha.8",
20
- "vscode-html-languageservice": "^5.0.3",
21
- "vscode-json-languageservice": "^5.1.3",
22
- "vscode-languageserver-protocol": "^3.17.2",
16
+ "@volar/language-core": "1.3.0-alpha.0",
17
+ "@volar/shared": "1.3.0-alpha.0",
18
+ "@volar/source-map": "1.3.0-alpha.0",
19
+ "@volar/typescript-faster": "1.3.0-alpha.0",
20
+ "vscode-html-languageservice": "^5.0.4",
21
+ "vscode-json-languageservice": "^5.2.0",
22
+ "vscode-languageserver-protocol": "^3.17.3",
23
23
  "vscode-languageserver-textdocument": "^1.0.8",
24
24
  "vscode-uri": "^3.0.7"
25
25
  },
26
- "gitHead": "9437b4560f35d2a153a9e2ae0dd0f64285bbb3b3"
26
+ "gitHead": "7582403cc521d33f642183a32da44fb1f64e65ef"
27
27
  }
@@ -1,11 +0,0 @@
1
- import type { LanguageServiceRuntimeContext } from '../types';
2
- import { ExecuteCommandContext } from '@volar/language-service';
3
- import * as vscode from 'vscode-languageserver-protocol';
4
- export declare const executePluginCommand: string;
5
- export type ExecutePluginCommandArgs = [
6
- string,
7
- // uri
8
- string | undefined,
9
- vscode.Command
10
- ];
11
- export declare function register(context: LanguageServiceRuntimeContext): (command: string, args: ExecutePluginCommandArgs, executeCommandContext: ExecuteCommandContext) => Promise<void>;