@volar/language-server 1.4.0-alpha.0 → 1.4.0-alpha.2

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,12 +1,3 @@
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
1
  Object.defineProperty(exports, "__esModule", { value: true });
11
2
  exports.startCommonLanguageServer = void 0;
12
3
  const language_service_1 = require("@volar/language-service");
@@ -30,17 +21,16 @@ function startCommonLanguageServer(connection, getCtx) {
30
21
  let plugins;
31
22
  let documents;
32
23
  let context;
33
- connection.onInitialize((_params) => __awaiter(this, void 0, void 0, function* () {
34
- var _a, _b, _c, _d;
24
+ connection.onInitialize(async (_params) => {
35
25
  initParams = _params;
36
26
  options = initParams.initializationOptions;
37
27
  context = getCtx(options);
38
28
  plugins = context.plugins.map(plugin => plugin(options));
39
29
  documents = (0, documents_1.createDocuments)(context.runtimeEnv, connection);
40
30
  if (options.l10n) {
41
- yield l10n.config({ uri: options.l10n.location });
31
+ await l10n.config({ uri: options.l10n.location });
42
32
  }
43
- if (((_a = initParams.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.workspaceFolders) && initParams.workspaceFolders) {
33
+ if (initParams.capabilities.workspace?.workspaceFolders && initParams.workspaceFolders) {
44
34
  roots = initParams.workspaceFolders.map(folder => vscode_uri_1.URI.parse(folder.uri));
45
35
  }
46
36
  else if (initParams.rootUri) {
@@ -51,27 +41,30 @@ function startCommonLanguageServer(connection, getCtx) {
51
41
  }
52
42
  const result = {
53
43
  capabilities: {
54
- textDocumentSync: (_b = options.textDocumentSync) !== null && _b !== void 0 ? _b : vscode.TextDocumentSyncKind.Incremental,
44
+ textDocumentSync: options.textDocumentSync ?? vscode.TextDocumentSyncKind.Incremental,
55
45
  },
56
46
  };
57
- configurationHost = ((_c = initParams.capabilities.workspace) === null || _c === void 0 ? void 0 : _c.configuration) ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined;
47
+ configurationHost = initParams.capabilities.workspace?.configuration ? (0, configurationHost_1.createConfigurationHost)(initParams, connection) : undefined;
58
48
  let lsPlugins = {};
59
49
  const ts = options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
60
50
  for (const root of roots) {
61
51
  if (root.scheme === 'file') {
62
- let config = (_d = (0, serverConfig_1.loadConfig)(root.path, options.configFilePath)) !== null && _d !== void 0 ? _d : {};
52
+ let config = (0, serverConfig_1.loadConfig)(root.path, options.configFilePath) ?? {};
63
53
  for (const plugin of plugins) {
64
54
  if (plugin.resolveConfig) {
65
55
  config = plugin.resolveConfig(config, { typescript: ts });
66
56
  }
67
57
  }
68
58
  if (config.plugins) {
69
- lsPlugins = Object.assign(Object.assign({}, lsPlugins), config.plugins);
59
+ lsPlugins = {
60
+ ...lsPlugins,
61
+ ...config.plugins,
62
+ };
70
63
  }
71
64
  }
72
65
  }
73
66
  (0, registerFeatures_1.setupCapabilities)(result.capabilities, options, plugins, getSemanticTokensLegend(), lsPlugins);
74
- yield createLanguageServiceHost();
67
+ await createLanguageServiceHost();
75
68
  try {
76
69
  // show version on LSP logs
77
70
  const packageJson = require('../package.json');
@@ -80,26 +73,25 @@ function startCommonLanguageServer(connection, getCtx) {
80
73
  version: packageJson.version,
81
74
  };
82
75
  }
83
- catch (_e) { }
76
+ catch { }
84
77
  return result;
85
- }));
78
+ });
86
79
  connection.onInitialized(() => {
87
- var _a, _b, _c;
88
- fsHost === null || fsHost === void 0 ? void 0 : fsHost.ready(connection);
89
- configurationHost === null || configurationHost === void 0 ? void 0 : configurationHost.ready();
90
- if ((_a = initParams.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.workspaceFolders) {
80
+ fsHost?.ready(connection);
81
+ configurationHost?.ready();
82
+ if (initParams.capabilities.workspace?.workspaceFolders) {
91
83
  connection.workspace.onDidChangeWorkspaceFolders(e => {
92
84
  for (const folder of e.added) {
93
- projects === null || projects === void 0 ? void 0 : projects.add(vscode_uri_1.URI.parse(folder.uri));
85
+ projects?.add(vscode_uri_1.URI.parse(folder.uri));
94
86
  }
95
87
  for (const folder of e.removed) {
96
- projects === null || projects === void 0 ? void 0 : projects.remove(vscode_uri_1.URI.parse(folder.uri));
88
+ projects?.remove(vscode_uri_1.URI.parse(folder.uri));
97
89
  }
98
90
  });
99
91
  }
100
92
  if (options.serverMode !== types_1.ServerMode.Syntactic
101
93
  && !options.disableFileWatcher
102
- && ((_c = (_b = initParams.capabilities.workspace) === null || _b === void 0 ? void 0 : _b.didChangeWatchedFiles) === null || _c === void 0 ? void 0 : _c.dynamicRegistration)) {
94
+ && initParams.capabilities.workspace?.didChangeWatchedFiles?.dynamicRegistration) {
103
95
  const exts = plugins.map(plugin => plugin.watchFileExtensions).flat();
104
96
  if (exts.length) {
105
97
  connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
@@ -112,50 +104,44 @@ function startCommonLanguageServer(connection, getCtx) {
112
104
  }
113
105
  }
114
106
  });
115
- connection.onShutdown(() => __awaiter(this, void 0, void 0, function* () {
107
+ connection.onShutdown(async () => {
116
108
  if (projects) {
117
109
  for (const workspace of projects.workspaces) {
118
- (yield workspace[1]).dispose();
110
+ (await workspace[1]).dispose();
119
111
  }
120
112
  }
121
- }));
113
+ });
122
114
  connection.listen();
123
- function createLanguageServiceHost() {
124
- var _a;
125
- return __awaiter(this, void 0, void 0, function* () {
126
- const ts = options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
127
- fsHost = ts ? context.runtimeEnv.createFileSystemHost(ts, initParams.capabilities, context.runtimeEnv, options) : undefined;
128
- const tsLocalized = options.typescript && initParams.locale ? yield context.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
129
- const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
130
- const _projects = (0, workspaces_1.createWorkspaces)({
131
- server: context,
132
- fileSystemHost: fsHost,
133
- configurationHost,
134
- ts,
135
- tsLocalized,
136
- initParams: initParams,
137
- initOptions: options,
138
- documents,
139
- cancelTokenHost,
140
- plugins,
141
- });
142
- projects = _projects;
143
- for (const root of roots) {
144
- projects.add(root);
145
- }
146
- (yield Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects, context.runtimeEnv);
147
- (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv, documents);
148
- for (const plugin of plugins) {
149
- (_a = plugin.onInitialized) === null || _a === void 0 ? void 0 : _a.call(plugin, getLanguageService, context.runtimeEnv);
150
- }
151
- function getLanguageService(uri) {
152
- var _a;
153
- return __awaiter(this, void 0, void 0, function* () {
154
- const project = (_a = (yield projects.getProject(uri))) === null || _a === void 0 ? void 0 : _a.project;
155
- return project === null || project === void 0 ? void 0 : project.getLanguageService();
156
- });
157
- }
115
+ async function createLanguageServiceHost() {
116
+ const ts = options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
117
+ fsHost = ts ? context.runtimeEnv.createFileSystemHost(ts, initParams.capabilities, context.runtimeEnv, options) : undefined;
118
+ const tsLocalized = options.typescript && initParams.locale ? await context.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
119
+ const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
120
+ const _projects = (0, workspaces_1.createWorkspaces)({
121
+ server: context,
122
+ fileSystemHost: fsHost,
123
+ configurationHost,
124
+ ts,
125
+ tsLocalized,
126
+ initParams: initParams,
127
+ initOptions: options,
128
+ documents,
129
+ cancelTokenHost,
130
+ plugins,
158
131
  });
132
+ projects = _projects;
133
+ for (const root of roots) {
134
+ projects.add(root);
135
+ }
136
+ (await Promise.resolve().then(() => require('./features/customFeatures'))).register(connection, projects, context.runtimeEnv);
137
+ (await Promise.resolve().then(() => require('./features/languageFeatures'))).register(connection, projects, initParams, options, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv, documents);
138
+ for (const plugin of plugins) {
139
+ plugin.onInitialized?.(getLanguageService, context.runtimeEnv);
140
+ }
141
+ async function getLanguageService(uri) {
142
+ const project = (await projects.getProject(uri))?.project;
143
+ return project?.getLanguageService();
144
+ }
159
145
  }
160
146
  function getSemanticTokensLegend() {
161
147
  if (!options.semanticTokensLegend) {
@@ -1,71 +1,67 @@
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
1
  Object.defineProperty(exports, "__esModule", { value: true });
11
2
  exports.getInferredCompilerOptions = void 0;
12
- function getInferredCompilerOptions(configurationHost) {
13
- return __awaiter(this, void 0, void 0, function* () {
14
- let [implicitProjectConfig_1, implicitProjectConfig_2] = yield Promise.all([
15
- configurationHost === null || configurationHost === void 0 ? void 0 : configurationHost.getConfiguration('js/ts.implicitProjectConfig'),
16
- configurationHost === null || configurationHost === void 0 ? void 0 : configurationHost.getConfiguration('javascript.implicitProjectConfig'),
17
- ]);
18
- implicitProjectConfig_1 = implicitProjectConfig_1 !== null && implicitProjectConfig_1 !== void 0 ? implicitProjectConfig_1 : {};
19
- implicitProjectConfig_2 = implicitProjectConfig_2 !== null && implicitProjectConfig_2 !== void 0 ? implicitProjectConfig_2 : {};
20
- const checkJs = readCheckJs();
21
- const experimentalDecorators = readExperimentalDecorators();
22
- const strictNullChecks = readImplicitStrictNullChecks();
23
- const strictFunctionTypes = readImplicitStrictFunctionTypes();
24
- const options = Object.assign(Object.assign({}, inferredProjectCompilerOptions('typescript')), { allowJs: true, allowSyntheticDefaultImports: true, allowNonTsExtensions: true, resolveJsonModule: true, jsx: 1 /* ts.JsxEmit.Preserve */ });
25
- return options;
26
- function readCheckJs() {
27
- var _a, _b;
28
- return (_b = (_a = implicitProjectConfig_1['checkJs']) !== null && _a !== void 0 ? _a : implicitProjectConfig_2['checkJs']) !== null && _b !== void 0 ? _b : false;
3
+ async function getInferredCompilerOptions(configurationHost) {
4
+ let [implicitProjectConfig_1, implicitProjectConfig_2] = await Promise.all([
5
+ configurationHost?.getConfiguration('js/ts.implicitProjectConfig'),
6
+ configurationHost?.getConfiguration('javascript.implicitProjectConfig'),
7
+ ]);
8
+ implicitProjectConfig_1 = implicitProjectConfig_1 ?? {};
9
+ implicitProjectConfig_2 = implicitProjectConfig_2 ?? {};
10
+ const checkJs = readCheckJs();
11
+ const experimentalDecorators = readExperimentalDecorators();
12
+ const strictNullChecks = readImplicitStrictNullChecks();
13
+ const strictFunctionTypes = readImplicitStrictFunctionTypes();
14
+ const options = {
15
+ ...inferredProjectCompilerOptions('typescript'),
16
+ allowJs: true,
17
+ allowSyntheticDefaultImports: true,
18
+ allowNonTsExtensions: true,
19
+ resolveJsonModule: true,
20
+ jsx: 1 /* ts.JsxEmit.Preserve */,
21
+ };
22
+ return options;
23
+ function readCheckJs() {
24
+ return implicitProjectConfig_1['checkJs']
25
+ ?? implicitProjectConfig_2['checkJs']
26
+ ?? false;
27
+ }
28
+ function readExperimentalDecorators() {
29
+ return implicitProjectConfig_1['experimentalDecorators']
30
+ ?? implicitProjectConfig_2['experimentalDecorators']
31
+ ?? false;
32
+ }
33
+ function readImplicitStrictNullChecks() {
34
+ return implicitProjectConfig_1['strictNullChecks'] ?? false;
35
+ }
36
+ function readImplicitStrictFunctionTypes() {
37
+ return implicitProjectConfig_1['strictFunctionTypes'] ?? true;
38
+ }
39
+ function inferredProjectCompilerOptions(projectType) {
40
+ const projectConfig = {
41
+ module: 1 /* ts.ModuleKind.CommonJS */,
42
+ target: 7 /* ts.ScriptTarget.ES2020 */,
43
+ jsx: 1 /* ts.JsxEmit.Preserve */,
44
+ };
45
+ if (checkJs) {
46
+ projectConfig.checkJs = true;
47
+ if (projectType === 'typescript') {
48
+ projectConfig.allowJs = true;
49
+ }
29
50
  }
30
- function readExperimentalDecorators() {
31
- var _a, _b;
32
- return (_b = (_a = implicitProjectConfig_1['experimentalDecorators']) !== null && _a !== void 0 ? _a : implicitProjectConfig_2['experimentalDecorators']) !== null && _b !== void 0 ? _b : false;
51
+ if (experimentalDecorators) {
52
+ projectConfig.experimentalDecorators = true;
33
53
  }
34
- function readImplicitStrictNullChecks() {
35
- var _a;
36
- return (_a = implicitProjectConfig_1['strictNullChecks']) !== null && _a !== void 0 ? _a : false;
54
+ if (strictNullChecks) {
55
+ projectConfig.strictNullChecks = true;
37
56
  }
38
- function readImplicitStrictFunctionTypes() {
39
- var _a;
40
- return (_a = implicitProjectConfig_1['strictFunctionTypes']) !== null && _a !== void 0 ? _a : true;
57
+ if (strictFunctionTypes) {
58
+ projectConfig.strictFunctionTypes = true;
41
59
  }
42
- function inferredProjectCompilerOptions(projectType) {
43
- const projectConfig = {
44
- module: 1 /* ts.ModuleKind.CommonJS */,
45
- target: 7 /* ts.ScriptTarget.ES2020 */,
46
- jsx: 1 /* ts.JsxEmit.Preserve */,
47
- };
48
- if (checkJs) {
49
- projectConfig.checkJs = true;
50
- if (projectType === 'typescript') {
51
- projectConfig.allowJs = true;
52
- }
53
- }
54
- if (experimentalDecorators) {
55
- projectConfig.experimentalDecorators = true;
56
- }
57
- if (strictNullChecks) {
58
- projectConfig.strictNullChecks = true;
59
- }
60
- if (strictFunctionTypes) {
61
- projectConfig.strictFunctionTypes = true;
62
- }
63
- if (projectType === 'typescript') {
64
- projectConfig.sourceMap = true;
65
- }
66
- return projectConfig;
60
+ if (projectType === 'typescript') {
61
+ projectConfig.sourceMap = true;
67
62
  }
68
- });
63
+ return projectConfig;
64
+ }
69
65
  }
70
66
  exports.getInferredCompilerOptions = getInferredCompilerOptions;
71
67
  //# sourceMappingURL=inferredCompilerOptions.js.map
@@ -4,7 +4,6 @@ const embedded = require("@volar/language-service");
4
4
  const types_1 = require("../../types");
5
5
  const vscode = require("vscode-languageserver");
6
6
  function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, lsPlugins) {
7
- var _a, _b, _c;
8
7
  const lsPluginInstances = Object.values(lsPlugins)
9
8
  .map(plugin => typeof plugin === 'function' ? plugin() : plugin)
10
9
  .filter((plugin) => !!plugin);
@@ -16,7 +15,7 @@ function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, l
16
15
  server.documentSymbolProvider = true;
17
16
  server.documentFormattingProvider = true;
18
17
  server.documentRangeFormattingProvider = true;
19
- const characters = [...new Set(lsPluginInstances.map(plugin => { var _a; return (_a = plugin.autoFormatTriggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat())];
18
+ const characters = [...new Set(lsPluginInstances.map(plugin => plugin.autoFormatTriggerCharacters ?? []).flat())];
20
19
  if (characters.length) {
21
20
  server.documentOnTypeFormattingProvider = {
22
21
  firstTriggerCharacter: characters[0],
@@ -35,15 +34,16 @@ function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, l
35
34
  prepareProvider: true,
36
35
  };
37
36
  server.signatureHelpProvider = {
38
- triggerCharacters: [...new Set(lsPluginInstances.map(plugin => { var _a; return (_a = plugin.signatureHelpTriggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat())],
39
- retriggerCharacters: [...new Set(lsPluginInstances.map(plugin => { var _a; return (_a = plugin.signatureHelpRetriggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat())],
37
+ triggerCharacters: [...new Set(lsPluginInstances.map(plugin => plugin.signatureHelpTriggerCharacters ?? []).flat())],
38
+ retriggerCharacters: [...new Set(lsPluginInstances.map(plugin => plugin.signatureHelpRetriggerCharacters ?? []).flat())],
40
39
  };
41
40
  server.completionProvider = {
42
- triggerCharacters: [...new Set(lsPluginInstances.map(plugin => { var _a; return (_a = plugin.triggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat())],
41
+ triggerCharacters: [...new Set(lsPluginInstances.map(plugin => plugin.triggerCharacters ?? []).flat())],
43
42
  resolveProvider: true,
44
43
  };
45
44
  if (initOptions.ignoreTriggerCharacters) {
46
- server.completionProvider.triggerCharacters = (_a = server.completionProvider.triggerCharacters) === null || _a === void 0 ? void 0 : _a.filter(c => !initOptions.ignoreTriggerCharacters.includes(c));
45
+ server.completionProvider.triggerCharacters = server.completionProvider.triggerCharacters
46
+ ?.filter(c => !initOptions.ignoreTriggerCharacters.includes(c));
47
47
  }
48
48
  server.documentHighlightProvider = true;
49
49
  server.documentLinkProvider = {
@@ -52,7 +52,7 @@ function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, l
52
52
  server.codeLensProvider = {
53
53
  resolveProvider: true,
54
54
  };
55
- (_b = server.executeCommandProvider) !== null && _b !== void 0 ? _b : (server.executeCommandProvider = { commands: [] });
55
+ server.executeCommandProvider ??= { commands: [] };
56
56
  server.executeCommandProvider.commands.push(embedded.showReferencesCommand);
57
57
  server.semanticTokensProvider = {
58
58
  range: true,
@@ -93,7 +93,7 @@ function setupCapabilities(server, initOptions, plugins, semanticTokensLegend, l
93
93
  server.workspaceSymbolProvider = true;
94
94
  }
95
95
  // diagnostics are shunted in the api
96
- if (((_c = initOptions.diagnosticModel) !== null && _c !== void 0 ? _c : types_1.DiagnosticModel.Push) === types_1.DiagnosticModel.Pull) {
96
+ if ((initOptions.diagnosticModel ?? types_1.DiagnosticModel.Push) === types_1.DiagnosticModel.Pull) {
97
97
  server.diagnosticProvider = {
98
98
  interFileDependencies: true,
99
99
  workspaceDiagnostics: false,
@@ -3,9 +3,9 @@ exports.loadConfig = void 0;
3
3
  function loadConfig(dir, configFile) {
4
4
  let configPath;
5
5
  try {
6
- configPath = require.resolve(configFile !== null && configFile !== void 0 ? configFile : './volar.config.js', { paths: [dir] });
6
+ configPath = require.resolve(configFile ?? './volar.config.js', { paths: [dir] });
7
7
  }
8
- catch (_a) { }
8
+ catch { }
9
9
  try {
10
10
  if (configPath) {
11
11
  const config = require(configPath);
@@ -64,7 +64,7 @@ function normalizeUri(uri) {
64
64
  try {
65
65
  return vscode_uri_1.URI.parse(uri).toString();
66
66
  }
67
- catch (_a) {
67
+ catch {
68
68
  return '';
69
69
  }
70
70
  }