@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.createWebFileSystemHost = void 0;
12
3
  const path = require("typesafe-path");
@@ -98,38 +89,36 @@ function createWebFileSystemHost(_0, _1, env, initOptions) {
98
89
  return path.resolve(fsPath);
99
90
  }
100
91
  function fileExists(fsPath) {
101
- var _a, _b, _c;
102
92
  fsPath = resolvePath(fsPath);
103
93
  const uri = env.fileNameToUri(fsPath);
104
94
  const dirPath = path.dirname(fsPath);
105
- if (((_a = initOptions.typescript) === null || _a === void 0 ? void 0 : _a.cdn) && uri.startsWith(initOptions.typescript.cdn)) {
95
+ if (initOptions.typescript?.cdn && uri.startsWith(initOptions.typescript.cdn)) {
106
96
  if (!(uri.endsWith('.d.ts') || uri.endsWith('/package.json'))) {
107
97
  return false;
108
98
  }
109
99
  readFile(fsPath);
110
100
  const file = getDir(dirPath).files.get(path.basename(fsPath));
111
- return (_b = file === null || file === void 0 ? void 0 : file.exists) !== null && _b !== void 0 ? _b : false;
101
+ return file?.exists ?? false;
112
102
  }
113
103
  readDirectory(dirPath);
114
104
  const file = getDir(path.dirname(fsPath)).files.get(path.basename(fsPath));
115
- return (_c = file === null || file === void 0 ? void 0 : file.exists) !== null && _c !== void 0 ? _c : false;
105
+ return file?.exists ?? false;
116
106
  }
117
107
  function readFile(fsPath) {
118
- var _a, _b, _c, _d;
119
108
  fsPath = resolvePath(fsPath);
120
109
  const uri = env.fileNameToUri(fsPath);
121
110
  const dirPath = path.dirname(fsPath);
122
111
  const dir = getDir(dirPath);
123
112
  const name = path.basename(fsPath);
124
- if (((_a = initOptions.typescript) === null || _a === void 0 ? void 0 : _a.cdn) && uri.startsWith(initOptions.typescript.cdn)) {
113
+ if (initOptions.typescript?.cdn && uri.startsWith(initOptions.typescript.cdn)) {
125
114
  if (!(uri.endsWith('.d.ts') || uri.endsWith('/package.json'))) {
126
- return ((_b = dir.files.get(name)) === null || _b === void 0 ? void 0 : _b.text) || '';
115
+ return dir.files.get(name)?.text || '';
127
116
  }
128
117
  readFileWorker();
129
- return ((_c = dir.files.get(name)) === null || _c === void 0 ? void 0 : _c.text) || '';
118
+ return dir.files.get(name)?.text || '';
130
119
  }
131
120
  readFileWorker();
132
- return ((_d = dir.files.get(name)) === null || _d === void 0 ? void 0 : _d.text) || '';
121
+ return dir.files.get(name)?.text || '';
133
122
  function readFileWorker() {
134
123
  if (connection) {
135
124
  fetch('load', fsPath, readFileAsync(connection, fsPath, dir));
@@ -138,26 +127,24 @@ function createWebFileSystemHost(_0, _1, env, initOptions) {
138
127
  onReadyCb.push((connection) => fetch('load', fsPath, readFileAsync(connection, fsPath, dir)));
139
128
  }
140
129
  }
141
- function readFileAsync(connection, fsPath, dir) {
142
- return __awaiter(this, void 0, void 0, function* () {
143
- const name = path.basename(fsPath);
144
- if (!dir.files.has(name)) {
145
- dir.files.set(name, {});
146
- }
147
- const file = dir.files.get(name);
148
- if (file.requested) {
149
- return;
150
- }
151
- file.requested = true;
152
- const uri = env.fileNameToUri(fsPath);
153
- const data = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, resolveRequestUrl(uri));
154
- const text = data ? new TextDecoder('utf8').decode(data) : undefined;
155
- if (text === null || text === void 0 ? void 0 : text.length) {
156
- file.exists = true;
157
- file.text = text;
158
- changes.push({ uri, type: vscode.FileChangeType.Changed });
159
- }
160
- });
130
+ async function readFileAsync(connection, fsPath, dir) {
131
+ const name = path.basename(fsPath);
132
+ if (!dir.files.has(name)) {
133
+ dir.files.set(name, {});
134
+ }
135
+ const file = dir.files.get(name);
136
+ if (file.requested) {
137
+ return;
138
+ }
139
+ file.requested = true;
140
+ const uri = env.fileNameToUri(fsPath);
141
+ const data = await connection.sendRequest(protocol_1.FsReadFileRequest.type, resolveRequestUrl(uri));
142
+ const text = data ? new TextDecoder('utf8').decode(data) : undefined;
143
+ if (text?.length) {
144
+ file.exists = true;
145
+ file.text = text;
146
+ changes.push({ uri, type: vscode.FileChangeType.Changed });
147
+ }
161
148
  }
162
149
  }
163
150
  function readDirectory(fsPath, extensions, exclude, include, depth) {
@@ -187,66 +174,61 @@ function createWebFileSystemHost(_0, _1, env, initOptions) {
187
174
  onReadyCb.push((connection) => fetch('directory', fsPath, readDirectoryAsync(connection, fsPath)));
188
175
  }
189
176
  }
190
- function readDirectoryAsync(connection, fsPath) {
191
- return __awaiter(this, void 0, void 0, function* () {
192
- const dir = getDir(fsPath);
193
- if (dir.requested) {
194
- return;
195
- }
196
- dir.requested = true;
197
- const uri = env.fileNameToUri(fsPath);
198
- const result = yield connection.sendRequest(protocol_1.FsReadDirectoryRequest.type, resolveRequestUrl(uri));
199
- for (const [name, fileType] of result) {
200
- if (fileType === vscode_html_languageservice_1.FileType.File || fileType === vscode_html_languageservice_1.FileType.SymbolicLink) {
201
- if (!dir.files.has(name)) {
202
- dir.files.set(name, {});
203
- }
204
- const file = dir.files.get(name);
205
- if (!file.exists) {
206
- file.exists = true;
207
- changes.push({
208
- uri: env.fileNameToUri(path.join(fsPath, name)),
209
- type: vscode.FileChangeType.Created,
210
- });
211
- }
177
+ async function readDirectoryAsync(connection, fsPath) {
178
+ const dir = getDir(fsPath);
179
+ if (dir.requested) {
180
+ return;
181
+ }
182
+ dir.requested = true;
183
+ const uri = env.fileNameToUri(fsPath);
184
+ const result = await connection.sendRequest(protocol_1.FsReadDirectoryRequest.type, resolveRequestUrl(uri));
185
+ for (const [name, fileType] of result) {
186
+ if (fileType === vscode_html_languageservice_1.FileType.File || fileType === vscode_html_languageservice_1.FileType.SymbolicLink) {
187
+ if (!dir.files.has(name)) {
188
+ dir.files.set(name, {});
212
189
  }
213
- else if (fileType === vscode_html_languageservice_1.FileType.Directory && !dir.dirs.has(name)) {
214
- const childDir = getDirFromDir(dir, name);
215
- childDir.exists = true;
190
+ const file = dir.files.get(name);
191
+ if (!file.exists) {
192
+ file.exists = true;
193
+ changes.push({
194
+ uri: env.fileNameToUri(path.join(fsPath, name)),
195
+ type: vscode.FileChangeType.Created,
196
+ });
216
197
  }
217
198
  }
218
- });
199
+ else if (fileType === vscode_html_languageservice_1.FileType.Directory && !dir.dirs.has(name)) {
200
+ const childDir = getDirFromDir(dir, name);
201
+ childDir.exists = true;
202
+ }
203
+ }
219
204
  }
220
205
  }
221
- function fetch(action, fileName, p) {
222
- return __awaiter(this, void 0, void 0, function* () {
223
- fetchTasks.push([action, fileName, p]);
224
- if (runningRead === false) {
225
- let toUpdate;
226
- runningRead = true;
227
- const progress = yield (connection === null || connection === void 0 ? void 0 : connection.window.createWorkDoneProgress());
228
- progress === null || progress === void 0 ? void 0 : progress.begin('');
229
- while (fetchTasks.length) {
230
- const current = fetchTasks.shift();
231
- updateProgress(current[0] + ' ' + vscode_uri_1.URI.parse(env.fileNameToUri(current[1])).fsPath);
232
- yield current[2];
233
- }
234
- progress === null || progress === void 0 ? void 0 : progress.done();
235
- runningRead = false;
236
- fireChanges();
237
- function updateProgress(text) {
238
- clearTimeout(toUpdate);
239
- toUpdate = setTimeout(() => {
240
- progress === null || progress === void 0 ? void 0 : progress.report(text);
241
- toUpdate = undefined;
242
- }, 0);
243
- }
206
+ async function fetch(action, fileName, p) {
207
+ fetchTasks.push([action, fileName, p]);
208
+ if (runningRead === false) {
209
+ let toUpdate;
210
+ runningRead = true;
211
+ const progress = await connection?.window.createWorkDoneProgress();
212
+ progress?.begin('');
213
+ while (fetchTasks.length) {
214
+ const current = fetchTasks.shift();
215
+ updateProgress(current[0] + ' ' + vscode_uri_1.URI.parse(env.fileNameToUri(current[1])).fsPath);
216
+ await current[2];
244
217
  }
245
- });
218
+ progress?.done();
219
+ runningRead = false;
220
+ fireChanges();
221
+ function updateProgress(text) {
222
+ clearTimeout(toUpdate);
223
+ toUpdate = setTimeout(() => {
224
+ progress?.report(text);
225
+ toUpdate = undefined;
226
+ }, 0);
227
+ }
228
+ }
246
229
  }
247
230
  function resolveRequestUrl(uri) {
248
- var _a;
249
- if (((_a = initOptions.typescript) === null || _a === void 0 ? void 0 : _a.cdn) && uri.startsWith(initOptions.typescript.cdn)) {
231
+ if (initOptions.typescript?.cdn && uri.startsWith(initOptions.typescript.cdn)) {
250
232
  let fileName = env.uriToFileName(uri);
251
233
  for (const [key, version] of Object.entries(initOptions.typescript.versions || {})) {
252
234
  if (fileName.startsWith(`/node_modules/${key}/`)) {
@@ -257,19 +239,17 @@ function createWebFileSystemHost(_0, _1, env, initOptions) {
257
239
  }
258
240
  return uri;
259
241
  }
260
- function fireChanges() {
261
- return __awaiter(this, void 0, void 0, function* () {
262
- if (runningRead || runningStat) {
263
- return;
264
- }
265
- const _changes = [...changes];
266
- changes.length = 0;
267
- for (const cb of [...onDidChangeWatchedFilesCb]) {
268
- if (onDidChangeWatchedFilesCb.has(cb)) {
269
- yield cb({ changes: _changes });
270
- }
242
+ async function fireChanges() {
243
+ if (runningRead || runningStat) {
244
+ return;
245
+ }
246
+ const _changes = [...changes];
247
+ changes.length = 0;
248
+ for (const cb of [...onDidChangeWatchedFilesCb]) {
249
+ if (onDidChangeWatchedFilesCb.has(cb)) {
250
+ await cb({ changes: _changes });
271
251
  }
272
- });
252
+ }
273
253
  }
274
254
  function getDir(dirPath) {
275
255
  const dirNames = [];
@@ -12,15 +12,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
12
12
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
13
13
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
14
  };
15
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
16
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
17
- return new (P || (P = Promise))(function (resolve, reject) {
18
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
19
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
20
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
21
- step((generator = generator.apply(thisArg, _arguments || [])).next());
22
- });
23
- };
24
15
  Object.defineProperty(exports, "__esModule", { value: true });
25
16
  exports.startLanguageServer = exports.createConnection = void 0;
26
17
  const request_light_1 = require("request-light");
@@ -54,17 +45,15 @@ function startLanguageServer(connection, ...plugins) {
54
45
  loadTypescript() {
55
46
  return require('typescript'); // force bundle because not support load by user config in web
56
47
  },
57
- loadTypescriptLocalized(tsdk, locale) {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- try {
60
- const uri = fileNameToUri(`${tsdk}/${locale}/diagnosticMessages.generated.json`);
61
- const json = yield (0, http_1.default)(uri);
62
- if (json) {
63
- return JSON.parse(json);
64
- }
48
+ async loadTypescriptLocalized(tsdk, locale) {
49
+ try {
50
+ const uri = fileNameToUri(`${tsdk}/${locale}/diagnosticMessages.generated.json`);
51
+ const json = await (0, http_1.default)(uri);
52
+ if (json) {
53
+ return JSON.parse(json);
65
54
  }
66
- catch (_a) { }
67
- });
55
+ }
56
+ catch { }
68
57
  },
69
58
  schemaRequestHandlers: {
70
59
  http: http_1.default,
@@ -78,17 +67,15 @@ function startLanguageServer(connection, ...plugins) {
78
67
  },
79
68
  };
80
69
  function uriToFileName(uri) {
81
- var _a;
82
70
  const parsed = vscode_uri_1.URI.parse(uri);
83
- if (((_a = options.typescript) === null || _a === void 0 ? void 0 : _a.cdn) && uri.startsWith(options.typescript.cdn)) {
71
+ if (options.typescript?.cdn && uri.startsWith(options.typescript.cdn)) {
84
72
  return parsed.toString(true).replace(options.typescript.cdn, '/node_modules/');
85
73
  }
86
74
  return `/${parsed.scheme}${parsed.authority ? '@' + parsed.authority : ''}${parsed.path}`;
87
75
  }
88
76
  ;
89
77
  function fileNameToUri(fileName) {
90
- var _a;
91
- if (fileName.startsWith('/node_modules/') && ((_a = options.typescript) === null || _a === void 0 ? void 0 : _a.cdn)) {
78
+ if (fileName.startsWith('/node_modules/') && options.typescript?.cdn) {
92
79
  return vscode_uri_1.URI.parse(fileName.replace('/node_modules/', options.typescript.cdn)).toString();
93
80
  }
94
81
  const parts = fileName.split('/');
@@ -21,7 +21,7 @@ exports.every = every;
21
21
  function findIndex(array, predicate, startIndex) {
22
22
  if (array === undefined)
23
23
  return -1;
24
- for (let i = startIndex !== null && startIndex !== void 0 ? startIndex : 0; i < array.length; i++) {
24
+ for (let i = startIndex ?? 0; i < array.length; i++) {
25
25
  if (predicate(array[i], i)) {
26
26
  return i;
27
27
  }
@@ -19,7 +19,7 @@ var NativeCollections;
19
19
  */
20
20
  function tryGetNativeMap() {
21
21
  // Internet Explorer's Map doesn't support iteration, so don't use it.
22
- const gMap = globals === null || globals === void 0 ? void 0 : globals.Map;
22
+ const gMap = globals?.Map;
23
23
  // eslint-disable-next-line local/no-in-operator
24
24
  const constructor = typeof gMap !== "undefined" && "entries" in gMap.prototype && new gMap([[0, 0]]).size === 1 ? gMap : undefined;
25
25
  if (!constructor) {
@@ -33,7 +33,7 @@ var NativeCollections;
33
33
  */
34
34
  function tryGetNativeSet() {
35
35
  // Internet Explorer's Set doesn't support iteration, so don't use it.
36
- const gSet = globals === null || globals === void 0 ? void 0 : globals.Set;
36
+ const gSet = globals?.Set;
37
37
  // eslint-disable-next-line local/no-in-operator
38
38
  const constructor = typeof gSet !== "undefined" && "entries" in gSet.prototype && new gSet([0]).size === 1 ? gSet : undefined;
39
39
  if (!constructor) {
@@ -35,7 +35,7 @@ function createCancellationTokenHost(_cancellationPipeName) {
35
35
  try {
36
36
  return fs.statSync(cancellationPipeName).mtime.valueOf();
37
37
  }
38
- catch (_a) {
38
+ catch {
39
39
  return -1;
40
40
  }
41
41
  }
@@ -1,52 +1,36 @@
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.createConfigurationHost = void 0;
12
3
  const vscode = require("vscode-languageserver");
13
4
  function createConfigurationHost(params, connection) {
14
5
  const callbacks = [];
15
6
  const cache = new Map();
16
- connection.onDidChangeConfiguration(() => __awaiter(this, void 0, void 0, function* () {
7
+ connection.onDidChangeConfiguration(async () => {
17
8
  cache.clear();
18
9
  for (const cb of callbacks) {
19
10
  cb();
20
11
  }
21
- }));
12
+ });
22
13
  return {
23
14
  ready() {
24
- var _a, _b;
25
- if ((_b = (_a = params.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.didChangeConfiguration) === null || _b === void 0 ? void 0 : _b.dynamicRegistration) {
15
+ if (params.capabilities.workspace?.didChangeConfiguration?.dynamicRegistration) {
26
16
  connection.client.register(vscode.DidChangeConfigurationNotification.type);
27
17
  }
28
18
  },
29
- getConfiguration(section, scopeUri) {
30
- var _a;
31
- return __awaiter(this, void 0, void 0, function* () {
32
- if (!scopeUri && ((_a = params.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.didChangeConfiguration)) {
33
- if (!cache.has(section)) {
34
- cache.set(section, yield getConfigurationWorker(section, scopeUri));
35
- }
36
- return cache.get(section);
19
+ async getConfiguration(section, scopeUri) {
20
+ if (!scopeUri && params.capabilities.workspace?.didChangeConfiguration) {
21
+ if (!cache.has(section)) {
22
+ cache.set(section, await getConfigurationWorker(section, scopeUri));
37
23
  }
38
- return yield getConfigurationWorker(section, scopeUri);
39
- });
24
+ return cache.get(section);
25
+ }
26
+ return await getConfigurationWorker(section, scopeUri);
40
27
  },
41
28
  onDidChangeConfiguration(cb) {
42
29
  callbacks.push(cb);
43
30
  },
44
31
  };
45
- function getConfigurationWorker(section, scopeUri) {
46
- var _a;
47
- return __awaiter(this, void 0, void 0, function* () {
48
- return (_a = (yield connection.workspace.getConfiguration({ scopeUri, section }))) !== null && _a !== void 0 ? _a : undefined /* replace null to undefined */;
49
- });
32
+ async function getConfigurationWorker(section, scopeUri) {
33
+ return (await connection.workspace.getConfiguration({ scopeUri, section })) ?? undefined /* replace null to undefined */;
50
34
  }
51
35
  }
52
36
  exports.createConfigurationHost = createConfigurationHost;
@@ -47,7 +47,7 @@ class IncrementalScriptSnapshot {
47
47
  getLength: () => text.length,
48
48
  getChangeRange: (oldSnapshot) => {
49
49
  if (!cache.has(oldSnapshot)) {
50
- const oldIndex = this.changes.findIndex(change => { var _a; return ((_a = change.snapshot) === null || _a === void 0 ? void 0 : _a.deref()) === oldSnapshot; });
50
+ const oldIndex = this.changes.findIndex(change => change.snapshot?.deref() === oldSnapshot);
51
51
  if (oldIndex >= 0) {
52
52
  const start = oldIndex + 1;
53
53
  const end = this.changes.indexOf(lastChange) + 1;
@@ -75,12 +75,11 @@ class IncrementalScriptSnapshot {
75
75
  return this.document;
76
76
  }
77
77
  clearUnReferenceVersions() {
78
- var _a;
79
78
  let versionToApply;
80
79
  for (let i = 0; i <= this.changes.length - 2; i++) {
81
80
  const change = this.changes[i];
82
81
  const nextChange = this.changes[i + 1];
83
- if (!((_a = change.snapshot) === null || _a === void 0 ? void 0 : _a.deref())) {
82
+ if (!change.snapshot?.deref()) {
84
83
  if (change.version !== nextChange.version) {
85
84
  versionToApply = change.version;
86
85
  }
@@ -1,41 +1,31 @@
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.register = void 0;
12
3
  const protocol_1 = require("../../protocol");
13
4
  const language_core_1 = require("@volar/language-core");
14
5
  function register(connection, projects, env) {
15
- connection.onNotification(protocol_1.ReportStats.type, () => __awaiter(this, void 0, void 0, function* () {
16
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
6
+ connection.onNotification(protocol_1.ReportStats.type, async () => {
17
7
  for (const [rootUri, _workspace] of projects.workspaces) {
18
8
  connection.console.log('workspace: ' + rootUri);
19
- const workspace = yield _workspace;
20
- connection.console.log('documentRegistry stats: ' + ((_a = workspace.documentRegistry) === null || _a === void 0 ? void 0 : _a.reportStats()));
9
+ const workspace = await _workspace;
10
+ connection.console.log('documentRegistry stats: ' + workspace.documentRegistry?.reportStats());
21
11
  connection.console.log('');
22
12
  connection.console.log('tsconfig: inferred');
23
13
  const _inferredProject = workspace.getInferredProjectDontCreate();
24
14
  if (_inferredProject) {
25
15
  connection.console.log('loaded: true');
26
- const inferredProject = yield _inferredProject;
16
+ const inferredProject = await _inferredProject;
27
17
  connection.console.log('largest 10 files:');
28
18
  for (const script of [...inferredProject.scripts.values()]
29
- .sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()) !== null && _d !== void 0 ? _d : 0); })
19
+ .sort((a, b) => (b.snapshot?.getLength() ?? 0) - (a.snapshot?.getLength() ?? 0))
30
20
  .slice(0, 10)) {
31
21
  connection.console.log(' - ' + script.fileName);
32
- connection.console.log(` size: ${(_b = script.snapshot) === null || _b === void 0 ? void 0 : _b.getLength()}`);
22
+ connection.console.log(` size: ${script.snapshot?.getLength()}`);
33
23
  }
34
24
  connection.console.log('files:');
35
25
  for (const script of inferredProject.scripts.values()) {
36
26
  connection.console.log(' - ' + script.fileName);
37
- connection.console.log(` size: ${(_c = script.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()}`);
38
- connection.console.log(` ref counts: "${(_e = (_d = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _e === void 0 ? void 0 : _e.call(_d, script.fileName, (_g = (_f = inferredProject.languageServiceHost).getScriptKind) === null || _g === void 0 ? void 0 : _g.call(_f, script.fileName))})"`);
27
+ connection.console.log(` size: ${script.snapshot?.getLength()}`);
28
+ connection.console.log(` ref counts: "${workspace.documentRegistry.getLanguageServiceRefCounts?.(script.fileName, inferredProject.languageServiceHost.getScriptKind?.(script.fileName))})"`);
39
29
  }
40
30
  }
41
31
  else {
@@ -43,40 +33,39 @@ function register(connection, projects, env) {
43
33
  }
44
34
  connection.console.log('');
45
35
  for (const _project of workspace.projects.values()) {
46
- const project = yield _project;
36
+ const project = await _project;
47
37
  connection.console.log('tsconfig: ' + project.tsConfig);
48
38
  connection.console.log('loaded: ' + !!project.getLanguageServiceDontCreate());
49
39
  connection.console.log('largest 10 files:');
50
40
  for (const script of [...project.scripts.values()]
51
- .sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()) !== null && _d !== void 0 ? _d : 0); })
41
+ .sort((a, b) => (b.snapshot?.getLength() ?? 0) - (a.snapshot?.getLength() ?? 0))
52
42
  .slice(0, 10)) {
53
43
  connection.console.log(' - ' + script.fileName);
54
- connection.console.log(` size: ${(_h = script.snapshot) === null || _h === void 0 ? void 0 : _h.getLength()}`);
44
+ connection.console.log(` size: ${script.snapshot?.getLength()}`);
55
45
  }
56
46
  connection.console.log('files:');
57
47
  for (const script of project.scripts.values()) {
58
48
  connection.console.log(' - ' + script.fileName);
59
- connection.console.log(` size: ${(_j = script.snapshot) === null || _j === void 0 ? void 0 : _j.getLength()}`);
60
- connection.console.log(` ref counts: "${(_l = (_k = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _l === void 0 ? void 0 : _l.call(_k, script.fileName, (_o = (_m = project.languageServiceHost).getScriptKind) === null || _o === void 0 ? void 0 : _o.call(_m, script.fileName))})"`);
49
+ connection.console.log(` size: ${script.snapshot?.getLength()}`);
50
+ connection.console.log(` ref counts: "${workspace.documentRegistry.getLanguageServiceRefCounts?.(script.fileName, project.languageServiceHost.getScriptKind?.(script.fileName))})"`);
61
51
  }
62
52
  }
63
53
  connection.console.log('');
64
54
  }
65
- }));
66
- connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
67
- const project = (yield projects.getProject(params.uri));
68
- if (project === null || project === void 0 ? void 0 : project.tsconfig) {
55
+ });
56
+ connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, async (params) => {
57
+ const project = (await projects.getProject(params.uri));
58
+ if (project?.tsconfig) {
69
59
  return { uri: env.fileNameToUri(project.tsconfig) };
70
60
  }
71
- }));
72
- connection.onRequest(protocol_1.GetVirtualFileNamesRequest.type, (document) => __awaiter(this, void 0, void 0, function* () {
73
- var _p, _q, _r;
74
- const project = yield projects.getProject(document.uri);
61
+ });
62
+ connection.onRequest(protocol_1.GetVirtualFileNamesRequest.type, async (document) => {
63
+ const project = await projects.getProject(document.uri);
75
64
  const fileNames = [];
76
65
  if (project) {
77
- const rootVirtualFile = (_q = (_p = project.project) === null || _p === void 0 ? void 0 : _p.getLanguageService().context.core.virtualFiles.getSource(env.uriToFileName(document.uri))) === null || _q === void 0 ? void 0 : _q.root;
66
+ const rootVirtualFile = project.project?.getLanguageService().context.core.virtualFiles.getSource(env.uriToFileName(document.uri))?.root;
78
67
  if (rootVirtualFile) {
79
- const kinds = (_r = document.fileKinds) !== null && _r !== void 0 ? _r : [language_core_1.FileKind.TypeScriptHostFile];
68
+ const kinds = document.fileKinds ?? [language_core_1.FileKind.TypeScriptHostFile];
80
69
  (0, language_core_1.forEachEmbeddedFile)(rootVirtualFile, e => {
81
70
  if (e.snapshot.getLength() && kinds.includes(e.kind)) {
82
71
  fileNames.push(e.fileName);
@@ -85,17 +74,16 @@ function register(connection, projects, env) {
85
74
  }
86
75
  }
87
76
  return fileNames;
88
- }));
89
- connection.onRequest(protocol_1.GetVirtualFileRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
90
- var _s, _t, _u, _v;
91
- const project = yield projects.getProject(params.sourceFileUri);
77
+ });
78
+ connection.onRequest(protocol_1.GetVirtualFileRequest.type, async (params) => {
79
+ const project = await projects.getProject(params.sourceFileUri);
92
80
  if (project) {
93
- const [virtualFile, source] = (_t = (_s = project.project) === null || _s === void 0 ? void 0 : _s.getLanguageService().context.core.virtualFiles.getVirtualFile(params.virtualFileName)) !== null && _t !== void 0 ? _t : [];
81
+ const [virtualFile, source] = project.project?.getLanguageService().context.core.virtualFiles.getVirtualFile(params.virtualFileName) ?? [];
94
82
  if (virtualFile && source) {
95
83
  const mappings = {};
96
84
  for (const mapping of virtualFile.mappings) {
97
- const sourceUri = env.fileNameToUri((_u = mapping.source) !== null && _u !== void 0 ? _u : source.fileName);
98
- (_v = mappings[sourceUri]) !== null && _v !== void 0 ? _v : (mappings[sourceUri] = []);
85
+ const sourceUri = env.fileNameToUri(mapping.source ?? source.fileName);
86
+ mappings[sourceUri] ??= [];
99
87
  mappings[sourceUri].push(mapping);
100
88
  }
101
89
  return {
@@ -104,16 +92,15 @@ function register(connection, projects, env) {
104
92
  };
105
93
  }
106
94
  }
107
- }));
95
+ });
108
96
  connection.onNotification(protocol_1.ReloadProjectNotification.type, () => {
109
97
  projects.reloadProject();
110
98
  });
111
- connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
112
- var _w;
113
- const fs = yield Promise.resolve().then(() => require('fs'));
114
- const project = yield projects.getProject(params.uri);
99
+ connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, async (params) => {
100
+ const fs = await Promise.resolve().then(() => require('fs'));
101
+ const project = await projects.getProject(params.uri);
115
102
  if (project) {
116
- const ls = (_w = (yield project.project)) === null || _w === void 0 ? void 0 : _w.getLanguageServiceDontCreate();
103
+ const ls = (await project.project)?.getLanguageServiceDontCreate();
117
104
  if (ls) {
118
105
  const sourceFiles = new Set(ls.context.host.getScriptFileNames());
119
106
  for (const virtualFile of ls.context.core.typescript.languageServiceHost.getScriptFileNames()) {
@@ -126,7 +113,7 @@ function register(connection, projects, env) {
126
113
  }
127
114
  }
128
115
  }
129
- }));
116
+ });
130
117
  }
131
118
  exports.register = register;
132
119
  //# sourceMappingURL=customFeatures.js.map