Skip to content

Commit fac9ff6

Browse files
committed
Use rootUri when server does not require on-disk files
1 parent 2a7126f commit fac9ff6

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

packages/jupyterlab-lsp/src/connection_manager.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -391,27 +391,36 @@ export namespace DocumentConnectionManager {
391391
virtual_document: VirtualDocument,
392392
language: string
393393
): IURIs {
394-
const { settings } = Private.getLanguageServerManager();
395-
const wsBase = settings.wsUrl;
394+
const serverManager = Private.getLanguageServerManager();
395+
const wsBase = serverManager.settings.wsUrl;
396396
const rootUri = PageConfig.getOption('rootUri');
397397
const virtualDocumentsUri = PageConfig.getOption('virtualDocumentsUri');
398398

399-
const baseUri = virtual_document.has_lsp_supported_file
400-
? rootUri
401-
: virtualDocumentsUri;
402-
403399
// for now take the best match only
404-
const matchingServers =
405-
Private.getLanguageServerManager().getMatchingServers({
406-
language
407-
});
408-
const language_server_id =
400+
const serverOptions: ILanguageServerManager.IGetServerIdOptions = {
401+
language
402+
};
403+
const matchingServers = serverManager.getMatchingServers(serverOptions);
404+
const languageServerId =
409405
matchingServers.length === 0 ? null : matchingServers[0];
410406

411-
if (language_server_id === null) {
407+
if (languageServerId === null) {
412408
throw `No language server installed for language ${language}`;
413409
}
414410

411+
const specs = serverManager.getMatchingSpecs(serverOptions);
412+
const spec = specs.get(languageServerId);
413+
if (!spec) {
414+
throw `Specification not available for server ${languageServerId}`;
415+
}
416+
const requiresOnDiskFiles = spec.requires_documents_on_disk ?? true;
417+
const supportsInMemoryFiles = !requiresOnDiskFiles;
418+
419+
const baseUri =
420+
virtual_document.has_lsp_supported_file || supportsInMemoryFiles
421+
? rootUri
422+
: virtualDocumentsUri;
423+
415424
// workaround url-parse bug(s) (see https://github.com/jupyter-lsp/jupyterlab-lsp/issues/595)
416425
let documentUri = URLExt.join(baseUri, virtual_document.uri);
417426
if (
@@ -435,7 +444,7 @@ export namespace DocumentConnectionManager {
435444
wsBase,
436445
ILanguageServerManager.URL_NS,
437446
'ws',
438-
language_server_id
447+
languageServerId
439448
)
440449
};
441450
}

0 commit comments

Comments
 (0)