Closed Per48edjes closed 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.
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
},
},
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.)
: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.
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)
š¤ it appears
nvim-ufo
tries to use the lsp folding provider even thoughhaskell-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:
Definitely happy to continue to be the guinea pig here! Just let me know whatever you'd need from my end. Thanks!
(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.)
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.
@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.
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:
Oops, I forgot to add documentHighlight
to the workaround. Should be fixed now.
š„ ... š ! No more cascading pop-ups and no error on load -- thank you, so much, for working on this, @mrcjkb !
š thanks for testing
@all-contributors please add @Per48edjes for bug.
@mrcjkb
I've put up a pull request to add @Per48edjes! :tada:
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:...and this one whenever I navigate around the
.cabal
file (copied from:Notifications
):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.