add list_imports support

pull/140/head
ray-x 2 years ago
parent 9d8117766c
commit 44d6a9d8f3

@ -24,9 +24,10 @@ The plugin covers most features required for a gopher.
- Go to alternative go file (between test and source)
- Test with ginkgo, richgo inside floaterm (to enable floaterm, guihua.lua has to be installed)
- Go 1.18 support, configure your go to `go1.18` in config
- GoFixPlural, FixStruct, FixSwitch, Add comment, IfErr, ModTidy, GoGet ... Most of the tools are built on top of
- Code refactor made easy: GoFixPlural, FixStruct, FixSwitch, Add comment, IfErr, ModTidy, GoGet ... Most of the tools are built on top of
treesitter AST or go AST. It is fast and accurate.
- GoCheat get go cheatsheet from [cheat.sh](https://cheat.sh/).
- Smart build tag detection when debug/run tests (e.g. `//go:build integration`)
## Installation

@ -9,16 +9,26 @@ function M.run_action()
local guihua = utils.load_plugin("guihua.lua", "guihua.gui")
local original_select = vim.ui.select
local original_input = vim.ui.input
if guihua then
vim.ui.select = require("guihua.gui").select
vim.ui.input = require("guihua.input").input
end
log("codeaction")
vim.lsp.buf.code_action()
if vim.api.nvim_get_mode().mode ~= "v" then
vim.lsp.buf.code_action()
else
vim.lsp.buf.range_code_action()
end
vim.defer_fn(function()
vim.ui.select = original_select
end, 1000)
vim.defer_fn(function()
vim.ui.input = original_input
end, 10000)
end
return M

@ -90,6 +90,29 @@ M.import = function(path)
})
end
M.list_imports = function(path)
path = path or vim.fn.expand("%:p")
local resp = cmds.list_imports({
URI = path,
})
result = {}
for _, v in pairs(resp) do
if v.result then
for k, val in pairs(v.result) do
result[k] = {}
for _, imp in ipairs(val) do
if imp.Name and imp.Name ~= "" then
table.insert(result[k], imp.Name .. ":" .. imp.Path)
else
table.insert(result[k], imp.Path)
end
end
end
end
end
return result, resp
end
M.list_pkgs = function()
local resp = cmds.list_known_packages() or {}

@ -52,6 +52,7 @@ local on_attach = function(client, bufnr)
buf_set_keymap("n", "<space>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
buf_set_keymap("n", "<space>rn", "<cmd>lua require('go.rename').run()<CR>", opts)
buf_set_keymap("n", "<space>ca", "<cmd>lua require('go.codeaction').run_action()<CR>", opts)
buf_set_keymap("v", "<space>ca", "<cmd>lua require('go.codeaction').run_action()<CR>", opts)
buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
buf_set_keymap("n", "<space>e", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts)
buf_set_keymap("n", "[d", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)

@ -10,7 +10,7 @@ local lsprename = function()
local input = vim.ui.input
if guihua then
vim.ui.input = require('guihua.floating').input
vim.ui.input = require('guihua.input').input
end
vim.lsp.buf.rename()
return vim.defer_fn(function()

Loading…
Cancel
Save