[Breaking] Rename commands(GoFillStruct GoFillSwitch, Goiferr)

pull/21/head
ray-x 3 years ago
parent 034ea57ffe
commit a65af41408

@ -17,6 +17,7 @@ The plugin covers most features required for a gopher.
- Code format: Supports LSP format and GoFmt
- Comments: Add autodocument for your package/function/struct/interface. This feature is unique and can help you suppress golint
errors...
Go to alternative go file (between test and source)
## install
@ -56,6 +57,7 @@ require('go').setup()
## refactor gorename
gorename as an alternative to gopls rename as it supports rename across packages
Command: GoRename
## code format
@ -77,6 +79,14 @@ require("go.format").goimport()
## Auto fill struct
Note: auto fill struct also supported by gopls lsp-action
| command | Description |
| ----------- | ----------- |
| GoFillStruct | auto fill struct |
| GoFillSwitch | fill switch|
![auto struct](https://github.com/ray-x/files/blob/master/img/go.nvim/fstruct.gif?raw=true)
## Textobject
@ -87,6 +97,16 @@ textobjects. Also with treesitter-objects, you can move, swap the selected block
## Build and test
| command | Description |
| ----------- | ----------- |
| GoMake | make |
| GoBuild | |
| GoGenerate | |
| GoRun | |
| GoTest | go test ./... |
| GoLint | golangci-lint |
Provided wrapper for gobulild/test etc with async make
Also suggest to use [vim-test](https://github.com/vim-test/vim-test), which can run running tests on different
granularities.
@ -95,16 +115,51 @@ granularities.
Support table based unit test auto generate, parse current function/method name using treesitter
| command | Description |
| ----------- | ----------- |
| GoTestFunc | run test for current func |
| GoAddTest | |
| GoAddExpTest | Add tests for exported funcs|
| GoAddAllTest | Add tests for all funcs |
## Modifytags
Modify struct tags by [`gomodifytags`](https://github.com/fatih/gomodifytags) and treesitter
| command | Description |
| ----------- | ----------- |
| GoAddTag | |
| GoRmTag | |
| GoClearTag | |
## GoFmt
nvim-lsp support goimport by default. The plugin provided a new formatter, goline + gofumports (stricter version of
goimport)
| command | Description |
| ----------- | ----------- |
| Gofmt | goline + gofumpt |
| Goimport | goline + goimport + gofumpt |
## Debug
| command | Description |
| ----------- | ----------- |
| GoDebug | start debug session |
| GoDebug test | start debug session for go test file |
| GoBreakToggle | |
| GoBreakCondition | conditional break |
| GoDbgStop | Stop debug session|
## Swtich between go and test file
| command | Description |
| ----------- | ----------- |
| GoAlt / GoAlt! | open alternative go file (use ! to create if not exist) |

@ -41,18 +41,18 @@ function go.setup(cfg)
end
_GO_NVIM_CFG = vim.tbl_extend("force", _GO_NVIM_CFG, cfg)
vim.cmd([[command! Gmake silent lua require'go.asyncmake'.make()]])
vim.cmd([[command! GoMake silent lua require'go.asyncmake'.make()]])
vim.cmd([[command! Gofmt lua require("go.format").gofmt()]])
vim.cmd([[command! Goimport lua require("go.format").goimport()]])
vim.cmd([[command! GoBuild :setl makeprg=go\ build | :Gmake]])
vim.cmd([[command! GoGenerate :setl makeprg=go\ generate | :Gmake]])
vim.cmd([[command! GoRun :setl makeprg=go\ run | :Gmake]])
vim.cmd([[command! GoBuild :setl makeprg=go\ build | :GoMake]])
vim.cmd([[command! GoGenerate :setl makeprg=go\ generate | :GoMake]])
vim.cmd([[command! GoRun :setl makeprg=go\ run | :GoMake]])
vim.cmd([[command! GoTest :setl makeprg=go\ test\ -v\ ./... | :Gmake]])
vim.cmd([[command! GoTestCompile :setl makeprg=go\ build | :Gmake]])
vim.cmd([[command! GoLint :setl makeprg=golangci-lint\ run\ --out-format\ tab | :Gmake]])
vim.cmd([[command! GoTest :setl makeprg=go\ test\ -v\ ./... | :GoMake]])
-- vim.cmd([[command! GoTestCompile :setl makeprg=go\ build | :GoMake]])
vim.cmd([[command! GoLint :setl makeprg=golangci-lint\ run\ --out-format\ tab | :GoMake]])
vim.cmd([[command! GoTestFunc lua require('go.gotest').test_fun()]])
vim.cmd([[command! GoAddTest lua require("go.gotests").fun_test()]])
@ -61,13 +61,13 @@ function go.setup(cfg)
vim.cmd([[command! -nargs=* GoAddTag lua require("go.tags").add(<f-args>)]])
vim.cmd([[command! -nargs=* GoRmTag lua require("go.tags").rm(<f-args>)]])
vim.cmd([[command! -nargs=* GoImpl lua require("go.impl").run(<f-args>)]])
-- vim.cmd([[command! -nargs=* GoImpl lua require("go.impl").run(<f-args>)]])
vim.cmd([[command! GoClearTag lua require("go.tags").clear()]])
vim.cmd([[command! GoCmt lua require("go.comment").gen()]])
vim.cmd([[command! GoRename lua require("go.rename").run()]])
vim.cmd([[command! Giferr lua require("go.iferr").run()]])
vim.cmd([[command! Gfstruct lua require("go.reftool").fillstruct()]])
vim.cmd([[command! Gfswitch lua require("go.reftool").fillswitch()]])
vim.cmd([[command! Goiferr lua require("go.iferr").run()]])
vim.cmd([[command! GoFillStruct lua require("go.reftool").fillstruct()]])
vim.cmd([[command! GoFillSwitch lua require("go.reftool").fillswitch()]])
vim.cmd([[command! -bang GoAlt lua require"go.alternate".switch("<bang>"=="!", '')]])
vim.cmd([[command! -bang GoAltV lua require"go.alternate".switch("<bang>"=="!", 'vsplit')]])
@ -87,6 +87,9 @@ function go.setup(cfg)
vim.cmd([[command! ReplOpen lua require"dap".repl.open(), 'split']])
vim.cmd(
[[command! DapRerun require'dap'.disconnect();require'dap'.stop();require'dap'.run_last()]])
vim.cmd([[command! GoDbgStop require'go.dap'.stop()]])
end
if _GO_NVIM_CFG.lsp_cfg then

@ -1,4 +1,4 @@
local bind = require("keymap.bind")
local bind = require("go.keybind")
local map_cr = bind.map_cr
local utils = require('go.utils')
local function setup_telescope()

@ -0,0 +1,86 @@
local rhs_options = {}
function rhs_options:new()
local instance = {
cmd = '',
options = {noremap = false, silent = false, expr = false, nowait = false}
}
setmetatable(instance, self)
self.__index = self
return instance
end
function rhs_options:map_cmd(cmd_string)
self.cmd = cmd_string
return self
end
function rhs_options:map_cr(cmd_string)
self.cmd = (":%s<CR>"):format(cmd_string)
return self
end
function rhs_options:map_args(cmd_string)
self.cmd = (":%s<Space>"):format(cmd_string)
return self
end
function rhs_options:map_cu(cmd_string)
self.cmd = (":<C-u>%s<CR>"):format(cmd_string)
return self
end
function rhs_options:with_silent()
self.options.silent = true
return self
end
function rhs_options:with_noremap()
self.options.noremap = true
return self
end
function rhs_options:with_expr()
self.options.expr = true
return self
end
function rhs_options:with_nowait()
self.options.nowait = true
return self
end
local pbind = {}
function pbind.map_cr(cmd_string)
local ro = rhs_options:new()
return ro:map_cr(cmd_string)
end
function pbind.map_cmd(cmd_string)
local ro = rhs_options:new()
return ro:map_cmd(cmd_string)
end
function pbind.map_cu(cmd_string)
local ro = rhs_options:new()
return ro:map_cu(cmd_string)
end
function pbind.map_args(cmd_string)
local ro = rhs_options:new()
return ro:map_args(cmd_string)
end
function pbind.nvim_load_mapping(mapping)
for key, value in pairs(mapping) do
local mode, keymap = key:match("([^|]*)|?(.*)")
if type(value) == 'table' then
local rhs = value.cmd
local options = value.options
vim.api.nvim_set_keymap(mode, keymap, rhs, options)
end
end
end
return pbind
Loading…
Cancel
Save