@volar/language-server 1.0.24 → 1.1.0-1.2.0-alpha.1.0

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.
@@ -170,8 +170,8 @@ function createWebFileSystemHost() {
170
170
  function statAsync(connection, fsPath, dir) {
171
171
  return __awaiter(this, void 0, void 0, function* () {
172
172
  const uri = shared.fileNameToUri(fsPath);
173
- if (uri.startsWith('https://cdn.jsdelivr.net/npm/')) { // stat request always response file type for jsdelivr
174
- const text = yield readJsdelivrFile(connection, uri);
173
+ if (uri.startsWith('https://unpkg.com/')) { // stat request always response file type for jsdelivr
174
+ const text = yield readWebFile(connection, uri);
175
175
  if (text !== undefined) {
176
176
  const name = path.basename(fsPath);
177
177
  dir.fileTypes.set(name, vscode_html_languageservice_1.FileType.File);
@@ -198,8 +198,8 @@ function createWebFileSystemHost() {
198
198
  function readFileAsync(connection, fsPath, dir) {
199
199
  return __awaiter(this, void 0, void 0, function* () {
200
200
  const uri = shared.fileNameToUri(fsPath);
201
- if (uri.startsWith('https://cdn.jsdelivr.net/npm/')) {
202
- const text = yield readJsdelivrFile(connection, uri);
201
+ if (uri.startsWith('https://unpkg.com/')) {
202
+ const text = yield readWebFile(connection, uri);
203
203
  if (text !== undefined) {
204
204
  const name = path.basename(fsPath);
205
205
  dir.fileTexts.set(name, text);
@@ -222,17 +222,12 @@ function createWebFileSystemHost() {
222
222
  }
223
223
  });
224
224
  }
225
- function readJsdelivrFile(connection, uri) {
225
+ function readWebFile(connection, uri) {
226
226
  var _a;
227
227
  return __awaiter(this, void 0, void 0, function* () {
228
228
  // ignore .js because it's no help for intellisense
229
229
  if (uri.endsWith('.d.ts') || uri.endsWith('.json')) {
230
- const text = (_a = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri)) !== null && _a !== void 0 ? _a : undefined;
231
- if (text !== undefined
232
- // ignore https://cdn.jsdelivr.net/npm/@vue/runtime-dom
233
- && text.indexOf('Minified by jsDelivr') === -1) {
234
- return text;
235
- }
230
+ return (_a = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri)) !== null && _a !== void 0 ? _a : undefined;
236
231
  }
237
232
  });
238
233
  }
@@ -263,7 +258,7 @@ function createWebFileSystemHost() {
263
258
  while (pendings.length) {
264
259
  const current = pendings.shift();
265
260
  progress === null || progress === void 0 ? void 0 : progress.report(i / pendings.length, vscode_uri_1.URI.parse(shared.fileNameToUri(current[1])).fsPath);
266
- yield current;
261
+ yield current[2];
267
262
  i++;
268
263
  }
269
264
  progress === null || progress === void 0 ? void 0 : progress.done();
@@ -24,7 +24,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.startLanguageServer = exports.createConnection = void 0;
26
26
  const request_light_1 = require("request-light");
27
- const ts = require("typescript/lib/tsserverlibrary"); // bundle typescript lib in web
28
27
  const vscode = require("vscode-languageserver/browser");
29
28
  const server_1 = require("../common/server");
30
29
  const http_1 = require("../common/schemaRequestHandlers/http");
@@ -43,8 +42,14 @@ function startLanguageServer(connection, ...plugins) {
43
42
  plugins,
44
43
  connection,
45
44
  runtimeEnv: {
45
+ timer: {
46
+ setImmediate(callback, ...args) {
47
+ const handle = setTimeout(callback, 0, ...args);
48
+ return { dispose: () => clearTimeout(handle) };
49
+ },
50
+ },
46
51
  loadTypescript() {
47
- return ts; // not support load by user config in web
52
+ return require('typescript'); // force bundle because not support load by user config in web
48
53
  },
49
54
  loadTypescriptLocalized(tsdk, locale) {
50
55
  return __awaiter(this, void 0, void 0, function* () {
@@ -17,6 +17,7 @@ declare class IncrementalScriptSnapshot {
17
17
  changes: IncrementalScriptSnapshotChange[];
18
18
  constructor(uri: string, languageId: string, version: number, text: string);
19
19
  get version(): number;
20
+ get languageId(): string;
20
21
  update(params: vscode.DidChangeTextDocumentParams): void;
21
22
  getSnapshot(): ts.IScriptSnapshot;
22
23
  getDocument(): TextDocument;
@@ -20,6 +20,9 @@ class IncrementalScriptSnapshot {
20
20
  get version() {
21
21
  return this.changes[this.changes.length - 1].version;
22
22
  }
23
+ get languageId() {
24
+ return this.document.languageId;
25
+ }
23
26
  update(params) {
24
27
  vscode_languageserver_textdocument_1.TextDocument.update(this.document, params.contentChanges, params.textDocument.version);
25
28
  this.changes = [
@@ -78,7 +78,7 @@ function register(connection, projects) {
78
78
  const rootVirtualFile = (_q = (_p = project.project) === null || _p === void 0 ? void 0 : _p.getLanguageService().context.core.virtualFiles.getSource(shared.uriToFileName(document.uri))) === null || _q === void 0 ? void 0 : _q.root;
79
79
  if (rootVirtualFile) {
80
80
  (0, language_core_1.forEachEmbeddedFile)(rootVirtualFile, e => {
81
- if (e.snapshot.getLength() && e.kind === 1) {
81
+ if (e.snapshot.getLength() && e.kind === language_core_1.FileKind.TypeScriptHostFile) {
82
82
  fileNames.push(e.fileName);
83
83
  }
84
84
  });
@@ -1,4 +1,5 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
2
  import { CancellationTokenHost } from '../cancellationPipe';
3
3
  import type { Workspaces } from '../workspaces';
4
- export declare function register(connection: vscode.Connection, projects: Workspaces, initParams: vscode.InitializeParams, cancelHost: CancellationTokenHost, semanticTokensLegend: vscode.SemanticTokensLegend): void;
4
+ import { RuntimeEnvironment } from '../../types';
5
+ export declare function register(connection: vscode.Connection, projects: Workspaces, initParams: vscode.InitializeParams, cancelHost: CancellationTokenHost, semanticTokensLegend: vscode.SemanticTokensLegend, runtime: RuntimeEnvironment): void;
@@ -13,59 +13,59 @@ const embedded = require("@volar/language-service");
13
13
  const vscode = require("vscode-languageserver");
14
14
  const protocol_1 = require("../../protocol");
15
15
  const shared = require("@volar/shared");
16
- function register(connection, projects, initParams, cancelHost, semanticTokensLegend) {
16
+ function register(connection, projects, initParams, cancelHost, semanticTokensLegend, runtime) {
17
17
  let lastCompleteUri;
18
18
  let lastCompleteLs;
19
19
  let lastCodeLensLs;
20
20
  let lastCodeActionLs;
21
21
  let lastCallHierarchyLs;
22
- connection.onDocumentFormatting((params) => __awaiter(this, void 0, void 0, function* () {
23
- return worker(params.textDocument.uri, vueLs => {
22
+ connection.onDocumentFormatting((params, token) => __awaiter(this, void 0, void 0, function* () {
23
+ return worker(params.textDocument.uri, token, vueLs => {
24
24
  return vueLs.format(params.textDocument.uri, params.options);
25
25
  });
26
26
  }));
27
- connection.onDocumentRangeFormatting((params) => __awaiter(this, void 0, void 0, function* () {
28
- return worker(params.textDocument.uri, vueLs => {
27
+ connection.onDocumentRangeFormatting((params, token) => __awaiter(this, void 0, void 0, function* () {
28
+ return worker(params.textDocument.uri, token, vueLs => {
29
29
  return vueLs.format(params.textDocument.uri, params.options, params.range);
30
30
  });
31
31
  }));
32
- connection.onDocumentOnTypeFormatting((params) => __awaiter(this, void 0, void 0, function* () {
33
- return worker(params.textDocument.uri, vueLs => {
32
+ connection.onDocumentOnTypeFormatting((params, token) => __awaiter(this, void 0, void 0, function* () {
33
+ return worker(params.textDocument.uri, token, vueLs => {
34
34
  return vueLs.format(params.textDocument.uri, params.options, undefined, params);
35
35
  });
36
36
  }));
37
- connection.onSelectionRanges((params) => __awaiter(this, void 0, void 0, function* () {
38
- return worker(params.textDocument.uri, vueLs => {
37
+ connection.onSelectionRanges((params, token) => __awaiter(this, void 0, void 0, function* () {
38
+ return worker(params.textDocument.uri, token, vueLs => {
39
39
  return vueLs.getSelectionRanges(params.textDocument.uri, params.positions);
40
40
  });
41
41
  }));
42
- connection.onFoldingRanges((params) => __awaiter(this, void 0, void 0, function* () {
43
- return worker(params.textDocument.uri, vueLs => {
42
+ connection.onFoldingRanges((params, token) => __awaiter(this, void 0, void 0, function* () {
43
+ return worker(params.textDocument.uri, token, vueLs => {
44
44
  return vueLs.getFoldingRanges(params.textDocument.uri);
45
45
  });
46
46
  }));
47
- connection.languages.onLinkedEditingRange((params) => __awaiter(this, void 0, void 0, function* () {
48
- return worker(params.textDocument.uri, vueLs => {
47
+ connection.languages.onLinkedEditingRange((params, token) => __awaiter(this, void 0, void 0, function* () {
48
+ return worker(params.textDocument.uri, token, vueLs => {
49
49
  return vueLs.findLinkedEditingRanges(params.textDocument.uri, params.position);
50
50
  });
51
51
  }));
52
- connection.onDocumentSymbol((params) => __awaiter(this, void 0, void 0, function* () {
53
- return worker(params.textDocument.uri, vueLs => {
52
+ connection.onDocumentSymbol((params, token) => __awaiter(this, void 0, void 0, function* () {
53
+ return worker(params.textDocument.uri, token, vueLs => {
54
54
  return vueLs.findDocumentSymbols(params.textDocument.uri);
55
55
  });
56
56
  }));
57
- connection.onDocumentColor((params) => __awaiter(this, void 0, void 0, function* () {
58
- return worker(params.textDocument.uri, vueLs => {
57
+ connection.onDocumentColor((params, token) => __awaiter(this, void 0, void 0, function* () {
58
+ return worker(params.textDocument.uri, token, vueLs => {
59
59
  return vueLs.findDocumentColors(params.textDocument.uri);
60
60
  });
61
61
  }));
62
- connection.onColorPresentation((params) => __awaiter(this, void 0, void 0, function* () {
63
- return worker(params.textDocument.uri, vueLs => {
62
+ connection.onColorPresentation((params, token) => __awaiter(this, void 0, void 0, function* () {
63
+ return worker(params.textDocument.uri, token, vueLs => {
64
64
  return vueLs.getColorPresentations(params.textDocument.uri, params.color, params.range);
65
65
  });
66
66
  }));
67
- connection.onCompletion((params) => __awaiter(this, void 0, void 0, function* () {
68
- return worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
67
+ connection.onCompletion((params, token) => __awaiter(this, void 0, void 0, function* () {
68
+ return worker(params.textDocument.uri, token, (vueLs) => __awaiter(this, void 0, void 0, function* () {
69
69
  lastCompleteUri = params.textDocument.uri;
70
70
  lastCompleteLs = vueLs;
71
71
  const list = yield vueLs.doComplete(params.textDocument.uri, params.position, params.context);
@@ -84,28 +84,28 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
84
84
  }
85
85
  return item;
86
86
  }));
87
- connection.onHover((params) => __awaiter(this, void 0, void 0, function* () {
88
- return worker(params.textDocument.uri, vueLs => {
87
+ connection.onHover((params, token) => __awaiter(this, void 0, void 0, function* () {
88
+ return worker(params.textDocument.uri, token, vueLs => {
89
89
  return vueLs.doHover(params.textDocument.uri, params.position);
90
90
  });
91
91
  }));
92
- connection.onSignatureHelp((params) => __awaiter(this, void 0, void 0, function* () {
93
- return worker(params.textDocument.uri, vueLs => {
92
+ connection.onSignatureHelp((params, token) => __awaiter(this, void 0, void 0, function* () {
93
+ return worker(params.textDocument.uri, token, vueLs => {
94
94
  return vueLs.getSignatureHelp(params.textDocument.uri, params.position, params.context);
95
95
  });
96
96
  }));
97
- connection.onPrepareRename((params) => __awaiter(this, void 0, void 0, function* () {
98
- return worker(params.textDocument.uri, vueLs => {
97
+ connection.onPrepareRename((params, token) => __awaiter(this, void 0, void 0, function* () {
98
+ return worker(params.textDocument.uri, token, vueLs => {
99
99
  return vueLs.prepareRename(params.textDocument.uri, params.position);
100
100
  });
101
101
  }));
102
- connection.onRenameRequest((params) => __awaiter(this, void 0, void 0, function* () {
103
- return worker(params.textDocument.uri, vueLs => {
102
+ connection.onRenameRequest((params, token) => __awaiter(this, void 0, void 0, function* () {
103
+ return worker(params.textDocument.uri, token, vueLs => {
104
104
  return vueLs.doRename(params.textDocument.uri, params.position, params.newName);
105
105
  });
106
106
  }));
107
- connection.onCodeLens((params) => __awaiter(this, void 0, void 0, function* () {
108
- return worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
107
+ connection.onCodeLens((params, token) => __awaiter(this, void 0, void 0, function* () {
108
+ return worker(params.textDocument.uri, token, (vueLs) => __awaiter(this, void 0, void 0, function* () {
109
109
  lastCodeLensLs = vueLs;
110
110
  return vueLs.doCodeLens(params.textDocument.uri);
111
111
  }));
@@ -120,7 +120,7 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
120
120
  if (!args) {
121
121
  return;
122
122
  }
123
- return worker(args[0], vueLs => {
123
+ return worker(args[0], token, vueLs => {
124
124
  return vueLs.doExecuteCommand(params.command, args, {
125
125
  token,
126
126
  workDoneProgress,
@@ -130,8 +130,8 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
130
130
  });
131
131
  }
132
132
  }));
133
- connection.onCodeAction((params) => __awaiter(this, void 0, void 0, function* () {
134
- return worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
133
+ connection.onCodeAction((params, token) => __awaiter(this, void 0, void 0, function* () {
134
+ return worker(params.textDocument.uri, token, (vueLs) => __awaiter(this, void 0, void 0, function* () {
135
135
  var _b, _c, _d;
136
136
  lastCodeActionLs = vueLs;
137
137
  let codeActions = (_b = yield vueLs.doCodeActions(params.textDocument.uri, params.range, params.context)) !== null && _b !== void 0 ? _b : [];
@@ -153,38 +153,38 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
153
153
  var _e;
154
154
  return (_e = yield lastCodeActionLs.doCodeActionResolve(codeAction)) !== null && _e !== void 0 ? _e : codeAction;
155
155
  }));
156
- connection.onReferences((params) => __awaiter(this, void 0, void 0, function* () {
157
- return worker(params.textDocument.uri, vueLs => {
156
+ connection.onReferences((params, token) => __awaiter(this, void 0, void 0, function* () {
157
+ return worker(params.textDocument.uri, token, vueLs => {
158
158
  return vueLs.findReferences(params.textDocument.uri, params.position);
159
159
  });
160
160
  }));
161
- connection.onRequest(protocol_1.FindFileReferenceRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
162
- return worker(params.textDocument.uri, vueLs => {
161
+ connection.onRequest(protocol_1.FindFileReferenceRequest.type, (params, token) => __awaiter(this, void 0, void 0, function* () {
162
+ return worker(params.textDocument.uri, token, vueLs => {
163
163
  return vueLs.findFileReferences(params.textDocument.uri);
164
164
  });
165
165
  }));
166
- connection.onImplementation((params) => __awaiter(this, void 0, void 0, function* () {
167
- return worker(params.textDocument.uri, vueLs => {
166
+ connection.onImplementation((params, token) => __awaiter(this, void 0, void 0, function* () {
167
+ return worker(params.textDocument.uri, token, vueLs => {
168
168
  return vueLs.findImplementations(params.textDocument.uri, params.position);
169
169
  });
170
170
  }));
171
- connection.onDefinition((params) => __awaiter(this, void 0, void 0, function* () {
172
- return worker(params.textDocument.uri, vueLs => {
171
+ connection.onDefinition((params, token) => __awaiter(this, void 0, void 0, function* () {
172
+ return worker(params.textDocument.uri, token, vueLs => {
173
173
  return vueLs.findDefinition(params.textDocument.uri, params.position);
174
174
  });
175
175
  }));
176
- connection.onTypeDefinition((params) => __awaiter(this, void 0, void 0, function* () {
177
- return worker(params.textDocument.uri, vueLs => {
176
+ connection.onTypeDefinition((params, token) => __awaiter(this, void 0, void 0, function* () {
177
+ return worker(params.textDocument.uri, token, vueLs => {
178
178
  return vueLs.findTypeDefinition(params.textDocument.uri, params.position);
179
179
  });
180
180
  }));
181
- connection.onDocumentHighlight((params) => __awaiter(this, void 0, void 0, function* () {
182
- return worker(params.textDocument.uri, vueLs => {
181
+ connection.onDocumentHighlight((params, token) => __awaiter(this, void 0, void 0, function* () {
182
+ return worker(params.textDocument.uri, token, vueLs => {
183
183
  return vueLs.findDocumentHighlights(params.textDocument.uri, params.position);
184
184
  });
185
185
  }));
186
- connection.onDocumentLinks((params) => __awaiter(this, void 0, void 0, function* () {
187
- return worker(params.textDocument.uri, vueLs => {
186
+ connection.onDocumentLinks((params, token) => __awaiter(this, void 0, void 0, function* () {
187
+ return worker(params.textDocument.uri, token, vueLs => {
188
188
  return vueLs.findDocumentLinks(params.textDocument.uri);
189
189
  });
190
190
  }));
@@ -203,9 +203,9 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
203
203
  }
204
204
  return results;
205
205
  }));
206
- connection.languages.callHierarchy.onPrepare((params) => __awaiter(this, void 0, void 0, function* () {
206
+ connection.languages.callHierarchy.onPrepare((params, token) => __awaiter(this, void 0, void 0, function* () {
207
207
  var _f;
208
- return (_f = yield worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
208
+ return (_f = yield worker(params.textDocument.uri, token, (vueLs) => __awaiter(this, void 0, void 0, function* () {
209
209
  lastCallHierarchyLs = vueLs;
210
210
  return vueLs.callHierarchy.doPrepare(params.textDocument.uri, params.position);
211
211
  }))) !== null && _f !== void 0 ? _f : [];
@@ -221,9 +221,7 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
221
221
  connection.languages.semanticTokens.on((params, token, _, resultProgress) => __awaiter(this, void 0, void 0, function* () {
222
222
  var _j;
223
223
  yield shared.sleep(200);
224
- if (token.isCancellationRequested)
225
- return buildTokens([]);
226
- return (_j = yield worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
224
+ return (_j = yield worker(params.textDocument.uri, token, (vueLs) => __awaiter(this, void 0, void 0, function* () {
227
225
  var _k;
228
226
  const result = (_k = yield (vueLs === null || vueLs === void 0 ? void 0 : vueLs.getSemanticTokens(params.textDocument.uri, undefined, semanticTokensLegend, token, tokens => resultProgress === null || resultProgress === void 0 ? void 0 : resultProgress.report(buildTokens(tokens))))) !== null && _k !== void 0 ? _k : [];
229
227
  return buildTokens(result);
@@ -232,18 +230,16 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
232
230
  connection.languages.semanticTokens.onRange((params, token, _, resultProgress) => __awaiter(this, void 0, void 0, function* () {
233
231
  var _l;
234
232
  yield shared.sleep(200);
235
- if (token.isCancellationRequested)
236
- return buildTokens([]);
237
- return (_l = yield worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
233
+ return (_l = yield worker(params.textDocument.uri, token, (vueLs) => __awaiter(this, void 0, void 0, function* () {
238
234
  var _m;
239
235
  const result = (_m = yield (vueLs === null || vueLs === void 0 ? void 0 : vueLs.getSemanticTokens(params.textDocument.uri, params.range, semanticTokensLegend, token, tokens => resultProgress === null || resultProgress === void 0 ? void 0 : resultProgress.report(buildTokens(tokens))))) !== null && _m !== void 0 ? _m : [];
240
236
  return buildTokens(result);
241
237
  }))) !== null && _l !== void 0 ? _l : buildTokens([]);
242
238
  }));
243
239
  connection.languages.diagnostics.on((params, token, _workDoneProgressReporter, resultProgressReporter) => __awaiter(this, void 0, void 0, function* () {
244
- token = cancelHost.createCancellationToken(token);
245
- const result = yield worker(params.textDocument.uri, vueLs => {
246
- return vueLs.doValidation(params.textDocument.uri, token, errors => {
240
+ const result = yield worker(params.textDocument.uri, token, vueLs => {
241
+ const tsToken = cancelHost.createCancellationToken(token);
242
+ return vueLs.doValidation(params.textDocument.uri, tsToken, errors => {
247
243
  // resultProgressReporter is undefined in vscode
248
244
  resultProgressReporter === null || resultProgressReporter === void 0 ? void 0 : resultProgressReporter.report({
249
245
  relatedDocuments: {
@@ -260,20 +256,20 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
260
256
  items: result !== null && result !== void 0 ? result : [],
261
257
  };
262
258
  }));
263
- connection.languages.inlayHint.on((params) => __awaiter(this, void 0, void 0, function* () {
264
- return worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
259
+ connection.languages.inlayHint.on((params, token) => __awaiter(this, void 0, void 0, function* () {
260
+ return worker(params.textDocument.uri, token, (vueLs) => __awaiter(this, void 0, void 0, function* () {
265
261
  return vueLs.getInlayHints(params.textDocument.uri, params.range);
266
262
  }));
267
263
  }));
268
264
  // TODO: connection.languages.inlayHint.resolve
269
- connection.workspace.onWillRenameFiles((params) => __awaiter(this, void 0, void 0, function* () {
265
+ connection.workspace.onWillRenameFiles((params, token) => __awaiter(this, void 0, void 0, function* () {
270
266
  const config = yield connection.workspace.getConfiguration('volar.updateImportsOnFileMove.enabled');
271
267
  if (!config) {
272
268
  return null;
273
269
  }
274
270
  const _edits = yield Promise.all(params.files.map((file) => __awaiter(this, void 0, void 0, function* () {
275
271
  var _o;
276
- return (_o = yield worker(file.oldUri, vueLs => {
272
+ return (_o = yield worker(file.oldUri, token, vueLs => {
277
273
  var _a;
278
274
  return (_a = vueLs.getEditsForFileRename(file.oldUri, file.newUri)) !== null && _a !== void 0 ? _a : null;
279
275
  })) !== null && _o !== void 0 ? _o : null;
@@ -285,22 +281,37 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
285
281
  }
286
282
  return null;
287
283
  }));
288
- connection.onRequest(protocol_1.AutoInsertRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
289
- return worker(params.textDocument.uri, vueLs => {
284
+ connection.onRequest(protocol_1.AutoInsertRequest.type, (params, token) => __awaiter(this, void 0, void 0, function* () {
285
+ return worker(params.textDocument.uri, token, vueLs => {
290
286
  return vueLs.doAutoInsert(params.textDocument.uri, params.position, params.options);
291
287
  });
292
288
  }));
293
- function worker(uri, cb) {
294
- return __awaiter(this, void 0, void 0, function* () {
295
- const vueLs = yield getLanguageService(uri);
296
- if (vueLs) {
297
- try {
298
- return cb(vueLs); // handle for TS cancel throw
289
+ function worker(uri, token, cb) {
290
+ return new Promise(resolve => {
291
+ runtime.timer.setImmediate(() => __awaiter(this, void 0, void 0, function* () {
292
+ if (token.isCancellationRequested) {
293
+ resolve(undefined);
294
+ return;
299
295
  }
300
- catch (_a) {
301
- return undefined;
296
+ const vueLs = yield getLanguageService(uri);
297
+ if (vueLs) {
298
+ try { // handle TS cancel throw
299
+ const result = yield cb(vueLs);
300
+ if (token.isCancellationRequested) {
301
+ resolve(undefined);
302
+ return;
303
+ }
304
+ resolve(result);
305
+ }
306
+ catch (_a) {
307
+ resolve(undefined);
308
+ return;
309
+ }
302
310
  }
303
- }
311
+ else {
312
+ resolve(undefined);
313
+ }
314
+ }));
304
315
  });
305
316
  }
306
317
  function buildTokens(tokens) {
@@ -1,16 +1,16 @@
1
1
  import * as embedded from '@volar/language-core';
2
2
  import * as embeddedLS from '@volar/language-service';
3
+ import { LanguageServiceConfig } from '@volar/language-service';
3
4
  import * as path from 'typesafe-path';
4
5
  import type * as ts from 'typescript/lib/tsserverlibrary';
5
6
  import { URI } from 'vscode-uri';
6
7
  import { WorkspaceContext } from './workspace';
7
- import { ServerConfig } from './utils/serverConfig';
8
8
  export interface ProjectContext {
9
9
  workspace: WorkspaceContext;
10
10
  rootUri: URI;
11
11
  tsConfig: path.PosixPath | ts.CompilerOptions;
12
12
  documentRegistry: ts.DocumentRegistry | undefined;
13
- serverConfig: ServerConfig | undefined;
13
+ serverConfig: LanguageServiceConfig | undefined;
14
14
  }
15
15
  export type Project = ReturnType<typeof createProject>;
16
16
  export declare function createProject(context: ProjectContext): Promise<{
@@ -9,11 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.createProject = void 0;
12
- const embedded = require("@volar/language-core");
13
12
  const embeddedLS = require("@volar/language-service");
14
13
  const shared = require("@volar/shared");
15
14
  const path = require("typesafe-path");
16
15
  const vscode = require("vscode-languageserver");
16
+ const vscode_uri_1 = require("vscode-uri");
17
17
  const types_1 = require("../types");
18
18
  const uriMap_1 = require("./utils/uriMap");
19
19
  function createProject(context) {
@@ -62,39 +62,37 @@ function createProject(context) {
62
62
  dispose,
63
63
  };
64
64
  function getLanguageService() {
65
+ var _a, _b, _c, _d, _e, _f;
65
66
  if (!languageService) {
66
- const languageModules = context.workspace.workspaces.plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.getLanguageModules) === null || _a === void 0 ? void 0 : _a.call(plugin, languageServiceHost)) !== null && _b !== void 0 ? _b : []; }).flat();
67
- const languageContext = embedded.createLanguageContext(languageServiceHost, languageModules);
68
- const languageServiceContext = embeddedLS.createLanguageServiceContext({
67
+ const config = {
68
+ languages: Object.assign({}, (_b = (_a = context.serverConfig) === null || _a === void 0 ? void 0 : _a.languages) !== null && _b !== void 0 ? _b : {}),
69
+ plugins: Object.assign({}, (_d = (_c = context.serverConfig) === null || _c === void 0 ? void 0 : _c.plugins) !== null && _d !== void 0 ? _d : {}),
70
+ rules: Object.assign({}, (_e = context.serverConfig) === null || _e === void 0 ? void 0 : _e.rules),
71
+ };
72
+ const env = {
73
+ rootUri: context.rootUri,
74
+ configurationHost: context.workspace.workspaces.configurationHost,
75
+ fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
76
+ documentContext: getDocumentContext(context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
77
+ schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
78
+ const protocol = uri.substring(0, uri.indexOf(':'));
79
+ const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
80
+ if (builtInHandler) {
81
+ return yield builtInHandler(uri);
82
+ }
83
+ return '';
84
+ }),
85
+ };
86
+ const lsCtx = {
87
+ project: context,
88
+ env,
89
+ sys,
69
90
  host: languageServiceHost,
70
- context: languageContext,
71
- getPlugins() {
72
- var _a, _b;
73
- return [
74
- ...(_b = (_a = context.serverConfig) === null || _a === void 0 ? void 0 : _a.plugins) !== null && _b !== void 0 ? _b : [],
75
- ...context.workspace.workspaces.plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.getLanguageServicePlugins) === null || _a === void 0 ? void 0 : _a.call(plugin, languageServiceHost, languageServiceContext)) !== null && _b !== void 0 ? _b : []; }).flat(),
76
- ];
77
- },
78
- env: {
79
- rootUri: context.rootUri,
80
- configurationHost: context.workspace.workspaces.configurationHost,
81
- fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
82
- documentContext: context.workspace.workspaces.ts
83
- ? getHTMLDocumentContext(context.workspace.workspaces.ts, languageServiceHost)
84
- : undefined,
85
- schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
86
- const protocol = uri.substring(0, uri.indexOf(':'));
87
- const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
88
- if (builtInHandler) {
89
- return yield builtInHandler(uri);
90
- }
91
- return '';
92
- }),
93
- },
94
- documentRegistry: context.documentRegistry,
95
- getLanguageService: () => languageService,
96
- });
97
- languageService = embeddedLS.createLanguageService(languageServiceContext);
91
+ };
92
+ for (const plugin of context.workspace.workspaces.plugins) {
93
+ (_f = plugin.resolveConfig) === null || _f === void 0 ? void 0 : _f.call(plugin, config, lsCtx);
94
+ }
95
+ languageService = embeddedLS.createLanguageService(languageServiceHost, config, env, context.documentRegistry);
98
96
  }
99
97
  return languageService;
100
98
  }
@@ -170,8 +168,12 @@ function createProject(context) {
170
168
  getCompilationSettings: () => parsedCommandLine.options,
171
169
  getScriptVersion,
172
170
  getScriptSnapshot,
173
- getTypeScriptModule: () => {
171
+ getTypeScriptModule: context.workspace.workspaces.ts ? () => {
174
172
  return context.workspace.workspaces.ts;
173
+ } : undefined,
174
+ getScriptLanguageId: (fileName) => {
175
+ var _a;
176
+ return (_a = context.workspace.workspaces.documents.data.pathGet(fileName)) === null || _a === void 0 ? void 0 : _a.languageId;
175
177
  },
176
178
  };
177
179
  if (context.workspace.workspaces.initOptions.noProjectReferences) {
@@ -181,11 +183,6 @@ function createProject(context) {
181
183
  if (context.workspace.workspaces.tsLocalized) {
182
184
  host.getLocalizedDiagnosticMessages = () => context.workspace.workspaces.tsLocalized;
183
185
  }
184
- for (const plugin of context.workspace.workspaces.plugins) {
185
- if (context.workspace.workspaces.ts && plugin.resolveLanguageServiceHost) {
186
- host = plugin.resolveLanguageServiceHost(context.workspace.workspaces.ts, sys, context.tsConfig, host);
187
- }
188
- }
189
186
  return host;
190
187
  function getScriptVersion(fileName) {
191
188
  var _a, _b;
@@ -243,7 +240,7 @@ function createProject(context) {
243
240
  }
244
241
  exports.createProject = createProject;
245
242
  function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
246
- const extraFileExtensions = plugins.map(plugin => { var _a; return (_a = plugin.extraFileExtensions) !== null && _a !== void 0 ? _a : []; }).flat();
243
+ const extraFileExtensions = plugins.map(plugin => { var _a; return (_a = plugin.tsconfigExtraFileExtensions) !== null && _a !== void 0 ? _a : []; }).flat();
247
244
  if (ts) {
248
245
  try {
249
246
  let content;
@@ -271,38 +268,53 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
271
268
  options: {},
272
269
  };
273
270
  }
274
- function getHTMLDocumentContext(ts, host) {
271
+ function getDocumentContext(ts, host, rootUri) {
275
272
  const documentContext = {
276
- resolveReference(ref, base) {
273
+ resolveReference: (ref, base) => {
277
274
  var _a, _b;
278
- const isUri = base.indexOf('://') >= 0;
279
- const resolveResult = ts.resolveModuleName(ref, isUri ? shared.uriToFileName(base) : base, host.getCompilationSettings(), host);
280
- const failedLookupLocations = typeof resolveResult === 'object' ? resolveResult.failedLookupLocations : [];
281
- const dirs = new Set();
282
- if (!failedLookupLocations) {
283
- console.warn(`[volar] failedLookupLocations not exists, ts: ${ts.version}`);
284
- }
285
- for (let failed of failedLookupLocations !== null && failedLookupLocations !== void 0 ? failedLookupLocations : []) {
286
- const fileName = path.basename(failed);
287
- if (fileName === 'index.d.ts' || fileName === '*.d.ts') {
288
- dirs.add(path.dirname(failed));
289
- }
290
- if (failed.endsWith('.d.ts')) {
291
- failed = failed.substring(0, failed.length - '.d.ts'.length);
275
+ if (ts && host) { // support tsconfig.json paths
276
+ const isUri = base.indexOf('://') >= 0;
277
+ const resolveResult = ts.resolveModuleName(ref, isUri ? shared.uriToFileName(base) : base, host.getCompilationSettings(), host);
278
+ const failedLookupLocations = typeof resolveResult === 'object' ? resolveResult.failedLookupLocations : [];
279
+ const dirs = new Set();
280
+ if (!failedLookupLocations) {
281
+ console.warn(`[volar] failedLookupLocations not exists, ts: ${ts.version}`);
292
282
  }
293
- else {
294
- continue;
283
+ for (let failed of failedLookupLocations !== null && failedLookupLocations !== void 0 ? failedLookupLocations : []) {
284
+ const fileName = path.basename(failed);
285
+ if (fileName === 'index.d.ts' || fileName === '*.d.ts') {
286
+ dirs.add(path.dirname(failed));
287
+ }
288
+ if (failed.endsWith('.d.ts')) {
289
+ failed = failed.substring(0, failed.length - '.d.ts'.length);
290
+ }
291
+ else {
292
+ continue;
293
+ }
294
+ if (host.fileExists(failed)) {
295
+ return isUri ? shared.fileNameToUri(failed) : failed;
296
+ }
295
297
  }
296
- if (host.fileExists(failed)) {
297
- return isUri ? shared.fileNameToUri(failed) : failed;
298
+ for (const dir of dirs) {
299
+ if ((_b = (_a = host.directoryExists) === null || _a === void 0 ? void 0 : _a.call(host, dir)) !== null && _b !== void 0 ? _b : true) {
300
+ return isUri ? shared.fileNameToUri(dir) : dir;
301
+ }
298
302
  }
299
303
  }
300
- for (const dir of dirs) {
301
- if ((_b = (_a = host.directoryExists) === null || _a === void 0 ? void 0 : _a.call(host, dir)) !== null && _b !== void 0 ? _b : true) {
302
- return isUri ? shared.fileNameToUri(dir) : dir;
304
+ // original html resolveReference
305
+ if (ref.match(/^\w[\w\d+.-]*:/)) {
306
+ // starts with a schema
307
+ return ref;
308
+ }
309
+ if (ref[0] === '/') { // resolve absolute path against the current workspace folder
310
+ const folderUri = rootUri;
311
+ if (folderUri) {
312
+ return folderUri + ref.substr(1);
303
313
  }
304
314
  }
305
- return undefined;
315
+ const baseUri = vscode_uri_1.URI.parse(base);
316
+ const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
317
+ return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
306
318
  },
307
319
  };
308
320
  return documentContext;
@@ -17,6 +17,7 @@ const configurationHost_1 = require("./configurationHost");
17
17
  const documents_1 = require("./documents");
18
18
  const registerFeatures_1 = require("./utils/registerFeatures");
19
19
  const workspaces_1 = require("./workspaces");
20
+ const l10n = require("@vscode/l10n");
20
21
  function startCommonLanguageServer(context) {
21
22
  let initParams;
22
23
  let options;
@@ -27,10 +28,13 @@ function startCommonLanguageServer(context) {
27
28
  let plugins;
28
29
  const documents = (0, documents_1.createDocuments)(context.connection);
29
30
  context.connection.onInitialize((_params) => __awaiter(this, void 0, void 0, function* () {
30
- var _a, _b, _c;
31
+ var _a, _b, _c, _d;
31
32
  initParams = _params;
32
33
  options = initParams.initializationOptions;
33
34
  plugins = context.plugins.map(plugin => plugin(options));
35
+ if (options.l10n) {
36
+ yield l10n.config({ uri: options.l10n.location });
37
+ }
34
38
  if (((_a = initParams.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.workspaceFolders) && initParams.workspaceFolders) {
35
39
  roots = initParams.workspaceFolders.map(folder => vscode_uri_1.URI.parse(folder.uri));
36
40
  }
@@ -56,7 +60,10 @@ function startCommonLanguageServer(context) {
56
60
  version: packageJson.version,
57
61
  };
58
62
  }
59
- catch (_d) { }
63
+ catch (_e) { }
64
+ for (const plugin of plugins) {
65
+ (_d = plugin.onInitialize) === null || _d === void 0 ? void 0 : _d.call(plugin, result);
66
+ }
60
67
  return result;
61
68
  }));
62
69
  context.connection.onInitialized(() => {
@@ -76,26 +83,25 @@ function startCommonLanguageServer(context) {
76
83
  if (options.serverMode !== types_1.ServerMode.Syntactic
77
84
  && !options.disableFileWatcher
78
85
  && ((_c = (_b = initParams.capabilities.workspace) === null || _b === void 0 ? void 0 : _b.didChangeWatchedFiles) === null || _c === void 0 ? void 0 : _c.dynamicRegistration)) {
79
- context.connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
80
- watchers: [
81
- {
82
- globPattern: `**/*.{${[
83
- 'js',
84
- 'cjs',
85
- 'mjs',
86
- 'ts',
87
- 'cts',
88
- 'mts',
89
- 'jsx',
90
- 'tsx',
91
- 'json',
92
- ...plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.extraFileExtensions) === null || _a === void 0 ? void 0 : _a.map(ext => ext.extension)) !== null && _b !== void 0 ? _b : []; }).flat(),
93
- ].join(',')}}`
94
- },
95
- ]
96
- });
86
+ const exts = plugins.map(plugin => { var _a; return (_a = plugin.extensions.fileWatcher) !== null && _a !== void 0 ? _a : []; }).flat();
87
+ if (exts.length) {
88
+ context.connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
89
+ watchers: [
90
+ {
91
+ globPattern: `**/*.{${exts.join(',')}}`
92
+ },
93
+ ]
94
+ });
95
+ }
97
96
  }
98
97
  });
98
+ context.connection.onShutdown(() => __awaiter(this, void 0, void 0, function* () {
99
+ if (projects) {
100
+ for (const workspace of projects.workspaces) {
101
+ (yield workspace[1]).dispose();
102
+ }
103
+ }
104
+ }));
99
105
  context.connection.listen();
100
106
  function createLanguageServiceHost() {
101
107
  var _a;
@@ -121,9 +127,9 @@ function startCommonLanguageServer(context) {
121
127
  projects.add(root);
122
128
  }
123
129
  (yield Promise.resolve().then(() => require('./features/customFeatures'))).register(context.connection, projects);
124
- (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(context.connection, projects, initParams, cancelTokenHost, getSemanticTokensLegend());
130
+ (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(context.connection, projects, initParams, cancelTokenHost, getSemanticTokensLegend(), context.runtimeEnv);
125
131
  for (const plugin of plugins) {
126
- (_a = plugin.onInitialize) === null || _a === void 0 ? void 0 : _a.call(plugin, context.connection, getLanguageService);
132
+ (_a = plugin.onInitialized) === null || _a === void 0 ? void 0 : _a.call(plugin, getLanguageService);
127
133
  }
128
134
  function getLanguageService(uri) {
129
135
  var _a;
@@ -66,18 +66,7 @@ function setupCapabilities(params, server, initOptions, plugins, semanticTokensL
66
66
  }
67
67
  if (!initOptions.respectClientCapabilities || ((_s = params.textDocument) === null || _s === void 0 ? void 0 : _s.completion)) {
68
68
  server.completionProvider = {
69
- // triggerCharacters: '!@#$%^&*()_+-=`~{}|[]\:";\'<>?,./ '.split(''), // all symbols on keyboard
70
- // hardcode to fix https://github.com/sublimelsp/LSP-volar/issues/114
71
- triggerCharacters: [...new Set([
72
- '/', '-', ':',
73
- ...'>+^*()#.[]$@-{}'.split(''),
74
- '.', ':', '<', '"', '=', '/',
75
- '@',
76
- '"', ':',
77
- '.', '"', '\'', '`', '/', '<', '@', '#', ' ',
78
- '*',
79
- '@', // typescript-comment
80
- ])],
69
+ triggerCharacters: '!@#$%^&*()_+-=`~{}|[]\:";\'<>?,./ '.split(''),
81
70
  resolveProvider: true,
82
71
  };
83
72
  if (initOptions.ignoreTriggerCharacters) {
@@ -126,53 +115,33 @@ function setupCapabilities(params, server, initOptions, plugins, semanticTokensL
126
115
  server.inlayHintProvider = true;
127
116
  }
128
117
  if ((!initOptions.respectClientCapabilities || ((_2 = params.textDocument) === null || _2 === void 0 ? void 0 : _2.diagnostic)) && ((_3 = initOptions.diagnosticModel) !== null && _3 !== void 0 ? _3 : types_1.DiagnosticModel.Push) === types_1.DiagnosticModel.Pull) {
129
- server.diagnosticProvider = {
130
- documentSelector: [
131
- {
132
- pattern: `**/*.{${[
133
- 'js',
134
- 'cjs',
135
- 'mjs',
136
- 'ts',
137
- 'cts',
138
- 'mts',
139
- 'jsx',
140
- 'tsx',
141
- // 'json',
142
- ...plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.extraFileExtensions) === null || _a === void 0 ? void 0 : _a.map(ext => ext.extension)) !== null && _b !== void 0 ? _b : []; }).flat(),
143
- ].join(',')}}`
144
- }
145
- ],
146
- interFileDependencies: true,
147
- workspaceDiagnostics: false,
148
- };
118
+ const selector = plugins.map(plugin => { var _a; return (_a = plugin.diagnosticDocumentSelector) !== null && _a !== void 0 ? _a : []; }).flat();
119
+ if (selector) {
120
+ server.diagnosticProvider = {
121
+ documentSelector: selector,
122
+ interFileDependencies: true,
123
+ workspaceDiagnostics: false,
124
+ };
125
+ }
149
126
  }
150
127
  // cross file features
151
128
  if (!initOptions.respectClientCapabilities || ((_4 = params.workspace) === null || _4 === void 0 ? void 0 : _4.fileOperations)) {
152
- server.workspace = {
153
- fileOperations: {
154
- willRename: {
155
- filters: [
156
- {
157
- pattern: {
158
- glob: `**/*.{${[
159
- 'js',
160
- 'cjs',
161
- 'mjs',
162
- 'ts',
163
- 'cts',
164
- 'mts',
165
- 'jsx',
166
- 'tsx',
167
- 'json',
168
- ...plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.extraFileExtensions) === null || _a === void 0 ? void 0 : _a.map(ext => ext.extension)) !== null && _b !== void 0 ? _b : []; }).flat(),
169
- ].join(',')}}`
170
- }
171
- },
172
- ]
129
+ const exts = plugins.map(plugin => plugin.extensions.fileRenameOperationFilter).flat();
130
+ if (exts.length) {
131
+ server.workspace = {
132
+ fileOperations: {
133
+ willRename: {
134
+ filters: [
135
+ {
136
+ pattern: {
137
+ glob: `**/*.{${exts.join(',')}}`
138
+ }
139
+ },
140
+ ]
141
+ }
173
142
  }
174
- }
175
- };
143
+ };
144
+ }
176
145
  }
177
146
  if (!initOptions.respectClientCapabilities || ((_5 = params.workspace) === null || _5 === void 0 ? void 0 : _5.symbol)) {
178
147
  server.workspaceSymbolProvider = true;
@@ -1,5 +1,2 @@
1
- import { LanguageServicePlugin } from '@volar/language-service';
2
- export interface ServerConfig {
3
- plugins?: LanguageServicePlugin[];
4
- }
5
- export declare function loadServerConfig(dir: string, configFile: string | undefined): ServerConfig | undefined;
1
+ import { LanguageServiceConfig } from "@volar/language-service";
2
+ export declare function loadConfig(dir: string, configFile: string | undefined): LanguageServiceConfig | undefined;
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.loadServerConfig = void 0;
3
- function loadServerConfig(dir, configFile) {
2
+ exports.loadConfig = void 0;
3
+ function loadConfig(dir, configFile) {
4
4
  let configPath;
5
5
  try {
6
6
  configPath = require.resolve(configFile !== null && configFile !== void 0 ? configFile : './volar.config.js', { paths: [dir] });
@@ -17,5 +17,5 @@ function loadServerConfig(dir, configFile) {
17
17
  console.log(err);
18
18
  }
19
19
  }
20
- exports.loadServerConfig = loadServerConfig;
20
+ exports.loadConfig = loadConfig;
21
21
  //# sourceMappingURL=serverConfig.js.map
@@ -23,7 +23,7 @@ function createWorkspace(context) {
23
23
  var _a, _b, _c;
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  let inferredProject;
26
- const serverConfig = (0, serverConfig_1.loadServerConfig)(shared.uriToFileName(context.rootUri.toString()), context.workspaces.initOptions.configFilePath);
26
+ const serverConfig = (0, serverConfig_1.loadConfig)(shared.uriToFileName(context.rootUri.toString()), context.workspaces.initOptions.configFilePath);
27
27
  const sys = (_a = context.workspaces.fileSystemHost) === null || _a === void 0 ? void 0 : _a.getWorkspaceFileSystem(context.rootUri);
28
28
  const documentRegistry = sys ? (_b = context.workspaces.ts) === null || _b === void 0 ? void 0 : _b.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.uriToFileName(context.rootUri.toString())) : undefined;
29
29
  const projects = (0, uriMap_1.createUriMap)();
@@ -147,7 +147,7 @@ function createWorkspaces(context) {
147
147
  function getProjectAndTsConfig(uri) {
148
148
  var _a;
149
149
  return __awaiter(this, void 0, void 0, function* () {
150
- const rootUris = [...workspaces.keys()]
150
+ let rootUris = [...workspaces.keys()]
151
151
  .filter(rootUri => (0, isFileInDir_1.isFileInDir)(shared.uriToFileName(uri), shared.uriToFileName(rootUri)))
152
152
  .sort((a, b) => (0, workspace_1.sortTsConfigs)(shared.uriToFileName(uri), shared.uriToFileName(a), shared.uriToFileName(b)));
153
153
  if (context.initOptions.serverMode !== types_1.ServerMode.Syntactic) {
@@ -159,6 +159,9 @@ function createWorkspaces(context) {
159
159
  }
160
160
  }
161
161
  }
162
+ if (!rootUris.length) {
163
+ rootUris = [...workspaces.keys()];
164
+ }
162
165
  if (rootUris.length) {
163
166
  const project = yield ((_a = (yield workspaces.get(rootUris[0]))) === null || _a === void 0 ? void 0 : _a.getInferredProject());
164
167
  project === null || project === void 0 ? void 0 : project.tryAddFile(shared.uriToFileName(uri));
package/out/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './protocol';
2
2
  export * from './types';
3
+ export * from 'vscode-languageserver';
3
4
  export * from '@volar/language-core/out/types';
4
5
  export * from '@volar/language-service/out/types';
package/out/index.js CHANGED
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
16
  __exportStar(require("./protocol"), exports);
17
17
  __exportStar(require("./types"), exports);
18
18
  // only export types of depend packages
19
+ __exportStar(require("vscode-languageserver"), exports);
19
20
  __exportStar(require("@volar/language-core/out/types"), exports);
20
21
  __exportStar(require("@volar/language-service/out/types"), exports);
21
22
  //# sourceMappingURL=index.js.map
package/out/node/index.js CHANGED
@@ -42,6 +42,12 @@ function startLanguageServer(connection, ...plugins) {
42
42
  plugins,
43
43
  connection,
44
44
  runtimeEnv: {
45
+ timer: {
46
+ setImmediate(callback, ...args) {
47
+ const handle = setImmediate(callback, ...args);
48
+ return { dispose: () => clearImmediate(handle) };
49
+ },
50
+ },
45
51
  loadTypescript(tsdk) {
46
52
  for (const name of ['./typescript.js', './tsserverlibrary.js', './tsserver.js']) {
47
53
  try {
package/out/protocol.js CHANGED
@@ -6,53 +6,53 @@ const vscode = require("vscode-languageserver-protocol");
6
6
  */
7
7
  var ShowReferencesNotification;
8
8
  (function (ShowReferencesNotification) {
9
- ShowReferencesNotification.type = new vscode.NotificationType('vue.findReferences');
9
+ ShowReferencesNotification.type = new vscode.NotificationType('volar/server/showReferences');
10
10
  })(ShowReferencesNotification = exports.ShowReferencesNotification || (exports.ShowReferencesNotification = {}));
11
11
  var FsStatRequest;
12
12
  (function (FsStatRequest) {
13
- FsStatRequest.type = new vscode.RequestType('fs/stat');
13
+ FsStatRequest.type = new vscode.RequestType('volar/server/fs/stat');
14
14
  })(FsStatRequest = exports.FsStatRequest || (exports.FsStatRequest = {}));
15
15
  var FsReadFileRequest;
16
16
  (function (FsReadFileRequest) {
17
- FsReadFileRequest.type = new vscode.RequestType('fs/readFile');
17
+ FsReadFileRequest.type = new vscode.RequestType('volar/server/fs/readFile');
18
18
  })(FsReadFileRequest = exports.FsReadFileRequest || (exports.FsReadFileRequest = {}));
19
19
  var FsReadDirectoryRequest;
20
20
  (function (FsReadDirectoryRequest) {
21
- FsReadDirectoryRequest.type = new vscode.RequestType('fs/readDirectory');
21
+ FsReadDirectoryRequest.type = new vscode.RequestType('volar/server/fs/readDirectory');
22
22
  })(FsReadDirectoryRequest = exports.FsReadDirectoryRequest || (exports.FsReadDirectoryRequest = {}));
23
23
  /**
24
24
  * Client request server
25
25
  */
26
26
  var FindFileReferenceRequest;
27
27
  (function (FindFileReferenceRequest) {
28
- FindFileReferenceRequest.type = new vscode.RequestType('vue/findFileReference');
28
+ FindFileReferenceRequest.type = new vscode.RequestType('volar/client/findFileReference');
29
29
  })(FindFileReferenceRequest = exports.FindFileReferenceRequest || (exports.FindFileReferenceRequest = {}));
30
30
  var GetMatchTsConfigRequest;
31
31
  (function (GetMatchTsConfigRequest) {
32
- GetMatchTsConfigRequest.type = new vscode.RequestType('volar/tsconfig');
32
+ GetMatchTsConfigRequest.type = new vscode.RequestType('volar/client/tsconfig');
33
33
  })(GetMatchTsConfigRequest = exports.GetMatchTsConfigRequest || (exports.GetMatchTsConfigRequest = {}));
34
34
  var AutoInsertRequest;
35
35
  (function (AutoInsertRequest) {
36
- AutoInsertRequest.type = new vscode.RequestType('vue/autoInsert');
36
+ AutoInsertRequest.type = new vscode.RequestType('volar/client/autoInsert');
37
37
  })(AutoInsertRequest = exports.AutoInsertRequest || (exports.AutoInsertRequest = {}));
38
38
  var WriteVirtualFilesNotification;
39
39
  (function (WriteVirtualFilesNotification) {
40
- WriteVirtualFilesNotification.type = new vscode.NotificationType('volar.action.writeVirtualFiles');
40
+ WriteVirtualFilesNotification.type = new vscode.NotificationType('volar/client/writeVirtualFiles');
41
41
  })(WriteVirtualFilesNotification = exports.WriteVirtualFilesNotification || (exports.WriteVirtualFilesNotification = {}));
42
42
  var ReloadProjectNotification;
43
43
  (function (ReloadProjectNotification) {
44
- ReloadProjectNotification.type = new vscode.NotificationType('volar.action.reloadProject');
44
+ ReloadProjectNotification.type = new vscode.NotificationType('volar/client/reloadProject');
45
45
  })(ReloadProjectNotification = exports.ReloadProjectNotification || (exports.ReloadProjectNotification = {}));
46
46
  var GetVirtualFileNamesRequest;
47
47
  (function (GetVirtualFileNamesRequest) {
48
- GetVirtualFileNamesRequest.type = new vscode.RequestType('vue/virtualFileNames');
48
+ GetVirtualFileNamesRequest.type = new vscode.RequestType('volar/client/virtualFileNames');
49
49
  })(GetVirtualFileNamesRequest = exports.GetVirtualFileNamesRequest || (exports.GetVirtualFileNamesRequest = {}));
50
50
  var GetVirtualFileRequest;
51
51
  (function (GetVirtualFileRequest) {
52
- GetVirtualFileRequest.type = new vscode.RequestType('vue/virtualFile');
52
+ GetVirtualFileRequest.type = new vscode.RequestType('volar/client/virtualFile');
53
53
  })(GetVirtualFileRequest = exports.GetVirtualFileRequest || (exports.GetVirtualFileRequest = {}));
54
54
  var ReportStats;
55
55
  (function (ReportStats) {
56
- ReportStats.type = new vscode.NotificationType0('vue/stats');
56
+ ReportStats.type = new vscode.NotificationType0('volar/client/stats');
57
57
  })(ReportStats = exports.ReportStats || (exports.ReportStats = {}));
58
58
  //# sourceMappingURL=protocol.js.map
package/out/types.d.ts CHANGED
@@ -5,7 +5,8 @@ import type { FileSystemProvider } from 'vscode-html-languageservice';
5
5
  import type * as ts from 'typescript/lib/tsserverlibrary';
6
6
  import * as vscode from 'vscode-languageserver';
7
7
  import { URI } from 'vscode-uri';
8
- import { LanguageServiceRuntimeContext } from '@volar/language-service';
8
+ import { LanguageServiceConfig, LanguageServiceRuntimeContext } from '@volar/language-service';
9
+ import { ProjectContext } from './common/project';
9
10
  export type FileSystemHost = {
10
11
  ready(connection: vscode.Connection): void;
11
12
  reload(): void;
@@ -22,13 +23,26 @@ export interface RuntimeEnvironment {
22
23
  onDidChangeConfiguration?: (settings: any) => void;
23
24
  fileSystemProvide: FileSystemProvider | undefined;
24
25
  createFileSystemHost: (ts: typeof import('typescript/lib/tsserverlibrary'), capabilities: vscode.ClientCapabilities) => FileSystemHost;
26
+ readonly timer: {
27
+ setImmediate(callback: (...args: any[]) => void, ...args: any[]): vscode.Disposable;
28
+ };
29
+ }
30
+ export interface LanguageServiceContext {
31
+ project: ProjectContext;
32
+ env: LanguageServiceRuntimeContext['env'];
33
+ host: embedded.LanguageServiceHost;
34
+ sys: FileSystem;
25
35
  }
26
- export type LanguageServerPlugin<A extends LanguageServerInitializationOptions = LanguageServerInitializationOptions, B extends embedded.LanguageServiceHost = embedded.LanguageServiceHost, C = embeddedLS.LanguageService> = (initOptions: A) => {
27
- extraFileExtensions?: ts.FileExtensionInfo[];
28
- resolveLanguageServiceHost?(ts: typeof import('typescript/lib/tsserverlibrary'), sys: FileSystem, tsConfig: string | ts.CompilerOptions, host: embedded.LanguageServiceHost): B;
29
- getLanguageModules?(host: B): embedded.LanguageModule[];
30
- getLanguageServicePlugins?(host: B, context: LanguageServiceRuntimeContext): embeddedLS.LanguageServicePlugin[];
31
- onInitialize?(connection: vscode.Connection, getLanguageService: (uri: string) => Promise<C>): void;
36
+ export type LanguageServerPlugin<A extends LanguageServerInitializationOptions = LanguageServerInitializationOptions, C = embeddedLS.LanguageService> = (initOptions: A) => {
37
+ tsconfigExtraFileExtensions: ts.FileExtensionInfo[];
38
+ diagnosticDocumentSelector: vscode.DocumentSelector;
39
+ extensions: {
40
+ fileRenameOperationFilter: string[];
41
+ fileWatcher: string[];
42
+ };
43
+ resolveConfig?(config: LanguageServiceConfig, ctx: LanguageServiceContext): void;
44
+ onInitialize?(_: vscode.InitializeResult): void;
45
+ onInitialized?(getLanguageService: (uri: string) => Promise<C>): void;
32
46
  };
33
47
  export declare enum ServerMode {
34
48
  Semantic = 0,
@@ -43,6 +57,9 @@ export interface LanguageServerInitializationOptions {
43
57
  typescript?: {
44
58
  tsdk: string;
45
59
  };
60
+ l10n?: {
61
+ location: string;
62
+ };
46
63
  serverMode?: ServerMode;
47
64
  diagnosticModel?: DiagnosticModel;
48
65
  textDocumentSync?: vscode.TextDocumentSyncKind | number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-server",
3
- "version": "1.0.24",
3
+ "version": "1.1.0-1.2.0-alpha.1.0",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,13 +13,14 @@
13
13
  ],
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "https://github.com/johnsoncodehk/volar.git",
16
+ "url": "https://github.com/volarjs/volar.js.git",
17
17
  "directory": "packages/language-server"
18
18
  },
19
19
  "dependencies": {
20
- "@volar/language-core": "1.0.24",
21
- "@volar/language-service": "1.0.24",
22
- "@volar/shared": "1.0.24",
20
+ "@volar/language-core": "1.1.0-1.2.0-alpha.1.0",
21
+ "@volar/language-service": "1.1.0-1.2.0-alpha.1.0",
22
+ "@volar/shared": "1.1.0-1.2.0-alpha.1.0",
23
+ "@vscode/l10n": "^0.0.10",
23
24
  "request-light": "^0.6.0",
24
25
  "typesafe-path": "^0.2.2",
25
26
  "vscode-html-languageservice": "^5.0.3",
@@ -28,5 +29,5 @@
28
29
  "vscode-languageserver-textdocument": "^1.0.8",
29
30
  "vscode-uri": "^3.0.7"
30
31
  },
31
- "gitHead": "46da609e8914e29642f4707dec31507ad51b03fc"
32
+ "gitHead": "ffc1267f2766722751551182ce1e717be661247a"
32
33
  }