jmbuhr / otter.nvim

Just ask an otter! 🦦
MIT License
515 stars 11 forks source link

LSP configured with mason-lsp-config not configured in otter #181

Open gbelouze opened 2 weeks ago

gbelouze commented 2 weeks ago

First of all, thanks for this great plugin.

It seems that my LSP configuration is not respected with otter. I use mason-lsp-config if this is relevant.

Example

With something like

{
  "williamboman/mason-lspconfig.nvim",
  dependencies = { "williamboman/mason.nvim" },
  config = function()
    local mls = require("mason-lspconfig")
    mls.setup({ ensure_installed = { "ruff_lsp" } })
    mls.setup_handlers({
      -- default handler
      function(server_name)
        require("lspconfig")[server_name].setup({})
      end,
      ["ruff_lsp"] = function()
        require("lspconfig").ruff_lsp.setup({
          on_attach = function(client, _)
            client.server_capabilities.hoverProvider = false
          end,
        })
      end,
    })
  end,
}

I do not get hover from ruff_lsp on normal python files, which is intentional, but I do in python cells of a .qmd file. Note : if I open a python file, then on_attach from the above config is called and I not longer get ruff_lsp's hover in the .qmd files.

Is there a way LSPs should be configured so that their configuration is taken into account by otter ?

jmbuhr commented 2 weeks ago

This is how otter starts language servers: https://github.com/jmbuhr/otter.nvim/blob/ca9ce67d0399380b659923381b58d174344c9ee7/lua/otter/init.lua#L154-L163

meaning it just calls the autocommand set by lspconfig via the respective setup call. Can you verify that this is indeed called by adding a print in there?

But, I do believe this is indeed currently a bug. What happens is this:

Otter checks that at least one server attached to the otter buffer for the language supports the requested method: https://github.com/jmbuhr/otter.nvim/blob/ca9ce67d0399380b659923381b58d174344c9ee7/lua/otter/lsp/init.lua#L116-L128 So, in your case, do you have other servers configured that have hover enabled?

Because eventually the request is forwarded to the buffer: https://github.com/jmbuhr/otter.nvim/blob/ca9ce67d0399380b659923381b58d174344c9ee7/lua/otter/lsp/init.lua#L156-L159 and it looks like this circumvents the capabilties-check.

gbelouze commented 2 weeks ago

Thank you for your quick response. I indeed did not mention that I use pylsp which has hover capabilities. This is made a little more complex by the additional layer that mason-lspconfig brings but I can say that the on_attach function is not called when opening a .qmd file (but is when opening .py files). This might be a me-issue, I'll investigate, although the bug you highlighted still holds in any case.

jmbuhr commented 2 weeks ago

You can also try it with the buffers.set_filetype option of otter, in which case otter just set's the filetype of the language buffer instead of manually calling just the lspconfig attach autocommand.