mrcjkb / haskell-tools.nvim

šŸ¦„ Supercharge your Haskell experience in neovim!
GNU General Public License v2.0
477 stars 19 forks source link

`.cabal` file `STextDocument` errors? #223

Closed Per48edjes closed 1 year ago

Per48edjes commented 1 year ago

Question

Love this plugin! Makes developing for a Haskell newbie like me so much easier -- thank you!

Because I'm still green, I'm wondering why I'm getting this error messages whenever I open a .cabal file in a buffer:

Error executing vim.schedule lua callback: UnhandledPromiseRejection with the reason:
RPC[Error] code_name = InvalidRequest, message = "No plugin enabled for STextDocumentFoldingRange, available: codeRange"

...and this one whenever I navigate around the .cabal file (copied from :Notifications):

haskell-tools.nvim: -32600: No plugin enabled for STextDocumentDocumentHighlight, available: ghcide-hover-and-symbols

I did a little digging into ghcide, but it looks like it's been obviated by HLS?

I'm tagging this as a question because I highly suspect this is "user error" (vs. a bug)...any guidance would be most helpful! (Happy to provide more detail as required.)


Update: Sometimes these issues arise on *.yaml project files, other times they don't...? After awhile I think this error goes away (when either configuration filetype is open)? It's been difficult to pin down the behavior of this.

mrcjkb commented 1 year ago

Hi. Thanks for the feedback. I'm on vacation right now, so my replies might be a bit infrequent in the next few days.

The error message No plugin enabled for STextDocumentFoldingRange tells me that your neovim LSP client has registered textDocument/foldingRange capabilities with haskell-language-server. hls supports those capabilities for Haskell files, but not for cabal files, so it reports the error you are encountering when the client tries to use them. Do you use a folding plugin, like nvim-ufo?

How do you configure the haskell-tools plugin? The legacy .setup way or the recommended way, using ftplugin and start_or_attach?

With the recommended approach, you can register different client capabilities for haskell and cabal files, respectively.

Per48edjes commented 1 year ago

Hey Marc, appreciate the response. Knowing you're taking some time off, please don't feel compelled to respond right away! šŸ˜…

Do you use a folding plugin, like nvim-ufo?

I do use nvim-ufo (as part of the modified AstroNvim build I use).

How do you configure the haskell-tools plugin?

Here's how I configured haskell-tools (lazy.nvim is my package manager):

  {
    "mrcjkb/haskell-tools.nvim",
    ft = { "haskell" },
    branch = "1.x.x", -- recommended by haskell-tools
    init = function() astronvim.lsp.skip_setup = utils.list_insert_unique(astronvim.lsp.skip_setup, "hls") end,
    opts = {
      hls = {
        on_attach = function(client, bufnr) require("astronvim.utils.lsp").on_attach(client, bufnr) end,
      },
    },
    config = function(_, opts)
      local tools = require "haskell-tools"
      vim.api.nvim_create_autocmd("Filetype", {
        pattern = "haskell", -- autocmd to start haskell-tools
        callback = function() tools.start_or_attach(opts) end,
      })

      vim.api.nvim_create_autocmd("LspAttach", {
        pattern = "*.hs", -- autocmd to start haskell-tools
        callback = function(args)
          local client = vim.lsp.get_client_by_id(args.data.client_id)
          if client.name == "haskell-tools.nvim" then tools.dap.discover_configurations(args.buf) end
        end,
      })
    end,
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-telescope/telescope.nvim", -- optional
    },
  },
Per48edjes commented 1 year ago

Ah, so it seems a little more general than I originally thought: while editing .*hs files, opening a buffer for a non-*.hs file causes the notifications (haskell-tools.nvim: -32600: No plugin enabled for STextDocumentDocumentHighlight, available: ghcide-hover-and-symbols) to cascade.

Dropping in the ftplugin/haskell.lua config seems to prevent haskell-tool.nvim from attaching to non-Haskell buffers, but it still attaches to buffers with .cabal files open.

