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

feat!: version 2.x.x ftplugin rewrite #226

Merged
merged 55 commits into from
Aug 26, 2023
Merged

feat!: version 2.x.x ftplugin rewrite #226

merged 55 commits into from
Aug 26, 2023

Conversation

mrcjkb
Copy link
Owner

@mrcjkb mrcjkb commented Aug 4, 2023

Description of changes

This is a major (breaking) rewrite of haskell-tools.nvim.

See also: #227.

Things done

@mrcjkb mrcjkb self-assigned this Aug 4, 2023
@mrcjkb mrcjkb marked this pull request as draft August 4, 2023 17:08
@mrcjkb
Copy link
Owner Author

mrcjkb commented Aug 4, 2023

TODO:

  • Update minimal.lua + troubleshooting guide
  • Add API to conditonally enable modules: enable :: fun():boolean | boolean.
  • Split config into public and internal modules.
  • Make sure minimal.lua doesn't use anything in $XDG_CONFIG_HOME/nvim.

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

local on_attach_def = function(client, bufnr)
    local function buf_set_option(...)
        vim.api.nvim_buf_set_option(bufnr, ...)
    end
    local buf_opts = { noremap = true, silent = true, buffer = bufnr }

    -- buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

    -- show info
    vim.keymap.set("n", "K", vim.lsp.buf.hover, buf_opts)
    -- open diagnostic window
    vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, buf_opts)
    -- next error
    vim.keymap.set("n", "<space>n", vim.diagnostic.goto_next, buf_opts)
    -- prev error
    vim.keymap.set("n", "<space>p", vim.diagnostic.goto_prev, buf_opts)
    -- open code actions
    -- vim.keymap.set("n", "<space>c", 'CodeActionMenu', buf_opts)
    -- rename
    vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, buf_opts)
    -- goto references
    vim.keymap.set("n", "gr", vim.lsp.buf.references, buf_opts)
    -- goto definition
    vim.keymap.set("n", "gd", vim.lsp.buf.definition, buf_opts)
    -- format
    vim.keymap.set("n", "<space>rf", function()
        vim.lsp.buf.format({ async = true })
    end, buf_opts)

    vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, buf_opts)
    vim.keymap.set("n", "gD", vim.lsp.buf.declaration, buf_opts)
    vim.keymap.set("n", "gi", vim.lsp.buf.implementation, buf_opts)
    vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, buf_opts)
    vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, buf_opts)
    vim.keymap.set("n", "<space>wl", function()
        print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
    end, buf_opts)
    vim.keymap.set("n", "<space>tl", lsplines.toggle, buf_opts)
end

local nvimlightbulb = require("nvim-lightbulb")
nvimlightbulb.setup({ autocmd = { enabled = true } })

-- Detect nvim-dap launch configurations
-- (requires nvim-dap and haskell-debug-adapter)

