ray-x / go.nvim

G'day Nvimer, Joyful Gopher: Discover the Feature-Rich Go Plugin for Neovim
MIT License
2.05k stars 123 forks source link

go.nvim is hiding my LSP keymaps #381

Closed ribtoks closed 1 year ago

ribtoks commented 1 year ago

Hi

Thank you for developing go.nvim!

I have a problem when I define my custom keymaps and use go.nvim, for some reason they are not visible. However, they do work for all other language servers that I use.

My config

local on_attach = function(client, bufnr)
    local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
    local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end

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

    local opts = { noremap = true, silent = true }

    buf_set_keymap('n', '<leader>d',  '<cmd>lua vim.lsp.buf.document_symbol()<cr>', opts)
    --- .....
end

local capabilities = require('cmp_nvim_lsp').default_capabilities()

require('go').setup({
  lsp_cfg = {
    capabilities = capabilities,
  },
  lsp_on_attach = on_attach,
  lsp_keymaps = false,
})

Now, all keybindings set in on_attach are not working and not visible in :map output. How to fix this?

Note that all the commands run perfectly fine if run myself, it's just the keybinding that is not set.

using Neovim 0.9.2 and latest go.nvim

Checkhealth go: require("go.health").check() Binaries ~ - go installed. - Tool installed: dlv - Tool installed: gotestsum - Tool installed: fillswitch - Tool installed: json-to-struct - Tool installed: gomvp - Tool installed: golines - Tool installed: govulncheck - Tool installed: golangci-lint - Tool installed: go-enum - Tool installed: goimports - Tool installed: gorename - Tool installed: gopls - Tool installed: gomodifytags - Tool installed: mockgen - Tool installed: gofumpt - Tool installed: gotests - Tool installed: iferr - Tool installed: callgraph - Tool installed: guru - Tool installed: impl - Tool installed: richgo - Tool installed: fillstruct - Tool installed: ginkgo - sed installed. - curl installed. - OK All binaries installed Go Plugin Check ~ - OK lspconfig: plugin is installed - OK nvim-treesitter: plugin is installed - WARNING guihua: not installed/loaded - WARNING nvim-dap-virtual-text: not installed/loaded - WARNING telescope: not installed/loaded - OK nvim-treesitter-go is installed - WARNING nvim-dap: not installed/loaded - WARNING nvim-dap-ui: not installed/loaded - WARNING Not all plugin installed - GOPATH is not set - GOROOT is not set - GOBIN is not set - Not all environment variables set
ribtoks commented 1 year ago

Also, after reading go.nvim source code, I tried this, to no avail too

local setup_keymaps = function(bufnr)
    local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
    local opts = { noremap = true, silent = true }

    buf_set_keymap('n', '<leader>d',  '<cmd>lua vim.lsp.buf.document_symbol()<cr>', opts)
    --- ...
end

local capabilities = require('cmp_nvim_lsp').default_capabilities()
require('go').setup({
  lsp_cfg = {
    capabilities = capabilities,
  },
  lsp_keymaps = setup_keymaps
})
ribtoks commented 1 year ago

Fixed by manually specifying gopls_cmd. Somehow :GoInstallBinaries worked, but gopls was not found (although gopls was install by the very same :GoInstallBinaries...)

zyriab commented 7 months ago

I have the same problem, this should not be closed :(