Update GoGet. if cursor current line is a valid pkg url, will auto fill it to go get argument
This commit is contained in:
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 | go test packagepath -tags=yourtags |
|
||||||
| GoTest package_path -tags=yourtags other_args | go test packagepath -tags=yourtags other_args |
|
| GoTest package_path -tags=yourtags other_args | go test packagepath -tags=yourtags other_args |
|
||||||
| GoLint | golangci-lint |
|
| GoLint | golangci-lint |
|
||||||
| GoGet package_url | go get package_url |
|
| GoGet {package_url} | go get package_url. Note1 |
|
||||||
| GoVet | go vet |
|
| GoVet | go vet |
|
||||||
| GoCoverage | go test -coverprofile |
|
| 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:
|
Show test coverage:
|
||||||
|
|
||||||
<img width="479" alt="GoTestCoverage" src="https://user-images.githubusercontent.com/1681295/130821038-fa2545c6-16f6-4448-9a0c-91a1ab333750.png">
|
<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*
|
:GoVet *:GoVet*
|
||||||
Run go vet
|
Run go vet
|
||||||
:GoGet {package_url} *:GoGet*
|
: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*
|
:GoLint *:GoLint*
|
||||||
Run Golint
|
Run Golint
|
||||||
@ -265,6 +266,10 @@ COMMANDS *go-nvim-commands*
|
|||||||
:GoDoc {options} *:GoDoc*
|
:GoDoc {options} *:GoDoc*
|
||||||
e.g. GoDoc fmt.Println
|
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*
|
OPTIONS *go-nvim-options*
|
||||||
|
|
||||||
|
@ -7,8 +7,23 @@ function M.run(args)
|
|||||||
table.remove(args, i)
|
table.remove(args, i)
|
||||||
table.insert(args, i, m)
|
table.insert(args, i, m)
|
||||||
end
|
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" }
|
local cmd = { "go", "get" }
|
||||||
vim.list_extend(cmd, args)
|
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)
|
runner.run(cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user