GoImpl autocomplete from treesitter symbols

pull/163/head
ray-x 2 years ago
parent 9ad2568465
commit fcc473b1ec

@ -214,6 +214,7 @@ first run of `GoFmt` may fail. It is recommended to run `GoInstallBinaries` to i
| GoTest -c | go test -c current_file_path |
| GoTest -n | test nearest, see GoTestFunc |
| GoTest -f | test current file, see GoTestFile |
| GoTest -n 1 | -count=1 flag |
| GoTest -p | test current package, see GoTestPkg |
| GoTest -t yourtags | go test ./... -tags=yourtags, see notes |
| GoTest package_path -t yourtags | go test packagepath -tags=yourtags |

@ -79,7 +79,7 @@ function M.make(...)
return
end
local runner = vim.split(makeprg, ' ')[1]
local runner = vim.split(makeprg, " ")[1]
if not require("go.install").install(runner) then
util.warn("please wait for " .. runner .. " to be installed and re-run the command")
@ -156,7 +156,7 @@ function M.make(...)
table.insert(cmd, "-v")
end
if optarg["r"] then
log("run test")
log("run test", efm)
table.insert(cmd, "-run")
end
if compile_test then
@ -191,6 +191,9 @@ function M.make(...)
end
local failed = false
local itemn = 1
local package_path = cmd[#cmd]
local pkg_len = #package_path
local function on_event(job_id, data, event)
-- log("stdout", data, event)
if event == "stdout" then
@ -200,15 +203,22 @@ function M.make(...)
if value:find("=== RUN") or value:find("no test file") then
goto continue
end
value = handle_color(value)
if value:find("FAIL") then
failed = true
if value == "FAIL" then
goto continue
end
end
local changed = false
if vim.fn.empty(vim.fn.glob(args[#args])) == 0 then
changed = true
if value:find("FAIL") == nil then
value = args[4] .. util.sep() .. util.ltrim(value)
local p = extract_filepath(value)
if p then
value = package_path .. util.sep() .. util.ltrim(value)
end
end
else
local p = extract_filepath(value)
@ -218,6 +228,7 @@ function M.make(...)
changed = true
end
end
trace(value)
table.insert(lines, value)
if itemn == 1 and failed and changed then
itemn = #lines
@ -252,6 +263,7 @@ function M.make(...)
if #lines > 0 then
vim.list_extend(errorlines, lines)
end
trace(errorlines)
vim.fn.setqflist({}, " ", {
title = cmd,
lines = errorlines,
@ -261,6 +273,7 @@ function M.make(...)
log(errorlines[1], job_id)
vim.cmd([[echo v:shell_error]])
elseif #lines > 0 then
trace(lines)
vim.fn.setqflist({}, " ", {
title = cmd,
lines = lines,

@ -158,6 +158,20 @@ local function complete(_, cmdline, _)
local gopls = require("go.gopls")
local last = words[#words]
local iface = get_interface_name()
local query = require("go.ts.go").query_type_declaration
local bufnr = vim.api.nvim_get_current_buf()
if iface ~= nil then
local nodes = require("go.ts.nodes").nodes_in_buf(query, "go", nil, bufnr, 100000, 100000)
local ns = {}
log(nodes)
for _, node in ipairs(nodes) do
table.insert(ns, node.name)
end
log(ns)
return vfn.uniq(ns)
end
if string.match(last, "^.+%..*") ~= nil then
local part = match_iface_name(last)
if part ~= nil then

@ -178,16 +178,18 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col)
if op == "name" then
-- ulog("node name " .. name)
name = get_node_text(node, bufnr) or ""
declaration_node = node
elseif op == "declaration" or op == "clause" then
declaration_node = node
sRow, sCol, eRow, eCol = ts_utils.get_vim_range({ ts_utils.get_node_range(node) }, bufnr)
end
sRow, sCol, eRow, eCol = ts_utils.get_vim_range({ ts_utils.get_node_range(node) }, bufnr)
end)
if declaration_node ~= nil then
-- ulog(name .. " " .. op)
-- ulog(sRow, pos_row)
if sRow > pos_row then
ulog( tostring(sRow) .. " beyond " .. tostring(pos_row))
ulog(tostring(sRow) .. " beyond " .. tostring(pos_row))
-- break
end
table.insert(results, {
@ -203,6 +205,22 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col)
return results
end
M.nodes_in_buf = function(query, default, bufnr, row, col)
bufnr = bufnr or vim.api.nvim_get_current_buf()
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
if row == nil or col == nil then
row, col = unpack(vim.api.nvim_win_get_cursor(0))
end
local nodes = M.get_all_nodes(query, ft, default, bufnr, row, col)
if nodes == nil then
vim.notify("Unable to find any nodes.", vim.lsp.log_levels.DEBUG)
ulog("Unable to find any nodes. place your cursor on a go symbol and try again")
return nil
end
return nodes
end
M.nodes_at_cursor = function(query, default, bufnr, row, col)
bufnr = bufnr or vim.api.nvim_get_current_buf()
local ft = vim.api.nvim_buf_get_option(bufnr, "ft")

Loading…
Cancel
Save