@volar/language-service 1.2.0-alpha.4 → 1.2.0-alpha.5

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.
@@ -1,10 +1,10 @@
1
1
  import { LanguageServiceHost } from '@volar/language-core';
2
2
  import * as executeCommand from './languageFeatures/executeCommand';
3
- import { LanguageServiceConfig, LanguageServiceRuntimeContext } from './types';
3
+ import { Config, LanguageServiceRuntimeContext } from './types';
4
4
  import type * as ts from 'typescript/lib/tsserverlibrary';
5
5
  import type * as _ from 'vscode-languageserver-protocol';
6
6
  export type LanguageService = ReturnType<typeof createLanguageService>;
7
- export declare function createLanguageService(host: LanguageServiceHost, config: LanguageServiceConfig, env: LanguageServiceRuntimeContext['env'], documentRegistry?: ts.DocumentRegistry): {
7
+ export declare function createLanguageService(host: LanguageServiceHost, config: Config, env: LanguageServiceRuntimeContext['env'], documentRegistry?: ts.DocumentRegistry): {
8
8
  format: (uri: string, options: _.FormattingOptions, range?: _.Range | undefined, onTypeParams?: {
9
9
  ch: string;
10
10
  position: _.Position;
@@ -64,7 +64,7 @@ function createLanguageServiceContext(host, languageContext, config, env, getLan
64
64
  var _a, _b;
65
65
  if (!plugins) {
66
66
  plugins = {}; // avoid infinite loop
67
- for (let pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) {
67
+ for (const pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) {
68
68
  const plugin = (_b = config.plugins) === null || _b === void 0 ? void 0 : _b[pluginId];
69
69
  if (plugin instanceof Function) {
70
70
  const _plugin = plugin(this, getLanguageService());
@@ -189,7 +189,14 @@ function register(context) {
189
189
  error.code || (error.code = ruleCtx.ruleId);
190
190
  reportResults.push([error, ...fixes]);
191
191
  };
192
- yield ((_d = rule[api]) === null || _d === void 0 ? void 0 : _d.call(rule, ruleCtx));
192
+ if (typeof rule === 'function') {
193
+ if (api === 'onSyntax') {
194
+ yield rule(ruleCtx);
195
+ }
196
+ }
197
+ else {
198
+ yield ((_d = rule[api]) === null || _d === void 0 ? void 0 : _d.call(rule, ruleCtx));
199
+ }
193
200
  (_e = context.ruleFixes) !== null && _e !== void 0 ? _e : (context.ruleFixes = {});
194
201
  (_f = (_h = context.ruleFixes)[_j = ruleCtx.document.uri]) !== null && _f !== void 0 ? _f : (_h[_j] = {});
195
202
  (_g = (_k = context.ruleFixes[ruleCtx.document.uri])[_l = ruleCtx.ruleId]) !== null && _g !== void 0 ? _g : (_k[_l] = {});
package/out/types.d.ts CHANGED
@@ -16,6 +16,7 @@ export interface LanguageServiceRuntimeContext<Host extends LanguageServiceHost
16
16
  } | undefined;
17
17
  env: {
18
18
  rootUri: URI;
19
+ locale?: string;
19
20
  configurationHost?: ConfigurationHost;
20
21
  documentContext: DocumentContext;
21
22
  fileSystemProvider?: FileSystemProvider;
@@ -78,8 +79,10 @@ export interface LanguageServicePlugin<T = {}> {
78
79
  (context: LanguageServiceRuntimeContext, service: LanguageService): LanguageServicePluginInstance & T;
79
80
  }
80
81
  export interface LanguageServicePluginInstance {
82
+ rules?: {
83
+ prepare?(context: RuleContext): NotNullableResult<RuleContext>;
84
+ };
81
85
  validation?: {
82
- setupRuleContext?(context: RuleContext): NotNullableResult<RuleContext>;
83
86
  onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
84
87
  onSyntactic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
85
88
  onSuggestion?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
@@ -147,16 +150,21 @@ export interface LanguageServicePluginInstance {
147
150
  */
148
151
  resolveEmbeddedRange?(range: vscode.Range): vscode.Range | undefined;
149
152
  }
150
- export interface Rule {
153
+ export type Rule = _Rule | NonNullable<_Rule['onSyntax']>;
154
+ export interface _Rule {
151
155
  onFormat?(ctx: RuleContext): void;
152
156
  onSyntax?(ctx: RuleContext): void;
153
157
  onSemantic?(ctx: RuleContext): void;
154
158
  }
155
159
  export interface RuleContext {
156
- ruleId: string;
157
- document: TextDocument;
160
+ locale?: string;
158
161
  uriToFileName(uri: string): string;
159
162
  fileNameToUri(fileName: string): string;
163
+ rootUri: URI;
164
+ getConfiguration?: ConfigurationHost['getConfiguration'];
165
+ onDidChangeConfiguration?: ConfigurationHost['onDidChangeConfiguration'];
166
+ ruleId: string;
167
+ document: TextDocument;
160
168
  report(error: vscode.Diagnostic, ...fixes: RuleFix[]): void;
161
169
  }
162
170
  export interface RuleFix {
@@ -165,11 +173,14 @@ export interface RuleFix {
165
173
  getEdits?(diagnostic: vscode.Diagnostic): NullableResult<vscode.TextEdit[]>;
166
174
  getWorkspaceEdit?(diagnostic: vscode.Diagnostic): NullableResult<vscode.WorkspaceEdit>;
167
175
  }
168
- export interface LanguageServiceConfig {
169
- languages?: ConfigValue<LanguageModule>;
170
- plugins?: ConfigValue<LanguageServicePlugin | LanguageServicePluginInstance>;
171
- rules?: ConfigValue<Rule>;
176
+ export interface Config {
177
+ languages?: {
178
+ [id: string]: LanguageModule | undefined;
179
+ };
180
+ plugins?: {
181
+ [id: string]: LanguageServicePlugin | LanguageServicePluginInstance | undefined;
182
+ };
183
+ rules?: {
184
+ [id: string]: Rule | undefined;
185
+ };
172
186
  }
173
- type ConfigValue<T> = {
174
- [id: string]: T | undefined;
175
- };
package/out/types.js CHANGED
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  __exportStar(require("vscode-languageserver-protocol"), exports);
17
17
  ;
18
+ ;
18
19
  //# sourceMappingURL=types.js.map
@@ -77,27 +77,33 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
77
77
  }
78
78
  exports.languageFeatureWorker = languageFeatureWorker;
79
79
  function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) {
80
- var _a, _b, _c;
80
+ var _a, _b, _c, _d, _e;
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 _d;
87
+ var _f, _g, _h;
88
88
  if (!isValidSourceMap(file)) {
89
89
  return true;
90
90
  }
91
91
  let ruleCtx = {
92
- ruleId: '',
93
- document: map.virtualFileDocument,
92
+ // project context
94
93
  uriToFileName: shared.uriToFileName,
95
94
  fileNameToUri: shared.fileNameToUri,
95
+ rootUri: context.env.rootUri,
96
+ 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
+ // document context
100
+ ruleId: '',
101
+ document: map.virtualFileDocument,
96
102
  report: () => { },
97
103
  };
98
104
  for (const plugin of Object.values(context.plugins)) {
99
- if ((_d = plugin.validation) === null || _d === void 0 ? void 0 : _d.setupRuleContext) {
100
- ruleCtx = yield plugin.validation.setupRuleContext(ruleCtx);
105
+ if ((_h = plugin.rules) === null || _h === void 0 ? void 0 : _h.prepare) {
106
+ ruleCtx = yield plugin.rules.prepare(ruleCtx);
101
107
  }
102
108
  }
103
109
  for (const ruleName in context.rules) {
@@ -125,15 +131,21 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
125
131
  }
126
132
  else if (document) {
127
133
  let ruleCtx = {
128
- ruleId: '',
129
- document,
134
+ // project context
130
135
  uriToFileName: shared.uriToFileName,
131
136
  fileNameToUri: shared.fileNameToUri,
137
+ rootUri: context.env.rootUri,
138
+ locale: context.env.locale,
139
+ getConfiguration: (_b = context.env.configurationHost) === null || _b === void 0 ? void 0 : _b.getConfiguration,
140
+ onDidChangeConfiguration: (_c = context.env.configurationHost) === null || _c === void 0 ? void 0 : _c.onDidChangeConfiguration,
141
+ // document context
142
+ ruleId: '',
143
+ document,
132
144
  report: () => { },
133
145
  };
134
146
  for (const plugin of Object.values(context.plugins)) {
135
- if ((_b = plugin.validation) === null || _b === void 0 ? void 0 : _b.setupRuleContext) {
136
- ruleCtx = yield ((_c = plugin.validation) === null || _c === void 0 ? void 0 : _c.setupRuleContext(ruleCtx));
147
+ if ((_d = plugin.rules) === null || _d === void 0 ? void 0 : _d.prepare) {
148
+ ruleCtx = yield ((_e = plugin.rules) === null || _e === void 0 ? void 0 : _e.prepare(ruleCtx));
137
149
  }
138
150
  }
139
151
  for (const ruleName in context.rules) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-service",
3
- "version": "1.2.0-alpha.4",
3
+ "version": "1.2.0-alpha.5",
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.4",
17
- "@volar/shared": "1.2.0-alpha.4",
18
- "@volar/source-map": "1.2.0-alpha.4",
19
- "@volar/typescript-faster": "1.2.0-alpha.4",
16
+ "@volar/language-core": "1.2.0-alpha.5",
17
+ "@volar/shared": "1.2.0-alpha.5",
18
+ "@volar/source-map": "1.2.0-alpha.5",
19
+ "@volar/typescript-faster": "1.2.0-alpha.5",
20
20
  "vscode-html-languageservice": "^5.0.3",
21
21
  "vscode-json-languageservice": "^5.1.3",
22
22
  "vscode-languageserver-protocol": "^3.17.2",
23
23
  "vscode-languageserver-textdocument": "^1.0.8",
24
24
  "vscode-uri": "^3.0.7"
25
25
  },
26
- "gitHead": "cce402aa84061635c951e27c4423408d0b56e46d"
26
+ "gitHead": "a31d022987c454762d1ba3c9ef8e7d74a5bca06a"
27
27
  }