diff options
Diffstat (limited to '')
| -rw-r--r-- | .config/nvim/after/ftplugin/go.lua | 32 |
1 files changed, 32 insertions, 0 deletions
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', '<leader>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, +}) |