Skip to content

Commit

Permalink
Support optional .virtual_documents
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Jun 18, 2023
1 parent 5246f1d commit 8caeede
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions packages/lsp/src/connection_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,27 +547,38 @@ 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];

if (languageServerId === null) {
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 (
Expand Down

0 comments on commit 8caeede

Please sign in to comment.