pull/87/head
ray-x 2 years ago
parent 4e3b2b1971
commit 2b059afc54

@ -193,6 +193,7 @@ first run of `GoFmt` may fail. It is recommended to run `GoInstallBinaries` to i
| GoTest package_path -tags=yourtags | go test packagepath -tags=yourtags |
| GoTest package_path -tags=yourtags other_args | go test packagepath -tags=yourtags other_args |
| GoLint | golangci-lint |
| GoGet package_url | go get package_url |
| GoVet | go vet |
| GoCoverage | go test -coverprofile |

@ -187,6 +187,10 @@ COMMANDS *go-nvim-commands*
:GoFmt {-tags=tagname}{pakcage_name} *:GoFmt*
Format code with golines+gofumpt package
:GoVet *:GoVet*
Run go vet
:GoGet {package_url} *:GoGet*
Run go get {package_url}
:GoLint *:GoLint*
Run Golint

@ -75,6 +75,7 @@ function go.setup(cfg)
vim.cmd([[command! GoFmt lua require("go.format").gofmt()]])
vim.cmd([[command! -nargs=* GoImport lua require("go.format").goimport(<f-args>)]])
vim.cmd([[command! -nargs=* GoGet lua require'go.goget'.run({<f-args>})]])
local gobin = _GO_NVIM_CFG.go
local cmd = string.format([[command! GoGenerate :setl makeprg=%s\ generate | :GoMake]], gobin)
vim.cmd(cmd)

@ -0,0 +1,15 @@
local runner = require("go.runner")
local M = {}
function M.run(args)
for i, arg in ipairs(args) do
local m = string.match(arg, "^https?://(.*)$") or arg
table.remove(args, i)
table.insert(args, i, m)
end
local cmd = { "go", "get" }
vim.list_extend(cmd, args)
runner.run(cmd)
end
return M

@ -67,12 +67,15 @@ local function go_install(pkg)
end
local function install(bin, verbose)
if verbose == nil then
verbose = _GO_NVIM_CFG.verbose
end
if not is_installed(bin) then
vim.notify("installing " .. bin, vim.lsp.log_levels.INFO)
go_install(bin)
else
if verbose then
vim.notify(bin .. " already install, use GoUpdateBinary to update it", vim.lsp.log_levels.INFO)
vim.notify(bin .. " already install, use GoUpdateBinary to update it", vim.lsp.log_levels.DEBUG)
end
end
end

@ -1,6 +1,6 @@
local uv, api = vim.loop, vim.api
local util = require('go.utils')
local log = require('go.utils').log
local util = require("go.utils")
local log = require("go.utils").log
local check_same = function(tbl1, tbl2)
if #tbl1 ~= #tbl2 then
return
@ -22,12 +22,13 @@ local run = function(cmd, opts)
cmd = vim.split(cmd, split_pattern)
log(cmd)
end
local cmd_str = vim.inspect(cmd)
local job_options = vim.deepcopy(opts or {})
job_options.args = job_options.args or {}
local cmdargs = vim.list_slice(cmd, 2, #cmd) or {}
if cmdargs and cmdargs[1] == 'test' and #cmdargs == 3 then
table.insert(cmdargs, '.' .. util.sep() .. '...')
if cmdargs and cmdargs[1] == "test" and #cmdargs == 3 then
table.insert(cmdargs, "." .. util.sep() .. "...")
log(cmdargs)
end
vim.list_extend(cmdargs, job_options.args)
@ -48,41 +49,43 @@ local run = function(cmd, opts)
local winnr = api.nvim_get_current_win()
local bufnr = api.nvim_get_current_buf()
local output_buf = ''
local output_buf = ""
local function update_chunk(err, chunk)
if chunk then
output_buf = output_buf .. chunk
local lines = vim.split(output_buf, '\n', true)
local lines = vim.split(output_buf, "\n", true)
api.nvim_buf_set_option(bufnr, "modifiable", true)
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
api.nvim_buf_set_option(bufnr, "modifiable", false)
api.nvim_buf_set_option(bufnr, "modified", false)
if api.nvim_win_is_valid(winnr) then
api.nvim_win_set_cursor(winnr, {#lines, 0})
api.nvim_win_set_cursor(winnr, { #lines, 0 })
end
end
end
update_chunk = vim.schedule_wrap(update_chunk)
log("job:", cmd, job_options)
handle, pid = uv.spawn(cmd, {stdio = {stdin, stdout, stderr}, args = job_options.args},
function(code, signal) -- on exit
update_chunk(nil, "Process exited with code " .. code .. " / signal " .. signal)
stdin:read_stop()
stdin:close()
handle, pid = uv.spawn(
cmd,
{ stdio = { stdin, stdout, stderr }, args = job_options.args },
function(code, signal) -- on exit
update_chunk(nil, cmd_str .. " finished with code " .. code .. " / signal " .. signal)
stdin:read_stop()
stdin:close()
stdout:read_stop()
stdout:close()
handle:close()
end)
stdout:read_stop()
stdout:close()
handle:close()
end
)
api.nvim_buf_attach(bufnr, false, {
on_detach = function()
if not handle:is_closing() then
handle:kill(15)
end
end
end,
})
-- uv.read_start(stdout, vim.schedule_wrap(on_stdout))
@ -95,12 +98,11 @@ local run = function(cmd, opts)
end)
stdout:read_start(update_chunk)
stderr:read_start(update_chunk)
end
local function make(...)
local makeprg = vim.api.nvim_buf_get_option(0, "makeprg")
local args = {...}
local args = { ... }
local setup = {}
if #args > 0 then
for i, v in ipairs(args) do
@ -112,4 +114,4 @@ local function make(...)
run(makeprg, opts)
end
return {run = run, make = make}
return { run = run, make = make }

Loading…
Cancel
Save