Update GoGet. if cursor current line is a valid pkg url, will auto fill it to go get argument

pull/87/head
ray-x 2 years ago
parent edbd796ded
commit f5c029e5fa

@ -194,10 +194,13 @@ 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 |
| GoGet {package_url} | go get package_url. Note1 |
| GoVet | go vet |
| GoCoverage | go test -coverprofile |
Note1: if package_url not provided, will check current line is a valid package url or not, if it is valid, will
fetch current url
Show test coverage:
<img width="479" alt="GoTestCoverage" src="https://user-images.githubusercontent.com/1681295/130821038-fa2545c6-16f6-4448-9a0c-91a1ab333750.png">

@ -195,7 +195,8 @@ COMMANDS *go-nvim-commands*
:GoVet *:GoVet*
Run go vet
:GoGet {package_url} *:GoGet*
Run go get {package_url}
Run go get {package_url}, if package_url not provided, will parse
current line and use it as url if valid
:GoLint *:GoLint*
Run Golint
@ -265,6 +266,10 @@ COMMANDS *go-nvim-commands*
:GoDoc {options} *:GoDoc*
e.g. GoDoc fmt.Println
:GoImpl {options} *:GoImpl*
e.g. GoImpl {receiver} {interface}, will check if cursor is a valid
receiver, if you park cursor on struct name, receiver can be omitted.
e.g ":GoImpl io.Reader", or "GoImpl f *File io.Reader"
==============================================================================
OPTIONS *go-nvim-options*

@ -7,8 +7,23 @@ function M.run(args)
table.remove(args, i)
table.insert(args, i, m)
end
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
row, col = row - 1, col
local line = vim.api.nvim_buf_get_lines(0, row, row + 1, true)[1]
local cmd = { "go", "get" }
vim.list_extend(cmd, args)
line = line:gsub("%s+", "")
line = line:gsub('"', "")
if string.find(line, "%a+%.%a+/%a+/%a+") then
-- the cursor is on line of package URL e.g. github.com/abc/pkg
table.insert(cmd, line)
else
if #args == 0 then
table.insert(cmd, "./...")
end
end
runner.run(cmd)
end

Loading…
Cancel
Save