feat(iferr): add -message support (#89)
* feat(iferr): add *-message* support * generate docs
This commit is contained in:
parent
bb31271311
commit
d1a21bffab
6 changed files with 48 additions and 1 deletions
|
|
@ -88,6 +88,11 @@ You can look at default options |gopher.nvim-config-defaults|
|
||||||
-- default tags to add to struct fields
|
-- default tags to add to struct fields
|
||||||
default_tag = "json",
|
default_tag = "json",
|
||||||
},
|
},
|
||||||
|
iferr = {
|
||||||
|
-- choose a custom error message
|
||||||
|
---@type string|nil
|
||||||
|
message = nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
<
|
<
|
||||||
Class ~
|
Class ~
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,11 @@ local default_config = {
|
||||||
-- default tags to add to struct fields
|
-- default tags to add to struct fields
|
||||||
default_tag = "json",
|
default_tag = "json",
|
||||||
},
|
},
|
||||||
|
iferr = {
|
||||||
|
-- choose a custom error message
|
||||||
|
---@type string|nil
|
||||||
|
message = nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
--minidoc_afterlines_end
|
--minidoc_afterlines_end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,13 @@ function iferr.iferr()
|
||||||
local pos = vim.fn.getcurpos()[2]
|
local pos = vim.fn.getcurpos()[2]
|
||||||
local fpath = vim.fn.expand "%"
|
local fpath = vim.fn.expand "%"
|
||||||
|
|
||||||
local rs = r.sync({ c.commands.iferr, "-pos", curb }, {
|
local cmd = { c.commands.iferr, "-pos", curb }
|
||||||
|
if c.iferr.message ~= nil and type(c.iferr.message) == "string" then
|
||||||
|
table.insert(cmd, "-message")
|
||||||
|
table.insert(cmd, c.iferr.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
local rs = r.sync(cmd, {
|
||||||
stdin = u.readfile_joined(fpath),
|
stdin = u.readfile_joined(fpath),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
7
spec/fixtures/iferr/message_input.go
vendored
Normal file
7
spec/fixtures/iferr/message_input.go
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
func getErr() error { return nil }
|
||||||
|
|
||||||
|
func test() error {
|
||||||
|
err := getErr()
|
||||||
|
}
|
||||||
10
spec/fixtures/iferr/message_output.go
vendored
Normal file
10
spec/fixtures/iferr/message_output.go
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
func getErr() error { return nil }
|
||||||
|
|
||||||
|
func test() error {
|
||||||
|
err := getErr()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,4 +23,18 @@ T["iferr"]["works"] = function()
|
||||||
t.eq(t.readfile(tmp), fixtures.output)
|
t.eq(t.readfile(tmp), fixtures.output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
T["iferr"]["works with custom message"] = function()
|
||||||
|
local tmp = t.tmpfile()
|
||||||
|
local fixtures = t.get_fixtures "iferr/message"
|
||||||
|
t.writefile(tmp, fixtures.input)
|
||||||
|
|
||||||
|
child.lua [[ require("gopher").setup { iferr = { message = 'fmt.Errorf("failed to %w", err)' } } ]]
|
||||||
|
child.cmd("silent edit " .. tmp)
|
||||||
|
child.fn.setpos(".", { child.fn.bufnr "%", 6, 2, 0 })
|
||||||
|
child.cmd "GoIfErr"
|
||||||
|
child.cmd "write"
|
||||||
|
|
||||||
|
t.eq(t.readfile(tmp), fixtures.output)
|
||||||
|
end
|
||||||
|
|
||||||
return T
|
return T
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue