@volar/language-service 1.2.0-alpha.1 → 1.2.0-alpha.11

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 (53) hide show
  1. package/out/baseLanguageService.d.ts +3 -5
  2. package/out/baseLanguageService.js +11 -14
  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 +84 -151
  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 +3 -3
  15. package/out/languageFeatures/callHierarchy.js +5 -3
  16. package/out/languageFeatures/codeActionResolve.d.ts +2 -2
  17. package/out/languageFeatures/codeActionResolve.js +28 -15
  18. package/out/languageFeatures/codeActions.d.ts +15 -6
  19. package/out/languageFeatures/codeActions.js +94 -22
  20. package/out/languageFeatures/codeLens.d.ts +11 -4
  21. package/out/languageFeatures/codeLens.js +25 -15
  22. package/out/languageFeatures/codeLensResolve.d.ts +4 -2
  23. package/out/languageFeatures/codeLensResolve.js +20 -12
  24. package/out/languageFeatures/complete.d.ts +3 -3
  25. package/out/languageFeatures/complete.js +20 -4
  26. package/out/languageFeatures/completeResolve.d.ts +2 -2
  27. package/out/languageFeatures/completeResolve.js +3 -14
  28. package/out/languageFeatures/definition.d.ts +2 -2
  29. package/out/languageFeatures/documentHighlights.d.ts +2 -2
  30. package/out/languageFeatures/documentLinks.d.ts +2 -2
  31. package/out/languageFeatures/documentSemanticTokens.d.ts +2 -2
  32. package/out/languageFeatures/fileReferences.d.ts +2 -2
  33. package/out/languageFeatures/fileRename.d.ts +2 -2
  34. package/out/languageFeatures/fileRename.js +1 -1
  35. package/out/languageFeatures/hover.d.ts +2 -2
  36. package/out/languageFeatures/inlayHints.d.ts +2 -2
  37. package/out/languageFeatures/references.d.ts +2 -2
  38. package/out/languageFeatures/rename.d.ts +3 -3
  39. package/out/languageFeatures/rename.js +64 -44
  40. package/out/languageFeatures/renamePrepare.d.ts +2 -2
  41. package/out/languageFeatures/signatureHelp.d.ts +2 -2
  42. package/out/languageFeatures/validation.d.ts +7 -3
  43. package/out/languageFeatures/validation.js +68 -15
  44. package/out/languageFeatures/workspaceSymbols.d.ts +2 -2
  45. package/out/transformer/foldingRanges.js +6 -6
  46. package/out/types.d.ts +90 -39
  47. package/out/utils/featureWorkers.d.ts +4 -4
  48. package/out/utils/featureWorkers.js +44 -11
  49. package/package.json +9 -9
  50. package/out/languageFeatures/executeCommand.d.ts +0 -11
  51. package/out/languageFeatures/executeCommand.js +0 -32
  52. package/out/languageFeatures/validation copy.d.ts +0 -7
  53. package/out/languageFeatures/validation copy.js +0 -234
@@ -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.ruleWorker = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
12
12
  const definePlugin_1 = require("./definePlugin");
