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

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.
@@ -61,18 +61,16 @@ function createLanguageServiceContext(host, languageContext, config, env, getLan
61
61
  core: languageContext,
62
62
  env: env,
63
63
  get plugins() {
64
- var _a, _b, _c, _d, _e;
64
+ var _a, _b;
65
65
  if (!plugins) {
66
66
  plugins = {}; // avoid infinite loop
67
67
  for (let 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());
71
- (_c = _plugin.setup) === null || _c === void 0 ? void 0 : _c.call(_plugin, this);
72
71
  plugins[pluginId] = _plugin;
73
72
  }
74
- else {
75
- (_e = (_d = plugin).setup) === null || _e === void 0 ? void 0 : _e.call(_d, this);
73
+ else if (plugin) {
76
74
  plugins[pluginId] = plugin;
77
75
  }
78
76
  }
package/out/types.d.ts CHANGED
@@ -78,9 +78,8 @@ export interface LanguageServicePlugin<T = {}> {
78
78
  (context: LanguageServiceRuntimeContext, service: LanguageService): LanguageServicePluginInstance & T;
79
79
  }
80
80
  export interface LanguageServicePluginInstance {
81
- setup?(context: LanguageServiceRuntimeContext): void;
82
81
  validation?: {
83
- resolveRuleContext?(context: RuleContext): void;
82
+ setupRuleContext?(context: RuleContext): NotNullableResult<RuleContext>;
84
83
  onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
85
84
  onSyntactic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
86
85
  onSuggestion?(document: TextDocument): NullableResult<vscode.Diagnostic[]>;
@@ -168,7 +167,7 @@ export interface RuleFix {
168
167
  }
169
168
  export interface LanguageServiceConfig {
170
169
  languages?: ConfigValue<LanguageModule>;
171
- plugins?: ConfigValue<LanguageServicePlugin>;
170
+ plugins?: ConfigValue<LanguageServicePlugin | LanguageServicePluginInstance>;
172
171
  rules?: ConfigValue<Rule>;
173
172
  }
174
173
  type ConfigValue<T> = {
@@ -84,11 +84,11 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
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, _e;
87
+ var _d;
88
88
  if (!isValidSourceMap(file)) {
89
89
  return true;
90
90
  }
91
- const ruleCtx = {
91
+ let ruleCtx = {
92
92
  ruleId: '',
93
93
  document: map.virtualFileDocument,
94
94
  uriToFileName: shared.uriToFileName,
@@ -96,7 +96,9 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
96
96
  report: () => { },
97
97
  };
98
98
  for (const plugin of Object.values(context.plugins)) {
99
- (_e = (_d = plugin.validation) === null || _d === void 0 ? void 0 : _d.resolveRuleContext) === null || _e === void 0 ? void 0 : _e.call(_d, ruleCtx);
99
+ if ((_d = plugin.validation) === null || _d === void 0 ? void 0 : _d.setupRuleContext) {
100
+ ruleCtx = yield plugin.validation.setupRuleContext(ruleCtx);
101
+ }
100
102
  }
101
103
  for (const ruleName in context.rules) {
102
104
  const rule = context.rules[ruleName];
@@ -122,7 +124,7 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
122
124
  }));
123
125
  }
124
126
  else if (document) {
125
- const ruleCtx = {
127
+ let ruleCtx = {
126
128
  ruleId: '',
127
129
  document,
128
130
  uriToFileName: shared.uriToFileName,
@@ -130,7 +132,9 @@ function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineRe
130
132
  report: () => { },
131
133
  };
132
134
  for (const plugin of Object.values(context.plugins)) {
133
- (_c = (_b = plugin.validation) === null || _b === void 0 ? void 0 : _b.resolveRuleContext) === null || _c === void 0 ? void 0 : _c.call(_b, ruleCtx);
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));
137
+ }
134
138
  }
135
139
  for (const ruleName in context.rules) {
136
140
  const rule = context.rules[ruleName];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-service",
3
- "version": "1.2.0-alpha.3",
3
+ "version": "1.2.0-alpha.4",
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.3",
17
- "@volar/shared": "1.2.0-alpha.3",
18
- "@volar/source-map": "1.2.0-alpha.3",
19
- "@volar/typescript-faster": "1.2.0-alpha.3",
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",
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": "651fb9568432d0bfcab86fc1cd9fcfaae87e1d6d"
26
+ "gitHead": "cce402aa84061635c951e27c4423408d0b56e46d"
27
27
  }