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, })