zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
46.92k stars 2.69k forks source link

Ability to run multiple language servers #15522

Open hanickadot opened 1 month ago

hanickadot commented 1 month ago

Check for existing issues

Describe the feature

I need ability to run multiple instances of different language servers for same language. I'm developing changes in clang and for test files I would like to run my own modified clangd. But for llvm project itself I would like to use system clangd.

Is this scenario possible? I couldn't find a way how to set up two LSPs for same language.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

osiewicz commented 1 month ago

Hi Hana, You can use worktree-local settings file to run different language servers based on the worktree you're in. Place settings.json in .zed/ directory at the root of your worktree. Settings from that file will apply only to this particular worktree. Now, I'm unsure whether you want your projects to default to your custom copy of clangd or to the system clangd.

If system clangd should be the default for all projects

  1. Place the following in your worktree-local settings.json:
    "lsp": {
    "clangd": {
      "binary": {
        "path": "path-to-your-dev-clangd"
        // you can also pass in "args" as an array.
      }
    }
    }

    That's it.

    If dev clangd should be the default for all projects

  2. Place the following in your global settings.json:
    "lsp": {
    "clangd": {
      "binary": {
        "path": "path-to-your-dev-clangd"
        // you can also pass in "args" as an array.
      }
    }
    }
  3. Place the following in your worktree-local settings.json
    "lsp": {
    "clangd": {
      "binary": {
        "path_lookup": true,
      }
    }
    }

Admittedly I'm unsure if 2. will actually work, as I haven't ran that kind of setup myself. Also, in case you're looking to run two different language servers within the same worktree (based on the distinction between test files and LLVM itself that you highlighted in the OP), that's not possible at the moment. You'd have to open test files subdirectory as a separate worktree. In that case, you can place .zed/settings.json at the root of tests dir.

Thanks for checking Zed out and for your work on CTRE btw. :)

hanickadot commented 1 month ago

Thank you!

Also, in case you're looking to run two different language servers within the same worktree (based on the distinction between test files and LLVM itself that you highlighted in the OP), that's not possible at the moment.

This is a little disappointing but totally understandable as I guess this is really a niche use-case :) I hoped there will be something similar as TextMate is doing having any setting customizable based on glob mask. Two work trees is probably a solution I can live with.

strangemonad commented 2 weeks ago

I was about to file a similar request for but for python. In short, in an editor workspace that contains multiple python projects, each with their own pyproject.toml, venv and pyrightconfig, the most robust way to run pyright or basedpyright is per-project.

There's now an extension that allows running basedpyright that's been mentioned in #7808 but since there's only a single python lsp instance running per editor workspace, you can't configure multiple python path or venv options.