nvim: got golang working finally
Jes Olson j3s@c3f.net
Sun, 19 Feb 2023 18:34:41 -0800
1 files changed,
14 insertions(+),
14 deletions(-)
jump to
M
.config/nvim/init.lua
→
.config/nvim/init.lua
@@ -4,7 +4,7 @@ use 'wbthomason/packer.nvim' -- Package manager
use 'neovim/nvim-lspconfig' -- Configurations for Nvim LSP use 'sainnhe/everforest' -- Colorscheme - -- Very powerful search + -- Very powerful picker use { 'nvim-telescope/telescope.nvim', tag = '0.1.1', requires = {{@@ -43,22 +43,22 @@
-- Mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local bufopts = { noremap=true, silent=true, buffer=bufnr } - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'gd', builtin.lsp_definitions, bufopts) + vim.keymap.set('n', 'gi', builtin.lsp_implementations, bufopts) + vim.keymap.set('n', 'gr', builtin.lsp_references, bufopts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) - vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) - vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) - vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts) - vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts) - vim.keymap.set('n', '<space>wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, bufopts) - vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', '<C-k>', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', '<space>D', builtin.lsp_type_definitions, bufopts) vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts) - vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) - vim.keymap.set('n', 'gr', builtin.lsp_references, bufopts) - vim.keymap.set('n', '<space>F', function() vim.lsp.buf.format { async = true } end, bufopts) end + +vim.api.nvim_create_autocmd('BufWritePre', { + pattern = '*.go', + callback = function() + vim.lsp.buf.format() + vim.lsp.buf.code_action({ context = { only = { 'source.organizeImports' } }, apply = true }) + end +}) ---- golang require('lspconfig')['gopls'].setup{