dundalek / lazy-lsp.nvim

Neovim plugin to auto install LSP servers
MIT License
203 stars 17 forks source link

Preferred LSP for languages #17

Closed zoriya closed 1 year ago

zoriya commented 1 year ago

Hi, I love the idea behind this plugin, but I find myself excluding lots of servers that I don't care about/that are buggy. For reference, my exclude_servers looks like this:

excluded_servers = {
    -- Disable generic purpose LSP that I don't care about.
    "efm",
    "diagnosticls",
    -- Prefer tsserver
    "denols",
    "eslint",
    -- Prefer nix_ls (more mature)
    "rnix",
    -- Prefer pyright
    "pylsp",
    "jedi_language_server",
    -- rls is deprecated, rust_analyzer should be used instead.
    "rls",
    -- Prefer clangd
    "ccls",
}

This is not optimal since I can't be sure a new conflicting LSP has been added every time I update my nvim configs. Furthermore, every time I open a file in a new programming language, there are 50% chances that a broken LSP starts and throw an error.

I propose two things:

  1. Add a preferred_server category to associate a file type to an LSP by default (for example, we could write python = "pyright" instead of excluding "pylsp" and "jedi_language_server" as in my example config).
  2. Add default preferred_servers that marks the most used server of each language, so we don't have to mark a custom preferred for each language.
dundalek commented 1 year ago

Hi, this is a cool idea. For reference my config also contains quite a few exlusions :)

excluded_servers = {
  -- prefer tsserver
  "denols", --"stylelint_lsp", "eslint",
  -- ghcide and hie seem to be deprecated in favor of haskell-language-server (hls)
  "ghcide", "hie",

  -- preferring rust_analyzer
  "rls",

  -- to avoid interference with markdown files
  "zk",
  -- interferes with efm for markdown files
  "diagnosticls",
  -- seems to get into infinite loop
  "marksman",

  -- prefer clangd
  "ccls",

  -- it is nice to offer grammar suggestions for markdown files, but uses too much CPU and noise for rough notes
  -- figure out a workflow to toggle it manually
  "ltex",

  -- causes error to be printed: E484: Can't open file /home/me/.m2/repository/com/fujitsu/lsp
  "vdmj",

  -- configured manually due to having issues installing it via nix
  "clojure_lsp",

  -- marked as deprecated
  "sqls",
},

Thinking out loud about how to implement this: Lsp configs have a list of filetypes, so we could likely build a reverse index from filetype->servers, then apply preferences and transform back to server->filetypes that would get used to override the configuration.

Therefore 1. sounds doable.

Regarding 2. some questions come to mind:

zoriya commented 1 year ago

I agree about the issues of the second point, I wrote the point thinking that it would probably not happen due to those issues I wanted to see what you thought about the idea. I think this can only be put on the readme for now. If someone has a bright idea how to handle this nicely, it would make a good feature to have.

dundalek commented 1 year ago

I agree about the issues of the second point, I wrote the point thinking that it would probably not happen due to those issues I wanted to see what you thought about the idea.

All good, thanks for sharing anyway.

I think this can only be put on the readme for now. If someone has a bright idea how to handle this nicely, it would make a good feature to have.

:+1: I will try 1) and we will see what the next steps could be after that.

basilgood commented 1 year ago

It's really necessary to have two lists excluded and preferred ? Why not have only one list ? More like nixos style. Only servers that are declared will start, nothing automatic.

Example: now for a nix file we have two lsp: rnix and nil. If I want nil to start I have two options: either put rnix in excluded or nil in preferred. If I leave the list empty, both servers start. It defaults to rnix, but nil is started and drains the battery and this is useless. But if I don't want any server for yaml files. If I add yamlls to excluded there is docker_compose_language_service which starts automatically. Until your plugin I never heard the docker_compose_language_service. Need to add both of them to excluded. It's like a server hunt.

dundalek commented 1 year ago

Only servers that are declared will start, nothing automatic.

My workflow is that to learn new things I read a lot of code in different languages that I don't work with daily. To me it is preferrable if servers are started automatically, so I get benefit of navigation and completions without needing to investigate and configure individual lsps beforehand. If a server ends up doing nothing and consumes a bit of CPU and RAM in the background that's fine to me. In few instances it misbehaves completely and consumes 100%, then I add it to excluded_servers.

But if I don't want any server for yaml files.

You should be able to add to do preferred_servers = { yaml = {} } it it will not start yamlls nor docker_compose_language_service.

It is great to get more feedback. I am not sure what the best option is, opened https://github.com/dundalek/lazy-lsp.nvim/issues/23 as a place for discussion as one possible approach.

basilgood commented 1 year ago

Ok, thank you.