Skip to content

Commit

Permalink
fix(neovim): added auto-organize go imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Wittano committed Dec 31, 2023
1 parent 4157797 commit 39be0cc
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion modules/editors/neovim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,33 @@ in
};
lua-ls.enable = true;
html.enable = true;
gopls.enable = true;
gopls = {
enable = true;
onAttach.function = ''
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.go",
callback = function()
local params = vim.lsp.util.make_range_params()
params.context = {only = {"source.organizeImports"}}
-- buf_request_sync defaults to a 1000ms timeout. Depending on your
-- machine and codebase, you may want longer. Add an additional
-- argument after params if you find that you have to write the file
-- twice for changes to be saved.
-- E.g., vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 3000)
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
for cid, res in pairs(result or {}) do
for _, r in pairs(res.result or {}) do
if r.edit then
local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-16"
vim.lsp.util.apply_workspace_edit(r.edit, enc)
end
end
end
vim.lsp.buf.format({async = false})
end
})
'';
};
cmake.enable = true;
gdscript.enable = true;
eslint.enable = true;
Expand Down Expand Up @@ -194,6 +220,11 @@ in
lspServersToEnable = "all";
};

efmls-configs = {
enable = true;
setup.go.formatter = [ "goimports" ];
};

barbar = {
enable = true;
autoHide = true;
Expand Down

0 comments on commit 39be0cc

Please sign in to comment.