(I'm just chronicling observations here...I have very little (read: absolutely no) idea why this is happening.)

mrcjkb commented 1 year ago

:thinking: it appears nvim-ufo tries to use the lsp folding provider even though haskell-language-server doesn't support folding for cabal files.

Try adding the following to your nvim-ufo config:

  provider_selector = function(_bufnr, filetype, _buftype)
    if filetype == 'cabal' then
      return { 'treesitter', 'indent' }
    end
    return nil -- use default
  end,

That disables the lsp provider for cabal files. See the nvim-ufo readme for more details.

mrcjkb commented 1 year ago

P.S. if this works for you, please leave this issue open. I believe I might be able to implement a workaround for this problem in the haskell-tools plugin.

(Note to self: https://github.com/kevinhwang91/nvim-ufo/blob/43e39ec74cd57c45ca9d8229a796750f6083b850/lua/ufo/provider/lsp/nvim.lua#L53)

Per48edjes commented 1 year ago

šŸ¤” it appears nvim-ufo tries to use the lsp folding provider even though haskell-language-server doesn't support folding for cabal files.

Try adding the following to your nvim-ufo config:

  provider_selector = function(_bufnr, filetype, _buftype)
    if filetype == 'cabal' then
      return { 'treesitter', 'indent' }
    end
    return nil -- use default
  end,

That disables the lsp provider for cabal files. See the nvim-ufo readme for more details.

This seems to prevent the first error, but unfortunately, no dice for the second error. šŸ™ Dropping a screen cap here that shows current state of affairs:

image

Definitely happy to continue to be the guinea pig here! Just let me know whatever you'd need from my end. Thanks!

Per48edjes commented 1 year ago

(Don't think this is a particularly earth-shattering observation, but when a .cabal file is opened in the absence of a file that would trigger haskell-tools.nvim, the pop-up error notifications don't appear.)

image

mrcjkb commented 1 year ago

Ah, I didn't notice the second error. That's related to another lsp feature that hasn't been implemented in neovim yet, and is provided by a plugin.

For example, you can disable this feature for cabal files in vim-illuminate by adding 'cabal' to the filetypes_denylist in the config:

 filetypes_denylist = {
      'cabal',
      'dirvish'
      'fugitive',
  },

I haven't encountered this error with vim-illuminate (and I don't have it disabled for cabal files) so it could be a different plugin causing it for you.

(Don't think this is a particularly earth-shattering observation, but when a .cabal file is opened in the absence of a file that would trigger haskell-tools.nvim, the pop-up error notifications don't appear.)

This might be a very useful observation, actually. It means I may be able to fix both errors by spawning different LSP clients (each with different server capabilities) depending on the file type.

mrcjkb commented 1 year ago

@Per48edjes could you please test the separate-cabal-client branch?

It works for me, but I'd like to know if it's solved for you before merging.

Per48edjes commented 1 year ago

Whoa, exciting! I just checked out separate-cabal-client locally and fired up a Haskell project (opening a .hs source file, a package.yaml file, and the project *.cabal file).

I'm getting this error on load:

Error executing vim.schedule lua callback: vim/shared.lua:0: after the second argument: expected table, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        vim/shared.lua: in function 'tbl_extend'
        ...m/lazy/haskell-tools.nvim/lua/haskell-tools/lsp/util.lua:24: in function 'get_active_haskell_clients'
        ...m/lazy/haskell-tools.nvim/lua/haskell-tools/lsp/util.lua:45: in function 'get_active_ht_clients'
        ...e/nvim/lazy/haskell-tools.nvim/lua/haskell-tools/lsp.lua:177: in function <...e/nvim/lazy/haskell-tools.nvim/lua/haskel
l-tools/lsp.lua:176>

Unfortunately, the issue with the cascading pop-up notifications still persists:

image
mrcjkb commented 1 year ago

Oops, I forgot to add documentHighlight to the workaround. Should be fixed now.

Per48edjes commented 1 year ago

šŸ„ ... šŸŽ‰ ! No more cascading pop-ups and no error on load -- thank you, so much, for working on this, @mrcjkb !

image
mrcjkb commented 1 year ago

šŸ˜„ thanks for testing

mrcjkb commented 1 year ago

@all-contributors please add @Per48edjes for bug.

allcontributors[bot] commented 1 year ago

@mrcjkb

I've put up a pull request to add @Per48edjes! :tada: