mirror of https://github.com/ray-x/go.nvim
updates for dap.ui
parent
ef332025ce
commit
1b11f52b08
@ -0,0 +1,120 @@
|
||||
-- gonkgo test
|
||||
local M = {}
|
||||
local utils = require("go.utils")
|
||||
local log = utils.log
|
||||
local function get_build_tags(args)
|
||||
local tags = {}
|
||||
|
||||
if args ~= nil then
|
||||
table.insert(tags, args)
|
||||
end
|
||||
|
||||
if _GO_NVIM_CFG.build_tags ~= "" then
|
||||
table.insert(tags, _GO_NVIM_CFG.build_tags)
|
||||
end
|
||||
|
||||
if #tags == 0 then
|
||||
return ""
|
||||
end
|
||||
|
||||
return [[-tags\ ]] .. table.concat(tags, ",") .. [[\ ]]
|
||||
end
|
||||
|
||||
local function find_describe(lines)
|
||||
local describe
|
||||
local pat = [[Describe%(%".*%",%sfunc]]
|
||||
local despat = [[%(%".*%"]]
|
||||
for i = #lines, 1, -1 do
|
||||
local line = lines[i]
|
||||
local fs, fe = string.find(line, pat)
|
||||
if fs then
|
||||
line = string.sub(line, fs + #"Describe", fe)
|
||||
fs, fe = string.find(line, despat)
|
||||
if fs ~= nil then
|
||||
if fe - fs <= 2 then
|
||||
return nil
|
||||
end
|
||||
describe = line:sub(fs + 2, fe - 1)
|
||||
return describe
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- print(find_describe({
|
||||
-- [[ var _ = Describe("Integration test hourly data EstimateCombinedRules without ws ID", func() { ]]
|
||||
-- }))
|
||||
|
||||
-- Run with ginkgo Description
|
||||
M.test_fun = function(...)
|
||||
|
||||
local args = {...}
|
||||
log(args)
|
||||
local fpath = vim.fn.expand('%:p:h')
|
||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
row, col = row, col + 1
|
||||
|
||||
local fnum = row - 3
|
||||
if fnum < 0 then
|
||||
fnum = 0
|
||||
end
|
||||
local lines = vim.api.nvim_buf_get_lines(0, fnum, row + 1, true)
|
||||
|
||||
local describe = find_describe(lines)
|
||||
log("testing: ", describe)
|
||||
if describe == nil then
|
||||
log("failed to find test function, test file instead")
|
||||
return M.test_file(args)
|
||||
end
|
||||
local test_runner = 'ginkgo'
|
||||
require("go.install").install(test_runner)
|
||||
|
||||
if _GO_NVIM_CFG.run_in_floaterm then
|
||||
local cmd = test_runner .. [[ --focus=']] .. describe .. [[']] .. get_build_tags(args) .. [[ ]] .. fpath
|
||||
log(cmd)
|
||||
local term = require('go.term').run
|
||||
term({cmd = cmd, autoclose = false})
|
||||
return
|
||||
end
|
||||
local cmd = [[setl makeprg=]] .. test_runner .. [[\ --focus=']] .. describe .. [[']] .. get_build_tags(args) .. [[\ ]]
|
||||
.. fpath .. [[ | lua require"go.asyncmake".make()]]
|
||||
utils.log("test cmd", cmd)
|
||||
vim.cmd(cmd)
|
||||
return true
|
||||
end
|
||||
|
||||
M.test_file = function(...)
|
||||
|
||||
local args = {...}
|
||||
log(args)
|
||||
-- require sed
|
||||
local fpath = vim.fn.expand('%:p:h')
|
||||
local fname = vim.fn.expand('%:p')
|
||||
|
||||
log(fpath, fname)
|
||||
|
||||
local workfolder = vim.lsp.buf.list_workspace_folders()[1]
|
||||
fname = "." .. fname:sub(#workfolder + 1)
|
||||
|
||||
log(workfolder, fname)
|
||||
local test_runner = 'ginkgo'
|
||||
require("go.install").install(test_runner)
|
||||
|
||||
if _GO_NVIM_CFG.run_in_floaterm then
|
||||
cmd = test_runner .. [[ --regexScansFilePath=true ]] .. get_build_tags(args) .. [[ --focus ]] .. fname .. " "
|
||||
.. fpath
|
||||
utils.log(cmd)
|
||||
local term = require('go.term').run
|
||||
term({cmd = cmd, autoclose = false})
|
||||
return
|
||||
end
|
||||
|
||||
fname = utils.relative_to_cwd(fname) .. [[\ ]]
|
||||
local cmd = [[setl makeprg=ginkgo\ ]] .. get_build_tags(args) .. [[\ --regexScansFilePath=true\ --focus\ ]] .. fname
|
||||
.. fpath .. [[| lua require"go.asyncmake".make()]]
|
||||
utils.log("test cmd", cmd)
|
||||
vim.cmd(cmd)
|
||||
end
|
||||
|
||||
return M
|
@ -0,0 +1,56 @@
|
||||
local utils = require 'go.utils'
|
||||
local api = vim.api
|
||||
local guihua_term = utils.load_plugin('guihua.lua', 'guihua.floating')
|
||||
if not guihua_term then
|
||||
utils.warn('guihua not installed, please install ray-x/guihua.lua for GUI functions')
|
||||
end
|
||||
|
||||
local function close_float_terminal()
|
||||
local has_var, float_term_win = pcall(api.nvim_buf_get_var, 0, 'go_float_terminal_win')
|
||||
if not has_var then
|
||||
return
|
||||
end
|
||||
if float_term_win[1] ~= nil and api.nvim_buf_is_valid(float_term_win[1]) then
|
||||
api.nvim_buf_delete(float_term_win[1], {force = true})
|
||||
end
|
||||
if float_term_win[2] ~= nil and api.nvim_win_is_valid(float_term_win[2]) then
|
||||
api.nvim_win_close(float_term_win[2], true)
|
||||
end
|
||||
end
|
||||
|
||||
local term = function(opts)
|
||||
|
||||
local columns = api.nvim_get_option("columns")
|
||||
local lines = api.nvim_get_option("lines")
|
||||
|
||||
local win_width, win_height
|
||||
if columns > 130 then
|
||||
-- split in right
|
||||
win_height = math.ceil(lines * 0.98)
|
||||
win_width = math.ceil(columns * 0.3)
|
||||
|
||||
opts.y = win_height
|
||||
opts.x = columns - win_width
|
||||
else
|
||||
win_height = math.ceil(lines * 0.3)
|
||||
win_width = math.ceil(columns * 0.98)
|
||||
|
||||
opts.y = opts.y or lines - win_height
|
||||
opts.x = opts.x or 1
|
||||
end
|
||||
opts.win_height = opts.win_height or win_height
|
||||
opts.win_width = opts.win_width or win_width
|
||||
opts.border = opts.border or 'single'
|
||||
if opts.autoclose == nil then
|
||||
opts.autoclose = true
|
||||
end
|
||||
local buf, win, closer = guihua_term.floating_term(opts)
|
||||
api.nvim_command('setlocal nobuflisted')
|
||||
api.nvim_buf_set_var(buf, 'go_float_terminal_win', {buf, win})
|
||||
|
||||
return buf, win, closer
|
||||
|
||||
end
|
||||
|
||||
-- term({cmd = 'echo abddeefsfsafd', autoclose = false})
|
||||
return {run = term, close = close_float_terminal}
|
Loading…
Reference in New Issue