Add iferr integration (#15)
* feat(iferr): add to installer & config * feat(iferr): add first implementation * docs(iferr): add
This commit is contained in:
parent
4b83da6d7f
commit
eb19ecdc05
6 changed files with 35 additions and 2 deletions
12
README.md
12
README.md
|
|
@ -130,12 +130,20 @@ Generate tests only for exported functions/methods in current file:
|
||||||
|
|
||||||
8. Generate doc comment
|
8. Generate doc comment
|
||||||
|
|
||||||
First set a cursor on **public** package/function/interface/struct and execure:
|
First set a cursor on **public** package/function/interface/struct and execute:
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
:GoCmt
|
:GoCmt
|
||||||
```
|
```
|
||||||
|
|
||||||
## Thanks:
|
9. Generate `if err`
|
||||||
|
|
||||||
|
Set cursor on the line with **err** and execute:
|
||||||
|
|
||||||
|
```vim
|
||||||
|
:GoIfErr
|
||||||
|
```
|
||||||
|
|
||||||
|
## Thanks
|
||||||
|
|
||||||
- [go.nvim](https://github.com/ray-x/go.nvim)
|
- [go.nvim](https://github.com/ray-x/go.nvim)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ local M = {
|
||||||
gomodifytags = "gomodifytags",
|
gomodifytags = "gomodifytags",
|
||||||
gotests = "gotests",
|
gotests = "gotests",
|
||||||
impl = "impl",
|
impl = "impl",
|
||||||
|
iferr = "iferr",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
lua/gopher/iferr.lua
Normal file
21
lua/gopher/iferr.lua
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
local c = require("gopher.config").config.commands
|
||||||
|
local u = require "gopher._utils"
|
||||||
|
|
||||||
|
---Add iferr declaration
|
||||||
|
---That's Lua of vimscript implementation of:
|
||||||
|
---github.com/koron/iferr
|
||||||
|
return function()
|
||||||
|
local boff = vim.fn.wordcount().cursor_bytes
|
||||||
|
local cmd = (c.iferr .. " -pos " .. boff)
|
||||||
|
local data = vim.fn.systemlist(cmd, vim.fn.bufnr "%")
|
||||||
|
|
||||||
|
if vim.v.shell_error ~= 0 then
|
||||||
|
u.notify("command " .. cmd .. " exited with code " .. vim.v.shell_error, "error")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos = vim.fn.getcurpos()[2]
|
||||||
|
vim.fn.append(pos, data)
|
||||||
|
vim.cmd [[silent normal! j=2j]]
|
||||||
|
vim.fn.setpos(".", pos)
|
||||||
|
end
|
||||||
|
|
@ -9,6 +9,7 @@ gopher.mod = require "gopher.gomod"
|
||||||
gopher.get = require "gopher.goget"
|
gopher.get = require "gopher.goget"
|
||||||
gopher.impl = require "gopher.impl"
|
gopher.impl = require "gopher.impl"
|
||||||
gopher.generate = require "gopher.gogenerate"
|
gopher.generate = require "gopher.gogenerate"
|
||||||
|
gopher.iferr = require "gopher.iferr"
|
||||||
gopher.comment = require "gopher.comment"
|
gopher.comment = require "gopher.comment"
|
||||||
gopher.test_add = gotests.func_test
|
gopher.test_add = gotests.func_test
|
||||||
gopher.test_exported = gotests.all_exported_tests
|
gopher.test_exported = gotests.all_exported_tests
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ local urls = {
|
||||||
gomodifytags = "github.com/fatih/gomodifytags",
|
gomodifytags = "github.com/fatih/gomodifytags",
|
||||||
impl = "github.com/josharian/impl",
|
impl = "github.com/josharian/impl",
|
||||||
gotests = "github.com/cweill/gotests/...",
|
gotests = "github.com/cweill/gotests/...",
|
||||||
|
iferr = "github.com/koron/iferr",
|
||||||
}
|
}
|
||||||
|
|
||||||
---@param pkg string
|
---@param pkg string
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,5 @@ command! -nargs=* GoGet :lua require"gopher".get(<f-args>)
|
||||||
command! -nargs=* GoImpl :lua require"gopher".impl(<f-args>)
|
command! -nargs=* GoImpl :lua require"gopher".impl(<f-args>)
|
||||||
command! -nargs=* GoGenerate :lua require"gopher".generate(<f-args>)
|
command! -nargs=* GoGenerate :lua require"gopher".generate(<f-args>)
|
||||||
command! GoCmt :lua require"gopher".comment()
|
command! GoCmt :lua require"gopher".comment()
|
||||||
|
command! GoIfErr :lua require"gopher".iferr()
|
||||||
command! GoInstallDeps :lua require"gopher".install_deps()
|
command! GoInstallDeps :lua require"gopher".install_deps()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue