Update neovim config for better Go development
This commit is contained in:
@@ -103,7 +103,8 @@ vim.g.mapleader = " "
|
|||||||
|
|
||||||
vim.g.qs_highlight_on_keys = {"f", "F"}
|
vim.g.qs_highlight_on_keys = {"f", "F"}
|
||||||
|
|
||||||
vim.cmd([[autocmd BufWritePre * undojoin | Neoformat]])
|
vim.cmd(
|
||||||
|
[[autocmd BufWritePre *.js,*.jsx,*.ts,*.tsx,*.html,*.css,*.scss,*.json undojoin | Neoformat]])
|
||||||
|
|
||||||
require("lsp")
|
require("lsp")
|
||||||
|
|
||||||
|
|||||||
@@ -140,9 +140,52 @@ nvim_lsp.ls_emmet.setup({capabilities = capabilities})
|
|||||||
|
|
||||||
nvim_lsp.gopls.setup({
|
nvim_lsp.gopls.setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = function() setupLspSignature() end
|
on_attach = function() setupLspSignature() end,
|
||||||
|
settings = {
|
||||||
|
gopls = {
|
||||||
|
experimentalPostfixCompletions = true,
|
||||||
|
analyses = {
|
||||||
|
unusedparams = true,
|
||||||
|
shadow = true
|
||||||
|
},
|
||||||
|
staticcheck = true
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function goimports(timeout_ms)
|
||||||
|
local context = { only = { "source.organizeImports" } }
|
||||||
|
vim.validate { context = { context, "t", true } }
|
||||||
|
|
||||||
|
local params = vim.lsp.util.make_range_params()
|
||||||
|
params.context = context
|
||||||
|
|
||||||
|
-- See the implementation of the textDocument/codeAction callback
|
||||||
|
-- (lua/vim/lsp/handler.lua) for how to do this properly.
|
||||||
|
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, timeout_ms)
|
||||||
|
if not result or next(result) == nil then return end
|
||||||
|
local actions = result[1].result
|
||||||
|
if not actions then return end
|
||||||
|
local action = actions[1]
|
||||||
|
|
||||||
|
-- textDocument/codeAction can return either Command[] or CodeAction[]. If it
|
||||||
|
-- is a CodeAction, it can have either an edit, a command or both. Edits
|
||||||
|
-- should be executed first.
|
||||||
|
if action.edit or type(action.command) == "table" then
|
||||||
|
if action.edit then
|
||||||
|
vim.lsp.util.apply_workspace_edit(action.edit)
|
||||||
|
end
|
||||||
|
if type(action.command) == "table" then
|
||||||
|
vim.lsp.buf.execute_command(action.command)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
vim.lsp.buf.execute_command(action)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.cmd([[autocmd BufWritePre *.go lua vim.lsp.buf.formatting_sync()]])
|
||||||
|
vim.cmd([[autocmd BufWritePre *.go lua goimports(1000)]])
|
||||||
|
|
||||||
require("luasnip/loaders/from_vscode").load({
|
require("luasnip/loaders/from_vscode").load({
|
||||||
include = {"javascript", "typescript", "go", "html"}
|
include = {"javascript", "typescript", "go", "html"}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user