Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.cabal file STextDocument errors? #223

Closed
Per48edjes opened this issue Jul 30, 2023 · 15 comments · Fixed by #224
Closed

.cabal file STextDocument errors? #223

Per48edjes opened this issue Jul 30, 2023 · 15 comments · Fixed by #224
Assignees
Labels
bug Something isn't working

Comments

@Per48edjes
Copy link

Per48edjes commented Jul 30, 2023

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.

@Per48edjes Per48edjes added the question Further information is requested label Jul 30, 2023
@mrcjkb
Copy link
Owner

mrcjkb commented Jul 30, 2023

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
Copy link
Author

Per48edjes commented Jul 30, 2023

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
Copy link
Author

Per48edjes commented Jul 31, 2023

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
Copy link
Owner

mrcjkb commented Jul 31, 2023

🤔 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
Copy link
Owner

mrcjkb commented Jul 31, 2023

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
Copy link
Author

🤔 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
Copy link
Author

(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
Copy link
Owner

mrcjkb commented Aug 1, 2023

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 mrcjkb self-assigned this Aug 1, 2023
@mrcjkb mrcjkb added bug Something isn't working and removed question Further information is requested labels Aug 1, 2023
@mrcjkb mrcjkb pinned this issue Aug 1, 2023
@mrcjkb
Copy link
Owner

mrcjkb commented Aug 2, 2023

@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
Copy link
Author

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
Copy link
Owner

mrcjkb commented Aug 3, 2023

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

@Per48edjes
Copy link
Author

Per48edjes commented Aug 3, 2023

🥁 ... 🎉 ! No more cascading pop-ups and no error on load -- thank you, so much, for working on this, @mrcjkb !

image

@mrcjkb
Copy link
Owner

mrcjkb commented Aug 3, 2023

😄 thanks for testing

mrcjkb added a commit that referenced this issue Aug 3, 2023
Fixes #223 

###### Things done

- [x] Tested, as applicable:
  - [x] Manually
  - [ ] Added plenary specs
- [x] Updated
[CHANGELOG.md](https://github.com/MrcJkb/haskell-tools.nvim/blob/master/CHANGELOG.md)
(if applicable).
- [x] Fits
[CONTRIBUTING.md](https://github.com/MrcJkb/haskell-tools.nvim/blob/master/CONTRIBUTING.md)
@mrcjkb
Copy link
Owner

mrcjkb commented Aug 3, 2023

@all-contributors please add @Per48edjes for bug.

@allcontributors
Copy link
Contributor

@mrcjkb

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

mrcjkb added a commit that referenced this issue Aug 3, 2023
Adds @Per48edjes as a contributor for bug.

This was requested by mrcjkb [in this
comment](#223 (comment))

[skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Marc Jakobi <marc@jakobi.dev>
@mrcjkb mrcjkb unpinned this issue Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants