go code action for null-ls

pull/274/head
ray-x 1 year ago
parent 16894803d7
commit a0a57a88e8

@ -6,6 +6,8 @@
local type, pairs, ipairs, os = type, pairs, ipairs, os
local utils = require('go.utils')
local log = utils.log
local alt_getopt = {}
local function convert_short2long(opts)
@ -53,6 +55,10 @@ function alt_getopt.get_ordered_opts(arg, sh_opts, long_opts)
while i <= #arg do
local a = arg[i]
if type(a) ~= "string" then
log('failed to decode', type(a), a)
goto continue
end
if a == "--" then
i = i + 1
break
@ -120,6 +126,8 @@ function alt_getopt.get_ordered_opts(arg, sh_opts, long_opts)
end
i = i + 1
::continue::
end
return opts, i, optarg, unparsed
@ -130,10 +138,10 @@ function alt_getopt.get_opts(arg, sh_opts, long_opts)
local opts, optind, optarg, unparsed = alt_getopt.get_ordered_opts(arg, sh_opts, long_opts)
for i, v in ipairs(opts) do
if optarg[i] then
if optarg and optarg[i] then
ret[v] = optarg[i]
else
ret[v] = true
ret[v] = (optarg ~= nil)
end
end

@ -449,7 +449,7 @@ end
--options {s:select, F: floaterm}
M.test_func = function(...)
local args = { ... }
local args = { ... } or {}
log(args)
local ns = M.get_test_func_name()

@ -14,6 +14,10 @@ local function handler()
-- there is no need to run on didChange, has to run until fil saved
return log('skip didChange')
end
if vim.fn.empty(msg.err) == 0 then
log('error', msg.err)
return
end
log(msg.method)
local msgs = msg.output
@ -127,4 +131,43 @@ return {
}),
}
end,
gotest_action = function()
return {
name = 'gotest nearest',
meta = {
url = 'https://github.com/ray-x/go.nvim',
description = 'test go code',
},
method = require('null-ls.methods').internal.CODE_ACTION,
filetypes = { 'go' },
generator = {
fn = function(params)
local actions = {}
local gt = require('go.gotest')
local cb = function()
local test_actions = gt.test_func
if not test_actions then
return
end
log('gotest action')
test_actions()
end
local fname = gt.get_test_func_name()
if not fname then
fname = 'file'
end
log(fname)
-- local mode = vim.api.nvim_get_mode().mode
table.insert(actions, {
title = 'gotest ' .. fname.name,
action = function()
vim.api.nvim_buf_call(params.bufnr, cb)
end,
})
return actions
end,
},
}
end,
}

Loading…
Cancel
Save