testing on_attach with golang

main
KeeganForelight 2 years ago
parent fa7c2cb4d6
commit b79e6922fd

@ -49,9 +49,40 @@ vim.cmd([[
-- language server setup
local lspconfig = require('lspconfig')
local on_attach = function(_, bufnr)
-- key mappings
local opts = {
buffer = bufnr,
noremap = true,
silent = true,
focusable = false,
border = 'rounded',
source = 'always',
prefix = ' ',
scope = 'cursor',
close_events = { "BufLeave","CursorMoved","InsertEnter","FocusLost" },
}
-- error viewing
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '<leader>[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', '<leader>]d', vim.diagnostic.goto_next, opts)
-- def viewing/rename
vim.keymap.set('n', '<leader>gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', '<leader>gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<leader>H', vim.lsp.buf.hover, opts)
-- auto hover for error viewing
vim.api.nvim_create_autocmd("CursorHold", {
callback = function()
vim.diagnostic.open_float(nil, opts)
end
})
end
-- Go
lspconfig.gopls.setup{
cmd = {"gopls", "serve"},
on_attach = on_attach,
filetypes = {"go", "gomod"},
settings = {
gopls = {
@ -98,24 +129,19 @@ vim.diagnostic.config({
vim.o.updatetime = 250
vim.api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function()
local opts = {
focusable = false,
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
border = 'rounded',
source = 'always',
prefix = ' ',
scope = 'cursor',
}
vim.diagnostic.open_float(nil, opts)
end
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(ev)
local opts = { buffer = ev.buf }
-- error viewing
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '<leader>[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', '<leader>]d', vim.diagnostic.goto_next, opts)
-- def viewing/rename
vim.keymap.set('n', '<leader>gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', '<leader>gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<leader>H', vim.lsp.buf.hover, opts)
end,
})
-- lsp mappingsd
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '<leader>gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', '<leader>gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<leader>H', vim.lsp.buf.hover, opts)

Loading…
Cancel
Save