mrcjkb / haskell-tools.nvim

🦥 Supercharge your Haskell experience in neovim!
GNU General Public License v2.0
483 stars 20 forks source link

haskell-tools mappings don't seem to be picked up #143

Closed tchoutri closed 1 year ago

tchoutri commented 1 year ago

Neovim version (nvim -v)

NVIM v0.9.0-dev+1009-gf1816f9ee

Operating system/version

Fedora 37

Output of haskell-language-server-wrapper --version

haskell-language-server version: 1.9.1.0 (GHC: 9.4.4)

How to reproduce the issue

  1. Open a Haskell project (like https://github.com/haskell-text/text-display for instance)
  2. Try and use a mapping like 'K' (hover)
  3. No result

Expected behaviour

Any kind of output or message.

Actual behaviour

nvim has a little spike of CPU consumption (from 0.0% to 0.7%) but nothing happens on the UI.

Log files

No response

The minimal config used to reproduce this issue.

-- Minimal nvim config with packer
-- Assumes a directory in $NVIM_DATA_MINIMAL
-- Start with $NVIM_DATA_MINIMAL=$(mktemp -d) nvim -u minimal.lua
-- Then exit out of neovim and start again.

-- Ignore default config
local buffer = vim.api.nvim_get_current_buf()
local fn = vim.fn
local config_path = fn.stdpath('config')
local def_opts = { noremap = true, silent = true, }
local keymap = vim.keymap

vim.opt.runtimepath:remove(config_path)

-- Ignore default plugins
local data_path = fn.stdpath('data')
local pack_path = data_path .. '/site'
vim.opt.packpath:remove(pack_path)

--append temporary config and pack dir
data_path = os.getenv('NVIM_DATA_MINIMAL')
if not data_path then
  error('$NVIM_DATA_MINIMAL environment variable not set!')
end
vim.opt.runtimepath:append('.')
vim.opt.runtimepath:append(data_path)
vim.opt.runtimepath:append(data_path .. '/site/pack/packer/start/plenary.nvim')
vim.opt.packpath:append(data_path .. '/site')

-- bootstrap packer
local packer_install_path = data_path .. '/site/pack/packer/start/packer.nvim'
local install_plugins = false

if vim.fn.empty(vim.fn.glob(packer_install_path)) > 0 then
  vim.cmd('!git clone git@github.com:wbthomason/packer.nvim ' .. packer_install_path)
  vim.cmd('packadd packer.nvim')
  install_plugins = true
else
  vim.cmd('packadd packer.nvim')
end

local packer = require('packer')

packer.init {
  package_root = data_path .. '/site/pack',
  compile_path = data_path .. '/plugin/packer_compiled.lua',
}

vim.cmd('runtime! plugin/plenary.vim')

packer.startup(function(use)
  use('wbthomason/packer.nvim')
  use {
    'MrcJkb/haskell-tools.nvim',
    requires = {
      'nvim-lua/plenary.nvim',
    },
    config = function()
      hls = {
        default_settings = {
          haskell = {
            checkProject = true,
          }
        },
        -- See nvim-lspconfig's  suggested configuration for keymaps, etc.
        on_attach = function(client, bufnr)
          local opts = vim.tbl_extend('keep', def_opts, { buffer = bufnr, })
          keymap.set('n', '<F2>', vim.lsp.buf.rename, opts)
          keymap.set('n', '<F3>', '<cmd>TroubleToggle<CR>', opts)
          keymap.set('n', '<F4>', vim.lsp.buf.code_action, opts)
          keymap.set('n', '<F5>', vim.lsp.codelens.run, opts)
          keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
          keymap.set('n', '<space>ca', vim.lsp.codelens.run, opts)
          keymap.set('n', '<space>e', vim.lsp.diagnostic.show_line_diagnostics, opts)
          keymap.set('n', '<space>ea', ht.lsp.buf_eval_all, opts)
          keymap.set('n', '<space>hs', ht.hoogle.hoogle_signature, opts)
          keymap.set('n', '<space>q', vim.lsp.diagnostic.set_loclist, opts)
          keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
          keymap.set('n', '<space>wl', print(vim.inspect(vim.lsp.buf.list_workspace_folders())), opts)
          keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
          keymap.set('n', 'K', vim.lsp.buf.hover, opts)
          keymap.set('n', '[d', vim.lsp.diagnostic.goto_prev, opts)
          keymap.set('n', ']d', vim.lsp.diagnostic.goto_next, opts)
          keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
          keymap.set('n', 'gh', ht.hoogle.hoogle_signature, opts)
          keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
          keymap.set('n', 'gr', vim.lsp.buf.references, opts)

        end,
      }

  if install_plugins then
    packer.sync()
  end
  end}
end)
mrcjkb commented 1 year ago

Hi. Thanks for reporting this.

For some reason, with the minimal config, the nightly build of Neovim doesn't seem to output error messages when setting a keymap fails. So it just fails silently, making this quite hard to debug.

The config you pasted doesn't actually call the haskell-tools.setup() function, but I'm guessing that was by accident...

Here are the errors I found in your config:

1

vim.lsp.diagnostic has been deprecated for a while, and moved to vim.diagnostic. The vim.lsp.diagnostic functions no longer exist in recent Neovim versions. I would recommend setting keymaps for vim.diagnostic globally, as there are many non-LSP related plugins that can make use of this feature (e.g. neotest, nvim-lint, ...). The syntax has changed a bit. See :h diagnostic for details.

2

The line

keymap.set('n', '<space>wl', print(vim.inspect(vim.lsp.buf.list_workspace_folders())), opts)

should be

keymap.set("n", "<space>wl", function()
  print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)

3

For some strange reason, it only works when I move def_opts = {...} and keymap = vim.keymap (at the top of the minimal config) into the on_attach function. It's as if they're not captured by the function, which should normally not be the case in Lua. My guess is that packer's startup function somehow clears the scope so that nothing from outside of on_attach can be captured?

tchoutri commented 1 year ago

The config you pasted doesn't actually call the haskell-tools.setup() function, but I'm guessing that was by accident...

Well-spotted. I recently saw that the README had changed since last time I looked at it, and .setup was replaced by .start_or_attach. I thought that on_attach would be the equivalent callback for in-packer configuration? :)

mrcjkb commented 1 year ago

You can still call setup if you want to configure in packer's startup. start_or_attach is meant to be used in ftplugin/haskell.lua (in which case it will only be called if you open a Haskell file). Here's the announcement with all the details :)

mrcjkb commented 1 year ago

I'll close this for now, assuming it's solved. Please reopen if you're still having issues :)