From 0860db73ae6fd9a6f6347219d820bf026a6b8b91 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Sun, 27 Sep 2026 17:38:39 +0200 Subject: * MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automated-commit-by: dots Signed-off-by: Robert Günzler --- .config/nvim/after/ftplugin/go.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .config/nvim/after/ftplugin/go.lua (limited to '.config/nvim/after/ftplugin/go.lua') diff --git a/.config/nvim/after/ftplugin/go.lua b/.config/nvim/after/ftplugin/go.lua new file mode 100644 index 0000000..ad5c56e --- /dev/null +++ b/.config/nvim/after/ftplugin/go.lua @@ -0,0 +1,32 @@ +vim.api.nvim_create_autocmd({ 'LspAttach' }, { + pattern = '*.go', + group = vim.api.nvim_create_augroup('lspattach.go', {}), + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + if not client:supports_method('workspace/executeCommand') then + return + end + + vim.keymap.set('n', 'i', function() + local p = vim + .system({ + 'sh', + '-c', + [[go mod graph | awk '{print $2}' | cut -d@ -f1 | sort -u]], + }) + :wait() + local opts = vim.split(p.stdout, '\n') + vim.ui.select(opts, {}, function(choice) + client:exec_cmd({ + command = 'gopls.add_import', + arguments = { + { + ['ImportPath'] = choice, + ['URI'] = vim.uri_from_bufnr(0), + }, + }, + }) + end) + end, { desc = 'gopls: add import' }) + end, +}) -- cgit 1.4.1