From 2893ebee96698a595510275bcce02483070363e5 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Wed, 17 May 2023 22:37:30 +0100 Subject: [PATCH] feat(go): organise imports on save --- Makefile | 2 +- nvim/init.lua | 1 + nvim/lua/autocommands.lua | 6 ++++++ nvim/lua/plugins/config/lsp.lua | 8 ++++---- 4 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 nvim/lua/autocommands.lua diff --git a/Makefile b/Makefile index 4aff51c..eaaa24b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: backup clean update install_packer package publish +.PHONY: backup clean update install_lazy package publish backup: @bash ./.helpers/config backup diff --git a/nvim/init.lua b/nvim/init.lua index 46c9346..66dcf26 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,3 +1,4 @@ require("options") require("plugins") require("keymappings") +require("autocommands") diff --git a/nvim/lua/autocommands.lua b/nvim/lua/autocommands.lua new file mode 100644 index 0000000..9c5c9fa --- /dev/null +++ b/nvim/lua/autocommands.lua @@ -0,0 +1,6 @@ +vim.api.nvim_create_autocmd('BufWritePre', { + pattern = '*.go', + callback = function() + vim.lsp.buf.code_action({ context = { only = { 'source.organizeImports' } }, apply = true }) + end +}) diff --git a/nvim/lua/plugins/config/lsp.lua b/nvim/lua/plugins/config/lsp.lua index 11dbb57..0341b86 100644 --- a/nvim/lua/plugins/config/lsp.lua +++ b/nvim/lua/plugins/config/lsp.lua @@ -72,8 +72,8 @@ lspconfig.golangci_lint_ls.setup{ -- Jsonnet lspconfig.jsonnet_ls.setup{ on_attach = custom_attach, - cmd = {"jsonnet-language-server", "--lint"}, - flags = lsp_flags, + cmd = {"jsonnet-language-server", "--lint"}, + flags = lsp_flags, } -- Terraform @@ -82,7 +82,7 @@ lspconfig.terraformls.setup{ cmd = {"terraform-ls", "serve", "-log-file="..log_directory.."/terraformls.log"}, filetypes = {"terraform", "hcl", "tf"}, root_dir = lspconfig.util.root_pattern{".terraform", ".git", "main.tf"}, - flags = lsp_flags, + flags = lsp_flags, } -- Python @@ -90,7 +90,7 @@ lspconfig.pylsp.setup{ on_attach = custom_attach, cmd = { "pylsp" }, filetypes = { "python" }, - flags = lsp_flags, + flags = lsp_flags, } -- Lua