cheatsheet(cht.sh) supports in go.nvim

pull/130/head
ray-x 2 years ago
parent bbb37ea81f
commit 051e8b2afa

@ -26,6 +26,7 @@ The plugin covers most features required for a gopher.
- Go 1.18 support, configure your go to `go1.18` in config
- GoFixPlural, FixStruct, FxiSwitch, Add comment, IfErr, ModTidy, GoGet ... Most of the tools are built on top of
treesitter AST or go AST. It is fast and accurate.
- GoCheat get go cheatsheet from [cheat.sh](https://cheat.sh/).
## Installation
@ -253,6 +254,7 @@ Support table based unit test auto generate, parse current function/method name
| command | Description |
| ------------------------ | ------------------------------------------------------- |
| GoTestFunc | run test for current func |
| GoTestFunc -s | select the test function you want to run |
| GoTestFunc -tags=yourtag | run test for current func with `-tags yourtag` option |
| GoTestFile | run test for current file |
| GoTestFile -tags=yourtag | run test for current folder with `-tags yourtag` option |
@ -275,6 +277,10 @@ GoTestXXX Arugments
Note: For GoTestXXX
You can add available arguments e.g. `GoTest -tags=integration ./internal/web -bench=. -count=1 -`
## GoCheat
Show cheat.sh for api in neovim new buffer. e.g. `GoCheat `sort
## GoDoc
Show go doc for api in neovim floating window. e.g. `GoDoc fmt.Println`

@ -184,8 +184,9 @@ COMMANDS *go-nvim-commands*
:GoTestFile {-tags=tagname} *:GoTestFile*
Test current file
:GoTestFunc {-tags=tagname} *:GoTestFunc*
:GoTestFunc {args} {-tags=tagname} *:GoTestFunc*
Test current function
{args} -s: select the function you want to run
:GoAddTest *:GoAddTest*
Add unit test for current function
@ -194,6 +195,8 @@ COMMANDS *go-nvim-commands*
Format code with golines+gofumpt package
:GoVet *:GoVet*
Run go vet
:GoCheat query *:GoCheat*
Run `curl cheat.sh/go/query`
:GoGet {package_url} *:GoGet*
Run go get {package_url}, if package_url not provided, will parse
current line and use it as url if valid

@ -141,6 +141,7 @@ function go.setup(cfg)
)
vim.cmd([[command! -nargs=* GoProject lua require('go.project').setup(<f-args>)]])
vim.cmd([[command! -nargs=* GoCheat lua require('go.chtsh').run(<f-args>)]])
-- e.g. GoTestFunc unit
vim.cmd([[command! -nargs=* GoTestFunc lua require('go.gotest').test_fun(<f-args>)]])

@ -0,0 +1,24 @@
local utils = require("go.utils")
local log = utils.log
local curl = "curl"
local run = function(...)
local query = select(1, ...)
local cmd = string.format('%s cht.sh/go/%s?T', curl, query)
local data = vim.fn.systemlist(cmd, vim.fn.bufnr('%'))
data = utils.handle_job_data(data)
if not data then
return
end
-- log(data)
if #data > 0 then
data = vim.list_slice(data, 4, #data)
local name = vim.fn.tempname() .. ".go"
vim.fn.writefile(data, name)
cmd = " silent exe 'e " .. name .. "'"
vim.cmd(cmd)
vim.cmd('e')
end
end
return {run = run}

@ -26,6 +26,10 @@ local run = function(fmtargs, from_buffer, cmd)
log("formatting... " .. vim.inspect(args), vim.lsp.log_levels.DEBUG)
end
if vim.fn.getbufinfo('%')[1].changed == 1 then
api.nvim_command("w")
end
local old_lines = api.nvim_buf_get_lines(0, 0, -1, true)
if cmd then
table.insert(args, 1, cmd)

Loading…
Cancel
Save