@volar/language-service 1.3.0-alpha.0 → 1.3.0-alpha.1

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,9 +1,8 @@
1
- import { LanguageServiceHost } from '@volar/language-core';
2
- import { Config, LanguageServicePluginContext } from './types';
1
+ import { LanguageServicePluginContext, LanguageServiceOptions } from './types';
3
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
4
3
  import type * as _ from 'vscode-languageserver-protocol';
5
4
  export type LanguageService = ReturnType<typeof createLanguageService>;
6
- export declare function createLanguageService(host: LanguageServiceHost, config: Config, env: LanguageServicePluginContext['env'], documentRegistry?: ts.DocumentRegistry): {
5
+ export declare function createLanguageService(ctx: LanguageServiceOptions, documentRegistry?: ts.DocumentRegistry): {
7
6
  triggerCharacters: string[];
8
7
  format: (uri: string, options: _.FormattingOptions, range?: _.Range | undefined, onTypeParams?: {
9
8
  ch: string;
@@ -34,61 +34,43 @@ const foldingRanges = require("./documentFeatures/foldingRanges");
34
34
  const format = require("./documentFeatures/format");
35
35
  const linkedEditingRanges = require("./documentFeatures/linkedEditingRanges");
36
36
  const selectionRanges = require("./documentFeatures/selectionRanges");
37
- function createLanguageService(host, config, env, documentRegistry) {
37
+ function createLanguageService(ctx, documentRegistry) {
38
38
  var _a;
39
- const languageContext = (0, language_core_1.createLanguageContext)(host, Object.values((_a = config.languages) !== null && _a !== void 0 ? _a : {}).filter(shared.notEmpty));
40
- const context = createLanguageServiceContext(host, languageContext, config, env, documentRegistry);
39
+ const languageContext = (0, language_core_1.createLanguageContext)(ctx.host, Object.values((_a = ctx.config.languages) !== null && _a !== void 0 ? _a : {}).filter(shared.notEmpty));
40
+ const context = createLanguageServiceContext(ctx, languageContext, documentRegistry);
41
41
  return createLanguageServiceBase(context);
42
42
  }
43
43
  exports.createLanguageService = createLanguageService;
44
- function createLanguageServiceContext(host, languageContext, config, env, documentRegistry) {
45
- var _a;
46
- const ts = (_a = host.getTypeScriptModule) === null || _a === void 0 ? void 0 : _a.call(host);
44
+ function createLanguageServiceContext(ctx, languageContext, documentRegistry) {
45
+ var _a, _b, _c, _d;
46
+ const ts = (_b = (_a = ctx.host).getTypeScriptModule) === null || _b === void 0 ? void 0 : _b.call(_a);
47
47
  const tsLs = ts === null || ts === void 0 ? void 0 : ts.createLanguageService(languageContext.typescript.languageServiceHost, documentRegistry);
48
48
  if (ts && tsLs) {
49
49
  tsFaster.decorate(ts, languageContext.typescript.languageServiceHost, tsLs);
50
50
  }
51
- let plugins;
52
- const textDocumentMapper = (0, documents_1.createDocumentsAndSourceMaps)(languageContext.virtualFiles);
51
+ const textDocumentMapper = (0, documents_1.createDocumentsAndSourceMaps)(ctx, languageContext.virtualFiles);
53
52
  const documents = new WeakMap();
54
53
  const documentVersions = new Map();
55
- const context = {
56
- uriToFileName: shared.uriToFileName,
57
- fileNameToUri: shared.fileNameToUri,
58
- host,
59
- core: languageContext,
60
- env: env,
61
- get plugins() {
62
- var _a, _b;
63
- if (!plugins) {
64
- plugins = {}; // avoid infinite loop
65
- for (const pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) {
66
- const plugin = (_b = config.plugins) === null || _b === void 0 ? void 0 : _b[pluginId];
67
- if (plugin instanceof Function) {
68
- const _plugin = plugin(this);
69
- plugins[pluginId] = _plugin;
70
- }
71
- else if (plugin) {
72
- plugins[pluginId] = plugin;
73
- }
74
- }
75
- }
76
- return plugins;
77
- },
78
- config,
79
- typescript: ts && tsLs ? {
54
+ const context = Object.assign(Object.assign({}, ctx), { core: languageContext, plugins: {}, typescript: ts && tsLs ? {
80
55
  module: ts,
81
56
  languageServiceHost: languageContext.typescript.languageServiceHost,
82
57
  languageService: tsLs,
83
- } : undefined,
84
- documents: textDocumentMapper,
85
- getTextDocument,
86
- };
58
+ } : undefined, documents: textDocumentMapper, getTextDocument });
59
+ for (const pluginId in (_c = ctx.config.plugins) !== null && _c !== void 0 ? _c : {}) {
60
+ const plugin = (_d = ctx.config.plugins) === null || _d === void 0 ? void 0 : _d[pluginId];
61
+ if (plugin instanceof Function) {
62
+ const _plugin = plugin(context);
63
+ context.plugins[pluginId] = _plugin;
64
+ }
65
+ else if (plugin) {
66
+ context.plugins[pluginId] = plugin;
67
+ }
68
+ }
87
69
  return context;
88
70
  function getTextDocument(uri) {
89
71
  var _a;
90
- const fileName = shared.uriToFileName(uri);
91
- const scriptSnapshot = host.getScriptSnapshot(fileName);
72
+ const fileName = ctx.uriToFileName(uri);
73
+ const scriptSnapshot = ctx.host.getScriptSnapshot(fileName);
92
74
  if (scriptSnapshot) {
93
75
  let document = documents.get(scriptSnapshot);
94
76
  if (!document) {
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.register = void 0;
12
12
  const vscode = require("vscode-languageserver-protocol");
13
13
  const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
14
- const shared = require("@volar/shared");
15
14
  const common_1 = require("../utils/common");
16
15
  function register(context) {
17
16
  return (uri, options, range, onTypeParams) => __awaiter(this, void 0, void 0, function* () {
@@ -26,7 +25,7 @@ function register(context) {
26
25
  ? yield tryFormat(document, onTypeParams.position, onTypeParams.ch)
27
26
  : yield tryFormat(document, range, undefined);
28
27
  }
29
- const initialIndentLanguageId = (_b = yield ((_a = context.env.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.format.initialIndent'))) !== null && _b !== void 0 ? _b : { html: true };
28
+ const initialIndentLanguageId = (_b = yield ((_a = context.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.format.initialIndent'))) !== null && _b !== void 0 ? _b : { html: true };
30
29
  const originalSnapshot = source.snapshot;
31
30
  const rootVirtualFile = source.root;
32
31
  const originalDocument = document;
@@ -81,7 +80,7 @@ function register(context) {
81
80
  if (edits.length > 0) {
82
81
  const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
83
82
  document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
84
- context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
83
+ context.core.virtualFiles.updateSource(context.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
85
84
  edited = true;
86
85
  }
87
86
  if (level > 1) {
@@ -125,7 +124,7 @@ function register(context) {
125
124
  if (indentEdits.length > 0) {
126
125
  const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
127
126
  document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
128
- context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
127
+ context.core.virtualFiles.updateSource(context.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), undefined);
129
128
  edited = true;
130
129
  }
131
130
  }
@@ -134,7 +133,7 @@ function register(context) {
134
133
  }
135
134
  if (edited) {
136
135
  // recover
137
- context.core.virtualFiles.updateSource(shared.uriToFileName(document.uri), originalSnapshot, undefined);
136
+ context.core.virtualFiles.updateSource(context.uriToFileName(document.uri), originalSnapshot, undefined);
138
137
  }
139
138
  if (document.getText() === originalDocument.getText())
140
139
  return;
@@ -3,6 +3,7 @@ import { Mapping, SourceMap } from '@volar/source-map';
3
3
  import * as vscode from 'vscode-languageserver-protocol';
4
4
  import { TextDocument } from 'vscode-languageserver-textdocument';
5
5
  import type * as ts from 'typescript/lib/tsserverlibrary';
6
+ import { LanguageServiceOptions } from './types';
6
7
  export type DocumentsAndSourceMaps = ReturnType<typeof createDocumentsAndSourceMaps>;
7
8
  export declare class SourceMapWithDocuments<Data = any> {
8
9
  sourceFileDocument: TextDocument;
@@ -29,7 +30,7 @@ export declare class MirrorMapWithDocument extends SourceMapWithDocuments<[Mirro
29
30
  constructor(document: TextDocument, map: MirrorMap);
30
31
  findMirrorPositions(start: vscode.Position): Generator<readonly [import("vscode-languageserver-textdocument").Position, MirrorBehaviorCapabilities], void, unknown>;
31
32
  }
32
- export declare function createDocumentsAndSourceMaps(mapper: VirtualFiles): {
33
+ export declare function createDocumentsAndSourceMaps(ctx: LanguageServiceOptions, mapper: VirtualFiles): {
33
34
  getSourceByUri(sourceFileUri: string): import("@volar/language-core").Source | undefined;
34
35
  hasVirtualFileByUri(virtualFileUri: string): boolean;
35
36
  getVirtualFileByUri(virtualFileUri: string): readonly [VirtualFile, import("@volar/language-core").Source] | readonly [undefined, undefined];
package/out/documents.js CHANGED
@@ -116,23 +116,23 @@ class MirrorMapWithDocument extends SourceMapWithDocuments {
116
116
  }
117
117
  }
118
118
  exports.MirrorMapWithDocument = MirrorMapWithDocument;
119
- function createDocumentsAndSourceMaps(mapper) {
119
+ function createDocumentsAndSourceMaps(ctx, mapper) {
120
120
  let version = 0;
121
121
  const _maps = new WeakMap();
122
122
  const _mirrorMaps = new WeakMap();
123
123
  const _documents = new WeakMap();
124
124
  return {
125
125
  getSourceByUri(sourceFileUri) {
126
- return mapper.getSource(shared.uriToFileName(sourceFileUri));
126
+ return mapper.getSource(ctx.uriToFileName(sourceFileUri));
127
127
  },
128
128
  hasVirtualFileByUri(virtualFileUri) {
129
- return mapper.hasVirtualFile(shared.uriToFileName(virtualFileUri));
129
+ return mapper.hasVirtualFile(ctx.uriToFileName(virtualFileUri));
130
130
  },
131
131
  getVirtualFileByUri(virtualFileUri) {
132
- return mapper.getVirtualFile(shared.uriToFileName(virtualFileUri));
132
+ return mapper.getVirtualFile(ctx.uriToFileName(virtualFileUri));
133
133
  },
134
134
  getMirrorMapByUri(virtualFileUri) {
135
- const fileName = shared.uriToFileName(virtualFileUri);
135
+ const fileName = ctx.uriToFileName(virtualFileUri);
136
136
  const [virtualFile] = mapper.getVirtualFile(fileName);
137
137
  if (virtualFile) {
138
138
  const map = mapper.getMirrorMap(virtualFile);
@@ -145,7 +145,7 @@ function createDocumentsAndSourceMaps(mapper) {
145
145
  }
146
146
  },
147
147
  getMapsBySourceFileUri(uri) {
148
- return this.getMapsBySourceFileName(shared.uriToFileName(uri));
148
+ return this.getMapsBySourceFileName(ctx.uriToFileName(uri));
149
149
  },
150
150
  getMapsBySourceFileName(fileName) {
151
151
  const source = mapper.getSource(fileName);
@@ -173,7 +173,7 @@ function createDocumentsAndSourceMaps(mapper) {
173
173
  }
174
174
  },
175
175
  getMapsByVirtualFileUri(virtualFileUri) {
176
- return this.getMapsByVirtualFileName(shared.uriToFileName(virtualFileUri));
176
+ return this.getMapsByVirtualFileName(ctx.uriToFileName(virtualFileUri));
177
177
  },
178
178
  *getMapsByVirtualFileName(virtualFileName) {
179
179
  var _a;
@@ -193,7 +193,7 @@ function createDocumentsAndSourceMaps(mapper) {
193
193
  }
194
194
  },
195
195
  getDocumentByUri(snapshot, uri) {
196
- return this.getDocumentByFileName(snapshot, shared.uriToFileName(uri));
196
+ return this.getDocumentByFileName(snapshot, ctx.uriToFileName(uri));
197
197
  },
198
198
  getDocumentByFileName,
199
199
  };
@@ -203,7 +203,7 @@ function createDocumentsAndSourceMaps(mapper) {
203
203
  }
204
204
  const map = _documents.get(snapshot);
205
205
  if (!map.has(fileName)) {
206
- map.set(fileName, vscode_languageserver_textdocument_1.TextDocument.create(shared.fileNameToUri(fileName), shared.syntaxToLanguageId(fileName.substring(fileName.lastIndexOf('.') + 1)), version++, snapshot.getText(0, snapshot.getLength())));
206
+ map.set(fileName, vscode_languageserver_textdocument_1.TextDocument.create(ctx.fileNameToUri(fileName), shared.syntaxToLanguageId(fileName.substring(fileName.lastIndexOf('.') + 1)), version++, snapshot.getText(0, snapshot.getLength())));
207
207
  }
208
208
  return map.get(fileName);
209
209
  }
@@ -131,7 +131,7 @@ function register(context) {
131
131
  if (!selectionRange)
132
132
  continue;
133
133
  const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(shared.notEmpty);
134
- const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === path_1.posix.basename(shared.uriToFileName(map.virtualFileDocument.uri)) ? path_1.posix.basename(shared.uriToFileName(map.sourceFileDocument.uri)) : tsItem.name, uri: map.sourceFileDocument.uri,
134
+ const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === path_1.posix.basename(context.uriToFileName(map.virtualFileDocument.uri)) ? path_1.posix.basename(context.uriToFileName(map.sourceFileDocument.uri)) : tsItem.name, uri: map.sourceFileDocument.uri,
135
135
  // TS Bug: `range: range` not works
136
136
  range: {
137
137
  start: range.start,
@@ -15,7 +15,7 @@ const vscode = require("vscode-languageserver-protocol");
15
15
  function register(context) {
16
16
  return (uri) => __awaiter(this, void 0, void 0, function* () {
17
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;
18
+ const referencesCodeLendsEnabled = (_b = yield ((_a = context.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.codeLens.references'))) !== null && _b !== void 0 ? _b : true;
19
19
  return (_c = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], (plugin, document) => __awaiter(this, void 0, void 0, function* () {
20
20
  var _d, _e, _f, _g;
21
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));
@@ -111,7 +111,7 @@ function register(context) {
111
111
  syntax_rules: { errors: [] },
112
112
  format_rules: { errors: [] },
113
113
  }).get(uri);
114
- const newSnapshot = context.host.getScriptSnapshot(shared.uriToFileName(uri));
114
+ const newSnapshot = context.host.getScriptSnapshot(context.uriToFileName(uri));
115
115
  let updateCacheRangeFailed = false;
116
116
  let errorsUpdated = false;
117
117
  let lastCheckCancelAt = 0;
package/out/types.d.ts CHANGED
@@ -7,25 +7,24 @@ import type { TextDocument } from 'vscode-languageserver-textdocument';
7
7
  import { URI } from 'vscode-uri';
8
8
  import { DocumentsAndSourceMaps } from './documents';
9
9
  export * from 'vscode-languageserver-protocol';
10
- export interface LanguageServicePluginContext {
10
+ export interface LanguageServiceOptions {
11
+ host: LanguageServiceHost;
11
12
  config: Config;
13
+ uriToFileName(uri: string): string;
14
+ fileNameToUri(fileName: string): string;
15
+ rootUri: URI;
16
+ locale?: string;
17
+ configurationHost?: ConfigurationHost;
18
+ documentContext?: DocumentContext;
19
+ fileSystemProvider?: FileSystemProvider;
20
+ schemaRequestService?: SchemaRequestService;
21
+ }
22
+ export interface LanguageServicePluginContext extends LanguageServiceOptions {
12
23
  typescript: {
13
24
  module: typeof import('typescript/lib/tsserverlibrary');
14
25
  languageServiceHost: ts.LanguageServiceHost;
15
26
  languageService: ts.LanguageService;
16
27
  } | undefined;
17
- env: {
18
- rootUri: URI;
19
- locale?: string;
20
- configurationHost?: ConfigurationHost;
21
- documentContext?: DocumentContext;
22
- fileSystemProvider?: FileSystemProvider;
23
- schemaRequestService?: SchemaRequestService;
24
- };
25
- uriToFileName(uri: string): string;
26
- fileNameToUri(fileName: string): string;
27
- /** @private */
28
- host: LanguageServiceHost;
29
28
  /** @private */
30
29
  core: LanguageContext;
31
30
  /** @private */
@@ -5,3 +5,4 @@ import { SourceMapWithDocuments } from '../documents';
5
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
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
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>;
8
+ export declare function safeCall<T>(cb: () => Promise<T> | T, errorMsg?: string): Promise<T | undefined>;
@@ -8,9 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.ruleWorker = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
11
+ exports.safeCall = exports.ruleWorker = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
12
12
  const definePlugin_1 = require("./definePlugin");
13
- const shared = require("@volar/shared");
14
13
  function documentFeatureWorker(context, uri, isValidSourceMap, worker, transform, combineResult) {
15
14
  return __awaiter(this, void 0, void 0, function* () {
16
15
  return languageFeatureWorker(context, uri, undefined, (_, map, file) => {
@@ -31,8 +30,8 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
31
30
  if (virtualFile) {
32
31
  yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () {
33
32
  for (const mappedArg of transformArg(arg, map, file)) {
34
- for (const plugin of Object.values(context.plugins)) {
35
- const embeddedResult = yield worker(plugin, map.virtualFileDocument, mappedArg, map, file);
33
+ for (const [pluginId, plugin] of Object.entries(context.plugins)) {
34
+ const embeddedResult = yield safeCall(() => worker(plugin, map.virtualFileDocument, mappedArg, map, file), 'plugin ' + pluginId + ' crashed on ' + map.virtualFileDocument.uri);
36
35
  if (!embeddedResult)
37
36
  continue;
38
37
  const result = transform(embeddedResult, map);
@@ -51,8 +50,8 @@ function languageFeatureWorker(context, uri, arg, transformArg, worker, transfor
51
50
  }));
52
51
  }
53
52
  else if (document) {
54
- for (const plugin of Object.values(context.plugins)) {
55
- const embeddedResult = yield worker(plugin, document, arg, undefined, undefined);
53
+ for (const [pluginId, plugin] of Object.entries(context.plugins)) {
54
+ const embeddedResult = yield safeCall(() => worker(plugin, document, arg, undefined, undefined), 'plugin ' + pluginId + ' crashed on ' + uri);
56
55
  if (!embeddedResult)
57
56
  continue;
58
57
  const result = transform(embeddedResult, undefined);
@@ -91,12 +90,12 @@ function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, comb
91
90
  let ruleCtx = {
92
91
  // project context
93
92
  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,
93
+ uriToFileName: context.uriToFileName,
94
+ fileNameToUri: context.fileNameToUri,
95
+ rootUri: context.rootUri,
96
+ locale: context.locale,
97
+ getConfiguration: (_m = context.configurationHost) === null || _m === void 0 ? void 0 : _m.getConfiguration,
98
+ onDidChangeConfiguration: (_o = context.configurationHost) === null || _o === void 0 ? void 0 : _o.onDidChangeConfiguration,
100
99
  settings: (_q = (_p = context.config.lint) === null || _p === void 0 ? void 0 : _p.settings) !== null && _q !== void 0 ? _q : {},
101
100
  // document context
102
101
  ruleId: '',
@@ -105,11 +104,16 @@ function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, comb
105
104
  };
106
105
  for (const plugin of Object.values(context.plugins)) {
107
106
  const fn = (_r = plugin.rules) === null || _r === void 0 ? void 0 : _r[api];
108
- if (fn) {
109
- ruleCtx = yield fn(ruleCtx);
107
+ try {
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
+ }
110
114
  }
111
- else if ((_s = plugin.rules) === null || _s === void 0 ? void 0 : _s.onAny) {
112
- ruleCtx = yield plugin.rules.onAny(ruleCtx);
115
+ catch (err) {
116
+ console.warn('plugin rule context setup crashed on ' + map.virtualFileDocument.uri + ': ' + err);
113
117
  }
114
118
  }
115
119
  for (const ruleName in (_t = context.config.lint) === null || _t === void 0 ? void 0 : _t.rules) {
@@ -118,7 +122,7 @@ function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, comb
118
122
  continue;
119
123
  }
120
124
  ruleCtx.ruleId = ruleName;
121
- const embeddedResult = yield worker(ruleName, rule, ruleCtx);
125
+ const embeddedResult = yield safeCall(() => worker(ruleName, rule, ruleCtx), 'rule ' + ruleName + ' crashed on ' + map.virtualFileDocument.uri);
122
126
  if (!embeddedResult)
123
127
  continue;
124
128
  const result = transform(embeddedResult, map);
@@ -139,12 +143,12 @@ function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, comb
139
143
  let ruleCtx = {
140
144
  // project context
141
145
  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,
146
+ uriToFileName: context.uriToFileName,
147
+ fileNameToUri: context.fileNameToUri,
148
+ rootUri: context.rootUri,
149
+ locale: context.locale,
150
+ getConfiguration: (_c = context.configurationHost) === null || _c === void 0 ? void 0 : _c.getConfiguration,
151
+ onDidChangeConfiguration: (_d = context.configurationHost) === null || _d === void 0 ? void 0 : _d.onDidChangeConfiguration,
148
152
  settings: (_f = (_e = context.config.lint) === null || _e === void 0 ? void 0 : _e.settings) !== null && _f !== void 0 ? _f : {},
149
153
  // document context
150
154
  ruleId: '',
@@ -153,11 +157,16 @@ function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, comb
153
157
  };
154
158
  for (const plugin of Object.values(context.plugins)) {
155
159
  const fn = (_g = plugin.rules) === null || _g === void 0 ? void 0 : _g[api];
156
- if (fn) {
157
- ruleCtx = yield fn(ruleCtx);
160
+ try {
161
+ if (fn) {
162
+ ruleCtx = yield fn(ruleCtx);
163
+ }
164
+ else if ((_h = plugin.rules) === null || _h === void 0 ? void 0 : _h.onAny) {
165
+ ruleCtx = yield plugin.rules.onAny(ruleCtx);
166
+ }
158
167
  }
159
- else if ((_h = plugin.rules) === null || _h === void 0 ? void 0 : _h.onAny) {
160
- ruleCtx = yield plugin.rules.onAny(ruleCtx);
168
+ catch (err) {
169
+ console.warn('plugin rule context setup crashed on ' + document.uri + ': ' + err);
161
170
  }
162
171
  }
163
172
  for (const ruleName in (_j = context.config.lint) === null || _j === void 0 ? void 0 : _j.rules) {
@@ -166,7 +175,7 @@ function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, comb
166
175
  continue;
167
176
  }
168
177
  ruleCtx.ruleId = ruleName;
169
- const embeddedResult = yield worker(ruleName, rule, ruleCtx);
178
+ const embeddedResult = yield safeCall(() => worker(ruleName, rule, ruleCtx), 'rule ' + ruleName + ' crashed on ' + document.uri);
170
179
  if (!embeddedResult)
171
180
  continue;
172
181
  const result = transform(embeddedResult, undefined);
@@ -190,4 +199,15 @@ function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, comb
190
199
  });
191
200
  }
192
201
  exports.ruleWorker = ruleWorker;
202
+ function safeCall(cb, errorMsg) {
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ try {
205
+ return yield cb();
206
+ }
207
+ catch (err) {
208
+ console.warn(errorMsg, err);
209
+ }
210
+ });
211
+ }
212
+ exports.safeCall = safeCall;
193
213
  //# sourceMappingURL=featureWorkers.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-service",
3
- "version": "1.3.0-alpha.0",
3
+ "version": "1.3.0-alpha.1",
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.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",
16
+ "@volar/language-core": "1.3.0-alpha.1",
17
+ "@volar/shared": "1.3.0-alpha.1",
18
+ "@volar/source-map": "1.3.0-alpha.1",
19
+ "@volar/typescript-faster": "1.3.0-alpha.1",
20
20
  "vscode-html-languageservice": "^5.0.4",
21
21
  "vscode-json-languageservice": "^5.2.0",
22
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": "7582403cc521d33f642183a32da44fb1f64e65ef"
26
+ "gitHead": "2926dc4af31890e01f6218773e88578ddf0de658"
27
27
  }
@@ -1,2 +0,0 @@
1
- import * as vscode from 'vscode-languageserver-protocol';
2
- export declare function transform<T extends vscode.SymbolInformation>(symbol: T, getOtherLocation: (location: vscode.Location) => vscode.Location | undefined): T | undefined;
@@ -1,10 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.transform = void 0;
3
- function transform(symbol, getOtherLocation) {
4
- const location = getOtherLocation(symbol.location);
5
- if (!location)
6
- return;
7
- return Object.assign(Object.assign({}, symbol), { location });
8
- }
9
- exports.transform = transform;
10
- //# sourceMappingURL=symbolInformation.js.map
@@ -1,2 +0,0 @@
1
- import * as vscode from 'vscode-languageserver-protocol';
2
- export declare function transform<T extends vscode.SymbolInformation>(locations: T[], getOtherLocation: (location: vscode.Location) => vscode.Location | undefined): T[];
@@ -1,11 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.transform = void 0;
3
- const shared = require("@volar/shared");
4
- const symbolInformation_1 = require("./symbolInformation");
5
- function transform(locations, getOtherLocation) {
6
- return locations
7
- .map(location => (0, symbolInformation_1.transform)(location, getOtherLocation))
8
- .filter(shared.notEmpty);
9
- }
10
- exports.transform = transform;
11
- //# sourceMappingURL=symbolInformations.js.map