lsp icon indicating copy to clipboard operation
lsp copied to clipboard

Per-project LSP server for the same filetype

Open dvaembit opened this issue 4 months ago • 0 comments

Feature Request

I would like to be able to specify a callback in my LSP server configuration that could take the current buffer's attributes into effect when determining which LSP to launch and which options to pass it. I want this so that I can launch multiple OmniSharp LSP servers, one for each project I am editing.

Background

The OmniSharp LSP server defaults to scanning it's current working directory for dotnet project files and config files such as omnisharp.json and .editorconfig. The help output:

dotnet "$HOME"/opt/omnisharp/OmniSharp.dll -h
Usage:  [options]

Options:
  -?|-h|--help             Show help information.
  -s|--source              Solution or directory for OmniSharp to point at (defaults to current directory).
  -l|--loglevel            Level of logging (defaults to 'Information').
  -v|--verbose             Explicitly set 'Debug' log level.
  -hpid|--hostPID          Host process ID.
  -z|--zero-based-indices  Use zero based indices in request/responses (defaults to 'false').
  -pl|--plugin             Plugin name(s).
  -d|--debug               Wait for debugger to attach
  -lsp|--languageserver    Use Language Server Protocol.
  -e|--encoding            Input / output encoding for STDIO protocol.

I have multiple dotnet projects, each with their own omnisharp.json and .editorconfig files. For unrelated reasons, I have vim configured to chdir to the root of whichever source control checkout the current buffer is in. This occurs just after the LSP server starts. Consider this sequence:

  • Launch vim from $HOME
  • :e $HOME/project-a/file-a.cs. LSP launches in $HOME
  • Other plugin changes directory to $HOME/project-a
  • I am now editing a file in project-a without the omnisharp.json settings for that project.
  • :LspServer restart starts in $HOME/project-a
  • :e $HOME/project-b/file-b.cs.
  • Other plugin changes directory to $HOME/project-b
  • I am now editing a file in project-b with the omnisharp.json settings for project-a. This would be true even if I make the directory change occur before the LSP server starts.

dvaembit avatar Sep 10 '25 17:09 dvaembit