Multi-root workspaces: How to spawn one LS per root?

So far we’ve been using clangd from theia/cpp, but this Theia extension contains workarounds to feed multiple configurations to a single instance of clangd. It looks like it would be much more scalable to have Theia spawn one LS per workspace root until clangd natively supports LSP’s multi-root settings.

I would like to know if this is already implemented, and if not what are our options?

[original thread by Paul Maréchal]

I had something like this working in the Che 6 IDE: a policy that would allow to spawn either one LS per project or one for the whole workspace. The problem is that the adapter from the VS Code extension to the LSP that Theia uses (https://github.com/Microsoft/vscode-languageserver-node#readme) does not support such a policy. IMO, it would be super interesting to contribute such a setting to the framework.

Or maybe you can do it inside the framework, I don’t know. The problem, as I remember it, was that you had to dispatch requests to the proper language server based on the URI, and for some results from the language servers, you had to remember which language server they came from in order to direct follow-up requests to the proper one.

I think this question is moot, since the Theia language client will be soon removed. In a VS Code extension one can spawn a new language client whenever a file is opened from a new, independent (non-nested) root: https://github.com/microsoft/vscode-extension-samples/blob/master/lsp-multi-server-sample/client/src/extension.ts#L55

i.e. this is the initial language client: https://github.com/microsoft/vscode-extension-samples/blob/master/lsp-multi-server-sample/client/src/extension.ts#L76

and this is where extra ones are created, as needed: https://github.com/microsoft/vscode-extension-samples/blob/master/lsp-multi-server-sample/client/src/extension.ts#L103

@tsmaeder The sample extension I linked above should still work in Theia, correct? It’s just that there is no way to set this behaviour so that it’s automatic and controlled by a policy? Or do I misunderstand?

It would work, but without looking inside the LanguageClient implementation, I have not idea if it does what we want. In particular, I don’t know how requests are dispatched to the various language servers and how results are merged. We’d have to understand whether the default algorithms in monaco are what we want.

Does it mean that vscode-languageclient does not respect WorkspaceFoldersServerCapabilities.supported?

I would expect that this library looks at this property and then decides whether to start a LSP per a workspace root or for the entire workspace.

That might seem reasonable, but I just don’t know if that’s the case.

@paul-marechal I think you should raise a question in https://github.com/microsoft/vscode-languageserver-node

It should not be different in VS Code.