13
+ const shared = require("@volar/shared");
13
14
  function documentFeatureWorker(context, uri, isValidSourceMap, worker, transform, combineResult) {
14
15
  return __awaiter(this, void 0, void 0, function* () {
15
16
  return languageFeatureWorker(context, uri, undefined, (_, map, file) => {
@@ -75,28 +76,44 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
75
76
  });
76
77
  }
77
78
  exports.languageFeatureWorker = languageFeatureWorker;
78
- function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) {
79
- var _a, _b, _c;
79
+ function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) {
80
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
80
81
  return __awaiter(this, void 0, void 0, function* () {
81
82
  const document = context.getTextDocument(uri);
82
83
  const virtualFile = (_a = context.documents.getSourceByUri(uri)) === null || _a === void 0 ? void 0 : _a.root;
83
84
  let results = [];
84
85
  if (virtualFile) {
85
86
  yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () {
86
- var _d, _e;
87
+ var _l, _m, _o, _p, _q, _r, _s, _t, _u;
87
88
  if (!isValidSourceMap(file)) {
88
89
  return true;
89
90
  }
90
- const ruleCtx = {
91
+ let ruleCtx = {
92
+ // project context
93
+ modules: { typescript: (_l = context.typescript) === null || _l === void 0 ? void 0 : _l.module },
94
+ uriToFileName: shared.uriToFileName,
95
+ fileNameToUri: shared.fileNameToUri,
96
+ rootUri: context.env.rootUri,
97
+ locale: context.env.locale,
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 : {},
101
+ // document context
91
102
  ruleId: '',
92
103
  document: map.virtualFileDocument,
93
104
  report: () => { },
94
105
  };
95
106
  for (const plugin of Object.values(context.plugins)) {
96
- (_e = (_d = plugin.validation) === null || _d === void 0 ? void 0 : _d.resolveRuleContext) === null || _e === void 0 ? void 0 : _e.call(_d, 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);
113
+ }
97
114
  }
98
- for (const ruleName in context.rules) {
99
- 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];
100
117
  if (!rule) {
101
118
  continue;
102
119
  }
@@ -119,16 +136,32 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
119
136
  }));
120
137
  }
121
138
  else if (document) {
122
- const ruleCtx = {
139
+ let ruleCtx = {
140
+ // project context
141
+ modules: { typescript: (_b = context.typescript) === null || _b === void 0 ? void 0 : _b.module },
142
+ uriToFileName: shared.uriToFileName,
143
+ fileNameToUri: shared.fileNameToUri,
144
+ rootUri: context.env.rootUri,
145
+ locale: context.env.locale,
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 : {},
149
+ // document context
123
150
  ruleId: '',
124
151
  document,
125
152
  report: () => { },
126
153
  };
127
154
  for (const plugin of Object.values(context.plugins)) {
128
- (_c = (_b = plugin.validation) === null || _b === void 0 ? void 0 : _b.resolveRuleContext) === null || _c === void 0 ? void 0 : _c.call(_b, 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);
161
+ }
129
162
  }
130
- for (const ruleName in context.rules) {
131
- 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];
132
165
  if (!rule) {
133
166
  continue;
134
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-service",
3
- "version": "1.2.0-alpha.1",
3
+ "version": "1.2.0-alpha.11",
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.1",
17
- "@volar/shared": "1.2.0-alpha.1",
18
- "@volar/source-map": "1.2.0-alpha.1",
19
- "@volar/typescript-faster": "1.2.0-alpha.1",
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.2.0-alpha.11",
17
+ "@volar/shared": "1.2.0-alpha.11",
18
+ "@volar/source-map": "1.2.0-alpha.11",
19
+ "@volar/typescript-faster": "1.2.0-alpha.11",
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": "08f0fd7c8a0ac7ba92de978c3ee7338d1919ebd7"
26
+ "gitHead": "b9b3d607df5772c00edda17cfda05281c3e7c06f"
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>;
@@ -1,32 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.register = exports.executePluginCommand = void 0;
12
- const randomCommandId = Math.random().toString(36).slice(2); // TODO
13
- exports.executePluginCommand = `volar.${randomCommandId}.executePluginCommand`;
14
- function register(context) {
15
- return (command, args, executeCommandContext) => __awaiter(this, void 0, void 0, function* () {
16
- var _a, _b;
17
- if (command === exports.executePluginCommand) {
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
- }
28
- }
29
- });
30
- }
31
- exports.register = register;
32
- //# sourceMappingURL=executeCommand.js.map
@@ -1,7 +0,0 @@
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[]>;
@@ -1,234 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.register = exports.updateRange = void 0;
12
- const shared = require("@volar/shared");
13
- const dedupe = require("../utils/dedupe");
14
- const featureWorkers_1 = require("../utils/featureWorkers");
15
- function updateRange(range, change) {
16
- if (!updatePosition(range.start, change, false)) {
17
- return;
18
- }
19
- if (!updatePosition(range.end, change, true)) {
20
- return;
21
- }
22
- if (range.end.line === range.start.line && range.end.character <= range.start.character) {
23
- range.end.character++;
24
- }
25
- return range;
26
- }
27
- exports.updateRange = updateRange;
28
- function updatePosition(position, change, isEnd) {
29
- if (change.range.end.line > position.line) {
30
- if (change.newEnd.line > position.line) {
31
- // No change
32
- return true;
33
- }
34
- else if (change.newEnd.line === position.line) {
35
- position.character = Math.min(position.character, change.newEnd.character);
36
- return true;
37
- }
38
- else if (change.newEnd.line < position.line) {
39
- position.line = change.newEnd.line;
40
- position.character = change.newEnd.character;
41
- return true;
42
- }
43
- }
44
- else if (change.range.end.line === position.line) {
45
- const characterDiff = change.newEnd.character - change.range.end.character;
46
- if (position.character >= change.range.end.character) {
47
- if (change.newEnd.line !== change.range.end.line) {
48
- position.line = change.newEnd.line;
49
- position.character = change.newEnd.character + position.character - change.range.end.character;
50
- }
51
- else {
52
- if (isEnd ? change.range.end.character < position.character : change.range.end.character <= position.character) {
53
- position.character += characterDiff;
54
- }
55
- else {
56
- const offset = change.range.end.character - position.character;
57
- if (-characterDiff > offset) {
58
- position.character += characterDiff + offset;
59
- }
60
- }
61
- }
62
- return true;
63
- }
64
- else {
65
- if (change.newEnd.line === change.range.end.line) {
66
- const offset = change.range.end.character - position.character;
67
- if (-characterDiff > offset) {
68
- position.character += characterDiff + offset;
69
- }
70
- }
71
- else if (change.newEnd.line < change.range.end.line) {
72
- position.line = change.newEnd.line;
73
- position.character = change.newEnd.character;
74
- }
75
- else {
76
- // No change
77
- }
78
- return true;
79
- }
80
- }
81
- else if (change.range.end.line < position.line) {
82
- position.line += change.newEnd.line - change.range.end.line;
83
- return true;
84
- }
85
- return false;
86
- }
87
- function register(context) {
88
- const responseCache = new Map();
89
- const cacheMaps = {
90
- semantic: new Map(),
91
- declaration: new Map(),
92
- syntactic: new Map(),
93
- suggestion: new Map(),
94
- };
95
- return (uri, token, response) => __awaiter(this, void 0, void 0, function* () {
96
- var _a;
97
- const lastResponse = (_a = responseCache.get(uri)) !== null && _a !== void 0 ? _a : responseCache.set(uri, {
98
- semantic: { errors: [] },
99
- declaration: { errors: [] },
100
- suggestion: { errors: [] },
101
- syntactic: { errors: [] },
102
- }).get(uri);
103
- const newSnapshot = context.host.getScriptSnapshot(shared.uriToFileName(uri));
104
- const newDocument = context.getTextDocument(uri);
105
- let updateCacheRangeFailed = false;
106
- let errorsUpdated = false;
107
- let lastCheckCancelAt = 0;
108
- for (const cache of Object.values(lastResponse)) {
109
- const oldSnapshot = cache.snapshot;
110
- const oldDocument = cache.document;
111
- const change = oldSnapshot ? newSnapshot === null || newSnapshot === void 0 ? void 0 : newSnapshot.getChangeRange(oldSnapshot) : undefined;
112
- cache.snapshot = newSnapshot;
113
- cache.document = newDocument;
114
- if (!updateCacheRangeFailed && newDocument && oldSnapshot && oldDocument && newSnapshot && change) {
115
- const changeRange = {
116
- range: {
117
- start: oldDocument.positionAt(change.span.start),
118
- end: oldDocument.positionAt(change.span.start + change.span.length),
119
- },
120
- newEnd: newDocument.positionAt(change.span.start + change.newLength),
121
- };
122
- for (const error of cache.errors) {
123
- if (!updateRange(error.range, changeRange)) {
124
- updateCacheRangeFailed = true;
125
- break;
126
- }
127
- }
128
- }
129
- }
130
- yield worker('onSyntactic', cacheMaps.syntactic, lastResponse.syntactic);
131
- doResponse();
132
- yield worker('onSuggestion', cacheMaps.suggestion, lastResponse.suggestion);
133
- doResponse();
134
- yield worker('onSemantic', cacheMaps.semantic, lastResponse.semantic);
135
- doResponse();
136
- yield worker('onDeclaration', cacheMaps.declaration, lastResponse.declaration);
137
- return collectErrors();
138
- function doResponse() {
139
- if (errorsUpdated && !updateCacheRangeFailed) {
140
- response === null || response === void 0 ? void 0 : response(collectErrors());
141
- errorsUpdated = false;
142
- }
143
- }
144
- function collectErrors() {
145
- return Object.values(lastResponse).flatMap(({ errors }) => errors);
146
- }
147
- function worker(api, cacheMap, cache) {
148
- return __awaiter(this, void 0, void 0, function* () {
149
- const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, _, file) {
150
- if (file.capabilities.diagnostic) {
151
- yield arg;
152
- }
153
- }, (plugin, document) => __awaiter(this, void 0, void 0, function* () {
154
- var _a, _b, _c, _d, _e;
155
- if (token) {
156
- if (Date.now() - lastCheckCancelAt >= 5) {
157
- yield shared.sleep(5); // wait for LSP event polling
158
- lastCheckCancelAt = Date.now();
159
- }
160
- if (token.isCancellationRequested)
161
- return;
162
- }
163
- const pluginId = context.plugins.indexOf(plugin);
164
- const pluginCache = (_a = cacheMap.get(pluginId)) !== null && _a !== void 0 ? _a : cacheMap.set(pluginId, new Map()).get(pluginId);
165
- const cache = pluginCache.get(document.uri);
166
- const tsProjectVersion = (api === 'onDeclaration' || api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined;
167
- if (api === 'onDeclaration' || api === 'onSemantic') {
168
- if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) {
169
- return cache.errors;
170
- }
171
- }
172
- else {
173
- if (cache && cache.documentVersion === document.version) {
174
- return cache.errors;
175
- }
176
- }
177
- const errors = yield ((_e = (_d = plugin.validation) === null || _d === void 0 ? void 0 : _d[api]) === null || _e === void 0 ? void 0 : _e.call(_d, document));
178
- errorsUpdated = true;
179
- pluginCache.set(document.uri, {
180
- documentVersion: document.version,
181
- errors,
182
- tsProjectVersion,
183
- });
184
- return errors;
185
- }), (errors, map) => transformErrorRange(map, errors), arr => dedupe.withDiagnostics(arr.flat()));
186
- if (result) {
187
- cache.errors = result;
188
- cache.snapshot = newSnapshot;
189
- }
190
- });
191
- }
192
- });
193
- function transformErrorRange(map, errors) {
194
- const result = [];
195
- for (const error of errors) {
196
- // clone it to avoid modify cache
197
- let _error = Object.assign({}, error);
198
- if (map) {
199
- const range = map.toSourceRange(error.range, data => !!data.diagnostic);
200
- if (!range) {
201
- continue;
202
- }
203
- _error.range = range;
204
- }
205
- if (_error.relatedInformation) {
206
- const relatedInfos = [];
207
- for (const info of _error.relatedInformation) {
208
- if (context.documents.hasVirtualFileByUri(info.location.uri)) {
209
- for (const [_, map] of context.documents.getMapsByVirtualFileUri(info.location.uri)) {
210
- const range = map.toSourceRange(info.location.range, data => !!data.diagnostic);
211
- if (range) {
212
- relatedInfos.push({
213
- location: {
214
- uri: map.sourceFileDocument.uri,
215
- range,
216
- },
217
- message: info.message,
218
- });
219
- }
220
- }
221
- }
222
- else {
223
- relatedInfos.push(info);
224
- }
225
- }
226
- _error.relatedInformation = relatedInfos;
227
- }
228
- result.push(_error);
229
- }
230
- return result;
231
- }
232
- }
233
- exports.register = register;
234
- //# sourceMappingURL=validation%20copy.js.map