Repository navigation
Description
This picks up the original request of #1352: several instances of one language server definition in a project, each serving a part of it. #1352 turned into the workspace folder support of #1492, which decides which folders the one instance sees. That doesn't help when each instance has to be started with a different Python interpreter.
Use case
RobotCode, the Robot Framework plugin, uses LSP4IJ. Its language server always has to run with the Python interpreter of the project or module whose files it analyses, and it uses the Robot Framework installed in that interpreter's environment. The plugin ships only the server's own code and starts it with that interpreter.
An IntelliJ project can contain several modules, each with its own interpreter, for example:
my-tests/ IntelliJ project
├── web-tests/ module, .venv with Python 3.12, Robot Framework 7.3 and the Browser library
│ ├── robot.toml
│ └── tests/
└── api-tests/ module, .venv with Python 3.10, Robot Framework 6.1 and RequestsLibrary
├── robot.toml
└── tests/
Such projects are common: IntelliJ IDEA lets each module have its own Python SDK, and the workspace mode of PyCharm 2026.2, enabled by default, makes every directory with a pyproject.toml a module of its own; in Poetry and Hatch monorepos each of them gets its own environment.
Each of these modules needs a server process started with the module's own interpreter, because the server analyses the module with the module's environment:
- it parses with the Robot Framework version installed there;
- it resolves what the tests import, such as Robot Framework libraries, Python packages, variable files and resource files shipped in packages, on that environment's Python path, and imports the libraries and variable files, with all their dependencies, to get their keywords and variables in the versions installed there;
- completion for imports offers the packages and files installed there;
- at startup it reads the module's
robot.tomland puts the environment variables and Python paths from it into its own process.
Today LSP4IJ starts one instance per project, so all modules are analysed with one interpreter: imports that only another module's environment provides fail, keywords and their documentation come from the wrong versions, and users are told that Robot Framework is missing in a module whose interpreter has it.
Workspace folders don't solve this: one process still runs with one interpreter. This is different from the Pyright case in #1352, where one process can serve all folders.
VS Code does this
In #1352 you wrote that you would implement this if VS Code can manage the use case. It can:
- vscode-languageclient has the client option
workspaceFolder, which locks a client to one folder:rootUriandworkspaceFoldersininitializeare that folder, and the client doesn't register the workspace folder feature. - The official sample lsp-multi-server-sample "demonstrates how to start a server per workspace folder".
- RobotCode's VS Code extension does exactly that: one
LanguageClientper workspace folder, started with the folder's Python interpreter and the folder as working directory.
Neovim works the same way: by default it reuses a running client only if the server name and the root directory match.
Proposal
- A server definition can tell which instance serves a file. The default stays one instance per project; other choices are one instance per module, per content root (the IntelliJ counterpart of a VS Code workspace folder), or a grouping that the adopter computes.
- LSP4IJ passes the instance's scope to the factory when it creates the connection provider and the language client, so the command line, the working directory and the initialization options can differ per instance.
- Each instance is initialized with the roots of its scope as
rootUriandworkspaceFolders, like a VS Code client locked to a workspace folder. - An instance starts when the first file of its scope is opened and stops on its own, as servers do today.
- There is API to get the instance for a file and all instances of a definition.
LanguageServerManager.startandstopact on all instances, as they already do for every wrapper of a definition. - The Language Servers view shows each instance as a process of its own, named after its scope, with its own log and traces.
- VFS events and file operations go to the instance whose scope contains the file.
Definitions that don't opt in keep today's behavior: the new methods are default methods, so existing factories compile and run unchanged, and the project scope keeps one instance per project with the same root, workspace folders and file events.
A first sketch of the API:
public interface LanguageServerFactory {
// ... existing methods
/**
* Returns the scope of the instance that serves the given file. Files with equal scopes share one instance.
* The default is the project, which keeps one instance per project.
*/
default @NotNull LanguageServerScope getServerScope(@NotNull VirtualFile file, @NotNull Project project) {
return LanguageServerScope.project(project);
}
default @NotNull StreamConnectionProvider createConnectionProvider(@NotNull Project project,
@NotNull LanguageServerScope scope) {
return createConnectionProvider(project);
}
default @NotNull LanguageClientImpl createLanguageClient(@NotNull Project project,
@NotNull LanguageServerScope scope) {
return createLanguageClient(project);
}
}LanguageServerScope would have an id for equality, a display name and its roots, with factories such as project(Project), module(Module) and folder(VirtualFile). User-defined servers could get the same choice in their settings later, for example one instance per workspace folder of the configured strategy.
The current code is close to this: collectLanguageServersFromDefinition reuses a started wrapper only if it can operate on the file and creates a new one otherwise, but canOperate(VirtualFile) returns true for every existing file, and LanguageServerWrapper has a constructor with an initialPath that nothing reads. The core change would give each wrapper its scope, compare scopes in canOperate, and use the scope for the root, the workspace folders and the factory calls.
If you agree with the direction, I could prepare a PR with tests. Which shape of the API would you prefer? I could also provide a sample project with two modules, two virtual environments and different Robot Framework versions.
AI/tooling disclosure: This issue was prepared with assistance from Claude Code. I reviewed the result manually and understand the use case and the proposal.
Activity
angelozerr commentedon Oct 31, 2026
@d-biehl it not a trivial issue. We need:
lagergren commentedon Nov 3, 2026
I think this would be a really powerful feature. Is work progressing or hasn't anything been started?
angelozerr commentedon Nov 3, 2026
Nothing for he moment.
d-biehl commentedon Nov 3, 2026
I'm working on it...
d-biehl commentedon Nov 3, 2026
A correction to point 7 of the proposal, "VFS events and file operations go to the instance whose scope contains the file": that was wrong, and the point can be dropped.
Each instance should get the file events and file operations that match what it registered, also for files outside its scope. Each wrapper already works like that today, so nothing has to change here. VS Code does the same: a client locked to a workspace folder creates its watchers from the registered globs and matches file operations by scheme and pattern, without looking at the folder.
Servers can depend on this. RobotCode's server watches the locations of what a module imports, so its instance has to hear about changes to a shared file outside the module.
angelozerr commentedon Nov 3, 2026
@d-biehl perhaps I am wrong but it could be a good idea to extend workspace folder strategy to define those folder instance.
User defined uses the configurable workspace strategy.
See doc at https://github.com/redhat-developer/lsp4ij/blob/main/docs/UserDefinedLanguageServer.md#workspace-folders-tab
By extending workspace strategy, user could reuse the Testing configuration to define folder server instance and workspace folder both.
It is also important to see those server instance in the Language Server view. Today the tree is filled with Language Server as root and process as child. We should see several process when we will have several instances (and it should be nice to see the folder).
test: cover the workspace folders of the built-in strategies
feat: let a workspace folder strategy ask for one language server ins…
feat: start an instance of a language server with its workspace folder
feat: show the workspace folder of a language server instance in its …
d-biehl commentedon Nov 3, 2026
@angelozerr Your suggestion works well, so I'm following it: the workspace folder strategy now decides the instances, and the Language Servers view shows each one with its folder. It's in the draft #1853. User-defined servers and the "Testing your configuration" preview come next. Feedback there is welcome.
angelozerr commentedon Nov 4, 2026
It is a super news that you can extend workspace strategy.
But I think we should also provide the capability to define workspace folders inside a server instance level.
feat: show a process node for each instance of a language server
feat: show the logs of an instance of a language server in its own node
test: cover the workspace folders of the built-in strategies
60 remaining items
feat: show the logs of an instance of a language server in its own node
test: cover the workspace folders of the built-in strategies
feat: let a workspace folder strategy ask for one language server ins…
feat: start an instance of a language server with its workspace folder
feat: show the workspace folder of a language server instance in its …
test: remove a project strategy test that depends on a platform event
feat: separate language server instances from workspace folders
feat: configure language server instances in the workspace folder con…
feat: run an instance of a user-defined language server in its root
feat: replace the language server instances when their configuration …
feat: show the language server instances in the workspace folders pre…
feat: several instances of one language server per project (#1853)
lagergren commentedon Nov 13, 2026
Done in 0.30.0 by #1853, which follows the plan above: a workspace folder strategy can give a language server several instances (
hasServerInstancesandgetServerInstanceRoot), each with its own root and environment, and the Language Servers view shows each instance with its folder. A user-defined language server sets it withserverInstances, and #1929 added${instanceRoot}for its command and working directory. See Several language server instances in the user guide and in the developer guide.Closing it; anything left can get an issue of its own.