From 8caeede0eee42b29882c3e52b1d2b1751e626273 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Sun, 18 Jun 2023 21:44:25 +0100 Subject: [PATCH] Support optional `.virtual_documents` Cherry-picked from https://github.com/jupyter-lsp/jupyterlab-lsp/pull/930 --- packages/lsp/src/connection_manager.ts | 31 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/lsp/src/connection_manager.ts b/packages/lsp/src/connection_manager.ts index cd1f684a117a..d5c5f953c3dd 100644 --- a/packages/lsp/src/connection_manager.ts +++ b/packages/lsp/src/connection_manager.ts @@ -547,20 +547,16 @@ export namespace DocumentConnectionManager { virtualDocument: VirtualDocument, language: string ): IURIs | undefined { - const { settings } = Private.getLanguageServerManager(); - const wsBase = settings.wsUrl; + const serverManager = Private.getLanguageServerManager(); + const wsBase = serverManager.settings.wsUrl; const rootUri = PageConfig.getOption('rootUri'); const virtualDocumentsUri = PageConfig.getOption('virtualDocumentsUri'); - const baseUri = virtualDocument.hasLspSupportedFile - ? rootUri - : virtualDocumentsUri; - // for now take the best match only - const matchingServers = - Private.getLanguageServerManager().getMatchingServers({ - language - }); + const serverOptions: ILanguageServerManager.IGetServerIdOptions = { + language + }; + const matchingServers = serverManager.getMatchingServers(serverOptions); const languageServerId = matchingServers.length === 0 ? null : matchingServers[0]; @@ -568,6 +564,21 @@ export namespace DocumentConnectionManager { return; } + const specs = serverManager.getMatchingSpecs(serverOptions); + const spec = specs.get(languageServerId); + if (!spec) { + console.warn( + `Specification not available for server ${languageServerId}` + ); + } + const requiresOnDiskFiles = spec?.requires_documents_on_disk ?? true; + const supportsInMemoryFiles = !requiresOnDiskFiles; + + const baseUri = + virtualDocument.hasLspSupportedFile || supportsInMemoryFiles + ? rootUri + : virtualDocumentsUri; + // workaround url-parse bug(s) (see https://github.com/jupyter-lsp/jupyterlab-lsp/issues/595) let documentUri = URLExt.join(baseUri, virtualDocument.uri); if (