diff --git a/README.md b/README.md index 0f6ae53..08afc8f 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/doc/go.txt b/doc/go.txt index b63f0d5..9148f20 100644 --- a/doc/go.txt +++ b/doc/go.txt @@ -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 diff --git a/lua/go.lua b/lua/go.lua index 152b730..3cce95f 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -141,6 +141,7 @@ function go.setup(cfg) ) vim.cmd([[command! -nargs=* GoProject lua require('go.project').setup()]]) + vim.cmd([[command! -nargs=* GoCheat lua require('go.chtsh').run()]]) -- e.g. GoTestFunc unit vim.cmd([[command! -nargs=* GoTestFunc lua require('go.gotest').test_fun()]]) diff --git a/lua/go/chtsh.lua b/lua/go/chtsh.lua new file mode 100644 index 0000000..58298fa --- /dev/null +++ b/lua/go/chtsh.lua @@ -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} diff --git a/lua/go/format.lua b/lua/go/format.lua index 5641d79..bd9b154 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -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)