vim.g.haskell_tools = {
    hls = {
        on_attach = function(client, bufnr, ht)
            local opts = { noremap = true, silent = true, buffer = bufnr }
            ht.dap.discover_configurations(bufnr)
            -- haskell-language-server relies heavily on codeLenses,
            -- so auto-refresh (see advanced configuration) is enabled by default
            vim.keymap.set("n", "<space>a", vim.lsp.codelens.run, opts)
            -- Hoogle search for the type signature of the definition under the cursor
            vim.keymap.set("n", "<space>hs", ht.hoogle.hoogle_signature, opts)
            -- Evaluate all code snippets
            vim.keymap.set("n", "<space>ea", ht.lsp.buf_eval_all, opts)
            -- Toggle a GHCi repl for the current package
            vim.keymap.set("n", "<leader>rt", ht.repl.toggle, opts)
            -- Toggle a GHCi repl for the current buffer
            vim.keymap.set("n", "<leader>rb", function()
                ht.repl.toggle(vim.api.nvim_buf_get_name(0))
            end, opts)
            vim.keymap.set("n", "<leader>rq", ht.repl.quit, opts)

            on_attach_def(client, bufnr)
        end,

I have tried to adjust my config to the new version of haskell-tools.nvim and did this, but none of the keybindings work; may I ask what am I doing wrong? :3

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

god, I have to rewrite my entire config, this is an absolute mess...

@mrcjkb
Copy link
Owner Author

mrcjkb commented Aug 10, 2023

god, I have to rewrite my entire config, this is an absolute mess...

Don't worry, you won't have to rewrite your entire config 😄
Identifying stuff like this is why I posted #227 and am waiting before releasing.

Can you send me a link to your config so I can identify the problem?

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

Don't worry, you won't have to rewrite your entire config smile

yeah this was independent of haskell.nvim, my config looks like frankensteins monster at this point heh

Can you send me a link to your config so I can identify the problem?

https://git.sr.ht/~mangoiv/dotfiles/tree/07c75d8a75524e583e4ddf986481aaca3216fade/item/modules/home/devel/nvim/init.lua

@mrcjkb
Copy link
Owner Author

mrcjkb commented Aug 10, 2023

Don't worry, you won't have to rewrite your entire config smile

yeah this was independent of haskell.nvim, my config looks like frankensteins monster at this point heh

Can you send me a link to your config so I can identify the problem?

https://git.sr.ht/~mangoiv/dotfiles/tree/07c75d8a75524e583e4ddf986481aaca3216fade/item/modules/home/devel/nvim/init.lua

It's nix, so I should be able to reproduce it. I'll give it a go after work 😅

@mrcjkb
Copy link
Owner Author

mrcjkb commented Aug 10, 2023

@MangoIV I had a look at your config and couldn't see anything wrong with it.

Maybe the call to ht.dap.discover_configurations(bufnr) is failing silently for some reason, and that's preventing the keymaps from being added?

Can you update the flake input and see if it works?
If not, I'll see if I can convert the home-manager module to a derivation and reproduce it this weekend.

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

Sure, will try and do that, thank you for investigating!

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

nah, that wasn't it... I will try to diff carefully and see where I messed up >D

@mrcjkb
Copy link
Owner Author

mrcjkb commented Aug 10, 2023

nah, that wasn't it... I will try to diff carefully and see where I messed up >D

Hmm, here are some things you can try:

  • What's the output of :filetype?
  • What's the output of :checkhealth haskell-tools?
  • Does it work if you open a Haskell file and run :lua require('haskell-tools.internal').start_or_attach()?

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

This all seems fine, I think the issue is that hls.on_attach doesn't have any effect / isn't called. I mean; the language server does run and offers hints and all that, it's just that the keybindings don't take effect.

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

nothing was getting called; I might have the solution and it might have been my stupid fault eh.

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

nothing is getting called eh.

@mrcjkb
Copy link
Owner Author

mrcjkb commented Aug 10, 2023

nothing is getting called eh.

That's very strange. I use vim.g.haskell_tools.hls.on_attach to set keymaps and it works fine for me.

Maybe somehow in your config, require('haskell-tools') is being called before you're setting vim.g.haskell_tools. Although I couldn't find any calls to it.
I'll investigate again after work. Could you please attach the ~/.config/nvim directory that home-manager generated for you?

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

it's just the same thing as on my git, except it first calls the vimrc

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

indeed; removing the vimrc from my home-manager config solves it.

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

image
!warning: extremely dirty fix eh

(This concatenates them in reverse order which somehow works)

@mrcjkb
Copy link
Owner Author

mrcjkb commented Aug 10, 2023

image !warning: extremely dirty fix eh

(This concatenates them in reverse order which somehow works)

I don't understand how your vimrc could interfere with haskell-tools, but okay, I guess 😕
Might be interesting to bisect it and find out which command is the culprit...

@MangoIV
Copy link
Contributor

MangoIV commented Aug 10, 2023

I don’t know either tbh. Can’t imagine.

@mrcjkb mrcjkb marked this pull request as ready for review August 26, 2023 22:02
@mrcjkb mrcjkb enabled auto-merge August 26, 2023 22:07
@mrcjkb mrcjkb merged commit fc29c58 into master Aug 26, 2023
6 checks passed
@mrcjkb mrcjkb deleted the 2.x.x branch August 26, 2023 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Try both haskell-language-server-wrapper and haskell-language-server by default
2 participants