Description
Elevator Pitch
Currently language server specifications can only be defined globally and all kernels have to use the same specification. Would it be possible to provide a way for kernels to generate language server specifications dynamically?
Motivation
We are developing Ark (https://github.com/posit-dev/ark), a new Jupyter kernel for R. One specificity of Ark is that it includes an LSP server that lives in the same process as the kernel. This provides the LSP with access to the current state of the workspace so that it is able to provide e.g. completions for global objects interactively defined by the user.
While our main target is the Positron IDE (https://github.com/posit-dev/positron), we would like users of Jupyter apps to be able to connect to our LSP server. The main problem we are facing is that configuration for jupyter-lsp is done via static files (https://jupyterlab-lsp.readthedocs.io/en/latest/Configuring.html) or via the LanguageServerManager
feature which, IIUC, only provides the ability to interpolate from global state, not state specific to a running kernel. This is problematic for us because we need a way to determine which kernel session to connect to.
Design ideas
One approach would be to create a Jupyter request to allow clients to retrieve a language server spec that is specific to the running kernel. When the kernel gets that request, it would respond with a language server spec built dynamically and that conforms with
.The Jupyter protocol states that unknown requests can be ignored. That makes it a bit awkward to send the request unconditionally as this would require a timeout to determine the kernel does not support the request. Instead we could advertise the capability through extended fields in the kernel-info response?
We would also need the ability to run one LSP per notebook/kernel, which is currently not the case (there is some discussion about this in #642).
(It would help if a language server spec could be set for a TCP connection. But that's not necessary as we could work around that and create a CLI util to relay between stdin/stdout and a TCP connection to our server.)