@volar/language-server 1.3.0-alpha.3 → 1.4.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,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.createProject = void 0;
12
3
  const embeddedLS = require("@volar/language-service");
@@ -14,243 +5,238 @@ const path = require("typesafe-path");
14
5
  const vscode = require("vscode-languageserver");
15
6
  const vscode_uri_1 = require("vscode-uri");
16
7
  const types_1 = require("../types");
8
+ const serverConfig_1 = require("./utils/serverConfig");
17
9
  const uriMap_1 = require("./utils/uriMap");
18
- function createProject(context) {
19
- var _a;
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const uriToFileName = context.workspace.workspaces.server.runtimeEnv.uriToFileName;
22
- const fileNameToUri = context.workspace.workspaces.server.runtimeEnv.fileNameToUri;
23
- const sys = context.workspace.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic || !context.workspace.workspaces.fileSystemHost
24
- ? {
25
- newLine: '\n',
26
- useCaseSensitiveFileNames: false,
27
- fileExists: () => false,
28
- readFile: () => undefined,
29
- readDirectory: () => [],
30
- getCurrentDirectory: () => '',
31
- realpath: () => '',
32
- resolvePath: () => '',
10
+ async function createProject(context) {
11
+ const uriToFileName = context.workspace.workspaces.server.runtimeEnv.uriToFileName;
12
+ const fileNameToUri = context.workspace.workspaces.server.runtimeEnv.fileNameToUri;
13
+ const sys = context.workspace.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic || !context.workspace.workspaces.fileSystemHost
14
+ ? {
15
+ newLine: '\n',
16
+ useCaseSensitiveFileNames: false,
17
+ fileExists: () => false,
18
+ readFile: () => undefined,
19
+ readDirectory: () => [],
20
+ getCurrentDirectory: () => '',
21
+ realpath: () => '',
22
+ resolvePath: () => '',
23
+ }
24
+ : context.workspace.workspaces.fileSystemHost.getWorkspaceFileSystem(context.rootUri);
25
+ let typeRootVersion = 0;
26
+ let projectVersion = 0;
27
+ let projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
28
+ let languageService;
29
+ let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
30
+ const scripts = (0, uriMap_1.createUriMap)(fileNameToUri);
31
+ const languageServiceHost = createLanguageServiceHost();
32
+ const disposeWatchEvent = context.workspace.workspaces.fileSystemHost?.onDidChangeWatchedFiles(params => {
33
+ onWorkspaceFilesChanged(params.changes);
34
+ });
35
+ const disposeDocChange = context.workspace.workspaces.documents.onDidChangeContent(() => {
36
+ projectVersion++;
37
+ projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
38
+ });
39
+ return {
40
+ tsConfig: context.tsConfig,
41
+ scripts,
42
+ languageServiceHost,
43
+ getLanguageService,
44
+ getLanguageServiceDontCreate: () => languageService,
45
+ getParsedCommandLine: () => parsedCommandLine,
46
+ tryAddFile: (fileName) => {
47
+ if (!parsedCommandLine.fileNames.includes(fileName)) {
48
+ parsedCommandLine.fileNames.push(fileName);
49
+ projectVersion++;
50
+ projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
33
51
  }
34
- : context.workspace.workspaces.fileSystemHost.getWorkspaceFileSystem(context.rootUri);
35
- let typeRootVersion = 0;
36
- let projectVersion = 0;
37
- let projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
38
- let languageService;
39
- let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
40
- const scripts = (0, uriMap_1.createUriMap)(fileNameToUri);
41
- const languageServiceHost = createLanguageServiceHost();
42
- const disposeWatchEvent = (_a = context.workspace.workspaces.fileSystemHost) === null || _a === void 0 ? void 0 : _a.onDidChangeWatchedFiles(params => {
43
- onWorkspaceFilesChanged(params.changes);
44
- });
45
- const disposeDocChange = context.workspace.workspaces.documents.onDidChangeContent(() => {
46
- projectVersion++;
47
- projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
48
- });
49
- return {
50
- tsConfig: context.tsConfig,
51
- scripts,
52
- languageServiceHost,
53
- getLanguageService,
54
- getLanguageServiceDontCreate: () => languageService,
55
- getParsedCommandLine: () => parsedCommandLine,
56
- tryAddFile: (fileName) => {
57
- if (!parsedCommandLine.fileNames.includes(fileName)) {
58
- parsedCommandLine.fileNames.push(fileName);
59
- projectVersion++;
60
- projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
52
+ },
53
+ dispose,
54
+ };
55
+ function getLanguageService() {
56
+ if (!languageService) {
57
+ let config = (context.workspace.rootUri.scheme === 'file' ? (0, serverConfig_1.loadConfig)(context.workspace.rootUri.path, context.workspace.workspaces.initOptions.configFilePath) : {}) ?? {};
58
+ const options = {
59
+ uriToFileName,
60
+ fileNameToUri,
61
+ rootUri: context.rootUri,
62
+ host: languageServiceHost,
63
+ get config() {
64
+ return config;
65
+ },
66
+ locale: context.workspace.workspaces.initParams.locale,
67
+ configurationHost: context.workspace.workspaces.configurationHost,
68
+ fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
69
+ documentContext: getDocumentContext(fileNameToUri, uriToFileName, context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
70
+ schemaRequestService: async (uri) => {
71
+ const protocol = uri.substring(0, uri.indexOf(':'));
72
+ const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
73
+ if (builtInHandler) {
74
+ return await builtInHandler(uri) ?? '';
75
+ }
76
+ return '';
77
+ },
78
+ };
79
+ const lsCtx = {
80
+ project: context,
81
+ options,
82
+ sys,
83
+ host: languageServiceHost,
84
+ };
85
+ for (const plugin of context.workspace.workspaces.plugins) {
86
+ if (plugin.resolveConfig) {
87
+ config = plugin.resolveConfig(config, { typescript: lsCtx.project.workspace.workspaces.ts }, lsCtx);
61
88
  }
62
- },
63
- dispose,
64
- };
65
- function getLanguageService() {
66
- var _a, _b, _c, _d, _e, _f;
67
- if (!languageService) {
68
- const config = {
69
- languages: Object.assign({}, (_a = context.serverConfig) === null || _a === void 0 ? void 0 : _a.languages),
70
- plugins: Object.assign({}, (_b = context.serverConfig) === null || _b === void 0 ? void 0 : _b.plugins),
71
- lint: Object.assign(Object.assign({}, (_c = context.serverConfig) === null || _c === void 0 ? void 0 : _c.lint), { rules: Object.assign({}, (_e = (_d = context.serverConfig) === null || _d === void 0 ? void 0 : _d.lint) === null || _e === void 0 ? void 0 : _e.rules) }),
72
- };
73
- const options = {
74
- uriToFileName,
75
- fileNameToUri,
76
- rootUri: context.rootUri,
77
- host: languageServiceHost,
78
- config,
79
- locale: context.workspace.workspaces.initParams.locale,
80
- configurationHost: context.workspace.workspaces.configurationHost,
81
- fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
82
- documentContext: getDocumentContext(fileNameToUri, uriToFileName, context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
83
- schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
84
- var _g;
85
- const protocol = uri.substring(0, uri.indexOf(':'));
86
- const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
87
- if (builtInHandler) {
88
- return (_g = yield builtInHandler(uri)) !== null && _g !== void 0 ? _g : '';
89
- }
90
- return '';
91
- }),
92
- };
93
- const lsCtx = {
94
- project: context,
95
- options,
96
- sys,
97
- host: languageServiceHost,
98
- };
99
- for (const plugin of context.workspace.workspaces.plugins) {
100
- (_f = plugin.resolveConfig) === null || _f === void 0 ? void 0 : _f.call(plugin, config, lsCtx);
89
+ }
90
+ languageService = embeddedLS.createLanguageService(options, context.documentRegistry);
91
+ }
92
+ return languageService;
93
+ }
94
+ async function onWorkspaceFilesChanged(changes) {
95
+ const _projectVersion = projectVersion;
96
+ for (const change of changes) {
97
+ const script = scripts.uriGet(change.uri);
98
+ if (script && (change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Created)) {
99
+ if (script.version >= 0) {
100
+ script.version = -1;
101
+ }
102
+ else {
103
+ script.version--;
101
104
  }
102
- languageService = embeddedLS.createLanguageService(options, context.documentRegistry);
103
105
  }
104
- return languageService;
106
+ else if (script && change.type === vscode.FileChangeType.Deleted) {
107
+ scripts.uriDelete(change.uri);
108
+ }
109
+ if (script
110
+ || change.uri.endsWith('.d.ts')
111
+ || change.uri.endsWith('/package.json')) {
112
+ projectVersion++;
113
+ }
105
114
  }
106
- function onWorkspaceFilesChanged(changes) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- const _projectVersion = projectVersion;
109
- for (const change of changes) {
110
- const script = scripts.uriGet(change.uri);
111
- if (script && (change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Created)) {
112
- if (script.version >= 0) {
113
- script.version = -1;
114
- }
115
- else {
116
- script.version--;
117
- }
118
- }
119
- else if (script && change.type === vscode.FileChangeType.Deleted) {
120
- scripts.uriDelete(change.uri);
115
+ const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
116
+ const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
117
+ if (creates.length || deletes.length) {
118
+ parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
119
+ projectVersion++;
120
+ typeRootVersion++;
121
+ }
122
+ if (_projectVersion !== projectVersion) {
123
+ projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
124
+ }
125
+ }
126
+ function createLanguageServiceHost() {
127
+ const token = {
128
+ isCancellationRequested() {
129
+ return context.workspace.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
130
+ },
131
+ throwIfCancellationRequested() { },
132
+ };
133
+ let host = {
134
+ // ts
135
+ getNewLine: () => sys.newLine,
136
+ useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
137
+ readFile: sys.readFile,
138
+ writeFile: sys.writeFile,
139
+ directoryExists: sys.directoryExists,
140
+ getDirectories: sys.getDirectories,
141
+ readDirectory: sys.readDirectory,
142
+ realpath: sys.realpath,
143
+ fileExists: sys.fileExists,
144
+ getCurrentDirectory: () => uriToFileName(context.rootUri.toString()),
145
+ getProjectReferences: () => parsedCommandLine.projectReferences,
146
+ getCancellationToken: () => token,
147
+ // custom
148
+ getDefaultLibFileName: options => {
149
+ if (context.workspace.workspaces.initOptions.typescript && context.workspace.workspaces.ts) {
150
+ try {
151
+ return context.workspace.workspaces.ts.getDefaultLibFilePath(options);
121
152
  }
122
- if (script
123
- || change.uri.endsWith('.d.ts')
124
- || change.uri.endsWith('/package.json')) {
125
- projectVersion++;
153
+ catch {
154
+ // web
155
+ const tsdk = context.workspace.workspaces.initOptions.typescript.tsdk;
156
+ return tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
126
157
  }
127
158
  }
128
- const creates = changes.filter(change => change.type === vscode.FileChangeType.Created);
129
- const deletes = changes.filter(change => change.type === vscode.FileChangeType.Deleted);
130
- if (creates.length || deletes.length) {
131
- parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, uriToFileName(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
132
- projectVersion++;
133
- typeRootVersion++;
134
- }
135
- if (_projectVersion !== projectVersion) {
136
- projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
137
- }
159
+ return '';
160
+ },
161
+ getProjectVersion: () => projectVersion.toString(),
162
+ getTypeRootsVersion: () => typeRootVersion,
163
+ getScriptFileNames: () => parsedCommandLine.fileNames,
164
+ getCompilationSettings: () => parsedCommandLine.options,
165
+ getScriptVersion,
166
+ getScriptSnapshot,
167
+ getTypeScriptModule: context.workspace.workspaces.ts ? () => {
168
+ return context.workspace.workspaces.ts;
169
+ } : undefined,
170
+ getScriptLanguageId: (fileName) => {
171
+ return context.workspace.workspaces.documents.data.pathGet(fileName)?.languageId;
172
+ },
173
+ };
174
+ if (context.workspace.workspaces.initOptions.noProjectReferences) {
175
+ host.getProjectReferences = undefined;
176
+ host.getCompilationSettings = () => ({
177
+ ...parsedCommandLine.options,
178
+ rootDir: undefined,
179
+ composite: false,
138
180
  });
139
181
  }
140
- function createLanguageServiceHost() {
141
- const token = {
142
- isCancellationRequested() {
143
- return context.workspace.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
144
- },
145
- throwIfCancellationRequested() { },
146
- };
147
- let host = {
148
- // ts
149
- getNewLine: () => sys.newLine,
150
- useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
151
- readFile: sys.readFile,
152
- writeFile: sys.writeFile,
153
- directoryExists: sys.directoryExists,
154
- getDirectories: sys.getDirectories,
155
- readDirectory: sys.readDirectory,
156
- realpath: sys.realpath,
157
- fileExists: sys.fileExists,
158
- getCurrentDirectory: () => uriToFileName(context.rootUri.toString()),
159
- getProjectReferences: () => parsedCommandLine.projectReferences,
160
- getCancellationToken: () => token,
161
- // custom
162
- getDefaultLibFileName: options => {
163
- if (context.workspace.workspaces.initOptions.typescript && context.workspace.workspaces.ts) {
164
- try {
165
- return context.workspace.workspaces.ts.getDefaultLibFilePath(options);
166
- }
167
- catch (_a) {
168
- // web
169
- const tsdk = context.workspace.workspaces.initOptions.typescript.tsdk;
170
- return tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
171
- }
172
- }
173
- return '';
174
- },
175
- getProjectVersion: () => projectVersion.toString(),
176
- getTypeRootsVersion: () => typeRootVersion,
177
- getScriptFileNames: () => parsedCommandLine.fileNames,
178
- getCompilationSettings: () => parsedCommandLine.options,
179
- getScriptVersion,
180
- getScriptSnapshot,
181
- getTypeScriptModule: context.workspace.workspaces.ts ? () => {
182
- return context.workspace.workspaces.ts;
183
- } : undefined,
184
- getScriptLanguageId: (fileName) => {
185
- var _a;
186
- return (_a = context.workspace.workspaces.documents.data.pathGet(fileName)) === null || _a === void 0 ? void 0 : _a.languageId;
187
- },
188
- };
189
- if (context.workspace.workspaces.initOptions.noProjectReferences) {
190
- host.getProjectReferences = undefined;
191
- host.getCompilationSettings = () => (Object.assign(Object.assign({}, parsedCommandLine.options), { rootDir: undefined, composite: false }));
182
+ if (context.workspace.workspaces.tsLocalized) {
183
+ host.getLocalizedDiagnosticMessages = () => context.workspace.workspaces.tsLocalized;
184
+ }
185
+ return host;
186
+ function getScriptVersion(fileName) {
187
+ const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
188
+ if (doc) {
189
+ return doc.version.toString();
192
190
  }
193
- if (context.workspace.workspaces.tsLocalized) {
194
- host.getLocalizedDiagnosticMessages = () => context.workspace.workspaces.tsLocalized;
191
+ return scripts.pathGet(fileName)?.version.toString() ?? '';
192
+ }
193
+ function getScriptSnapshot(fileName) {
194
+ const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
195
+ if (doc) {
196
+ return doc.getSnapshot();
195
197
  }
196
- return host;
197
- function getScriptVersion(fileName) {
198
- var _a, _b;
199
- const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
200
- if (doc) {
201
- return doc.version.toString();
202
- }
203
- return (_b = (_a = scripts.pathGet(fileName)) === null || _a === void 0 ? void 0 : _a.version.toString()) !== null && _b !== void 0 ? _b : '';
198
+ const script = scripts.pathGet(fileName);
199
+ if (script && script.snapshotVersion === script.version) {
200
+ return script.snapshot;
204
201
  }
205
- function getScriptSnapshot(fileName) {
206
- var _a;
207
- const doc = context.workspace.workspaces.documents.data.pathGet(fileName);
208
- if (doc) {
209
- return doc.getSnapshot();
210
- }
211
- const script = scripts.pathGet(fileName);
212
- if (script && script.snapshotVersion === script.version) {
213
- return script.snapshot;
202
+ if (context.workspace.workspaces.ts && sys.fileExists(fileName)) {
203
+ if (context.workspace.workspaces.initOptions.maxFileSize) {
204
+ const fileSize = sys.getFileSize?.(fileName);
205
+ if (fileSize !== undefined && fileSize > context.workspace.workspaces.initOptions.maxFileSize) {
206
+ console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${context.workspace.workspaces.initOptions.maxFileSize}bytes)`);
207
+ return context.workspace.workspaces.ts.ScriptSnapshot.fromString('');
208
+ }
214
209
  }
215
- if (context.workspace.workspaces.ts && sys.fileExists(fileName)) {
216
- if (context.workspace.workspaces.initOptions.maxFileSize) {
217
- const fileSize = (_a = sys.getFileSize) === null || _a === void 0 ? void 0 : _a.call(sys, fileName);
218
- if (fileSize !== undefined && fileSize > context.workspace.workspaces.initOptions.maxFileSize) {
219
- console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${context.workspace.workspaces.initOptions.maxFileSize}bytes)`);
220
- return context.workspace.workspaces.ts.ScriptSnapshot.fromString('');
221
- }
210
+ const text = sys.readFile(fileName, 'utf8');
211
+ if (text !== undefined) {
212
+ const snapshot = context.workspace.workspaces.ts.ScriptSnapshot.fromString(text);
213
+ if (script) {
214
+ script.snapshot = snapshot;
215
+ script.snapshotVersion = script.version;
222
216
  }
223
- const text = sys.readFile(fileName, 'utf8');
224
- if (text !== undefined) {
225
- const snapshot = context.workspace.workspaces.ts.ScriptSnapshot.fromString(text);
226
- if (script) {
227
- script.snapshot = snapshot;
228
- script.snapshotVersion = script.version;
229
- }
230
- else {
231
- scripts.pathSet(fileName, {
232
- version: -1,
233
- fileName: fileName,
234
- snapshot: snapshot,
235
- snapshotVersion: -1,
236
- });
237
- }
238
- return snapshot;
217
+ else {
218
+ scripts.pathSet(fileName, {
219
+ version: -1,
220
+ fileName: fileName,
221
+ snapshot: snapshot,
222
+ snapshotVersion: -1,
223
+ });
239
224
  }
225
+ return snapshot;
240
226
  }
241
227
  }
242
228
  }
243
- function dispose() {
244
- languageService === null || languageService === void 0 ? void 0 : languageService.dispose();
245
- scripts.clear();
246
- disposeWatchEvent === null || disposeWatchEvent === void 0 ? void 0 : disposeWatchEvent();
247
- disposeDocChange();
248
- }
249
- });
229
+ }
230
+ function dispose() {
231
+ languageService?.dispose();
232
+ scripts.clear();
233
+ disposeWatchEvent?.();
234
+ disposeDocChange();
235
+ }
250
236
  }
251
237
  exports.createProject = createProject;
252
238
  function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
253
- const extraFileExtensions = plugins.map(plugin => { var _a; return (_a = plugin.tsconfigExtraFileExtensions) !== null && _a !== void 0 ? _a : []; }).flat();
239
+ const extraFileExtensions = plugins.map(plugin => plugin.extraFileExtensions ?? []).flat();
254
240
  if (ts) {
255
241
  try {
256
242
  let content;
@@ -268,7 +254,7 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
268
254
  content.fileNames = content.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
269
255
  return content;
270
256
  }
271
- catch (_a) {
257
+ catch {
272
258
  // will be failed if web fs host first result not ready
273
259
  }
274
260
  }
@@ -281,7 +267,6 @@ function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
281
267
  function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
282
268
  const documentContext = {
283
269
  resolveReference: (ref, base) => {
284
- var _a, _b;
285
270
  if (ts && host) { // support tsconfig.json paths
286
271
  const isUri = base.indexOf('://') >= 0;
287
272
  const resolveResult = ts.resolveModuleName(ref, isUri ? uriToFileName(base) : base, host.getCompilationSettings(), host);
@@ -290,7 +275,7 @@ function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
290
275
  if (!failedLookupLocations) {
291
276
  console.warn(`[volar] failedLookupLocations not exists, ts: ${ts.version}`);
292
277
  }
293
- for (let failed of failedLookupLocations !== null && failedLookupLocations !== void 0 ? failedLookupLocations : []) {
278
+ for (let failed of failedLookupLocations ?? []) {
294
279
  const fileName = path.basename(failed);
295
280
  if (fileName === 'index.d.ts' || fileName === '*.d.ts') {
296
281
  dirs.add(path.dirname(failed));
@@ -306,7 +291,7 @@ function getDocumentContext(fileNameToUri, uriToFileName, ts, host, rootUri) {
306
291
  }
307
292
  }
308
293
  for (const dir of dirs) {
309
- if ((_b = (_a = host.directoryExists) === null || _a === void 0 ? void 0 : _a.call(host, dir)) !== null && _b !== void 0 ? _b : true) {
294
+ if (host.directoryExists?.(dir) ?? true) {
310
295
  return isUri ? fileNameToUri(dir) : dir;
311
296
  }
312
297
  }