REditorSupport / languageserver

An implementation of the Language Server Protocol for R
Other
564 stars 91 forks source link

Handle multi workspace folders #621

Open renkun-ken opened 1 year ago

renkun-ken commented 1 year ago

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:

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.

Fred-Wu commented 1 year ago

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?

renkun-ken commented 1 year ago

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.

randy3k commented 1 year ago

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