languageserver icon indicating copy to clipboard operation
languageserver copied to clipboard

Handle multi workspace folders

Open renkun-ken opened this issue 1 year ago • 3 comments

Currently, we only support working with a single workspace in a Language Server session. The support of multi-root workspace (i.e. multiple workspace folders) is implemented on client side. For example, in vscode-R, we spawn a language server for each workspace folder and use documentSelector to make each language server only handle requests from the corresponding workspace folder.

However, the approach is somehow problematic in the following aspects:

  • Untitled documents do not belong to any workspace folder.
  • Some documents are stored in a workspace folder, but they should mostly be treated independently, i.e. rmd, notebooks, etc.
  • Each language server will by default spawns multiple child processes to handle parse, resolve, and diagnostics requests, which is too expensive for an average PC.

Therefore, I'd like to add native support for multi-root workspace in langaugeserver, and on client side, it just needs one client and one server to handle all requests. On server side, it seems that each workspace folder will need a process to start from the workspace folder so that the Rprofile and folder-specific settings could be properly respected.

renkun-ken avatar May 30 '23 09:05 renkun-ken

As this has now been incorporated in the new release, could you provide an example for how to use this feature when working with, say, 2 projects?

For languageserver to work with R, does this involve to open a second R terminal, or does it only matter about respecting the settings under each project?

Fred-Wu avatar Jun 12 '23 08:06 Fred-Wu

vscode-R just adds a new setting r.lsp.multiServer to allow user to disable multi-server approach so that a single languageserver handles all requests from r and rmd documents.

On languageserver side, the implementation is not yet ready, mainly due to the complexity of handling multiple workspace folders where each uses a separate .Rprofile setup (e.g. to activate renv, common library(...), modify libPaths, etc.), so that languageserver may have to start an R session from each workspace folder so that the behavior of each R session is consistent with the setup for each folder. This requires some important changes to the design of languageserver itself. I'm still working on this.

renkun-ken avatar Jun 12 '23 09:06 renkun-ken

If we ignore the .Rprofile related issues, the work needed in languageserver is to

  1. move text_sync to Workspace class
  2. Allow per workspace task_manager
  3. obtain the list of workspaces in on_initialize

randy3k avatar Jun 22 '23 17:06 randy3k