feat: json2go (#130)
* feat(json2go): implement * feat(json2go): support manual input * chore(readme): add json2go * chore(docs): add docs
This commit is contained in:
parent
4a2384ade8
commit
6a3924cee5
16 changed files with 312 additions and 1 deletions
|
|
@ -13,6 +13,7 @@ Table of Contents
|
|||
Config ................................................ |gopher.nvim-config|
|
||||
Commands ............................................ |gopher.nvim-commands|
|
||||
Modify struct tags ............................... |gopher.nvim-struct-tags|
|
||||
json2go .............................................. |gopher.nvim-json2go|
|
||||
Auto implementation of interface methods ................ |gopher.nvim-impl|
|
||||
Generating unit tests boilerplate .................... |gopher.nvim-gotests|
|
||||
Iferr .................................................. |gopher.nvim-iferr|
|
||||
|
|
@ -69,6 +70,7 @@ or use `require("gopher").install_deps()` if you prefer lua api.
|
|||
gotests = "gotests",
|
||||
impl = "impl",
|
||||
iferr = "iferr",
|
||||
json2go = "json2go",
|
||||
},
|
||||
---@class gopher.ConfigGotests
|
||||
gotests = {
|
||||
|
|
@ -96,12 +98,24 @@ or use `require("gopher").install_deps()` if you prefer lua api.
|
|||
---@type string|nil
|
||||
option = nil,
|
||||
},
|
||||
---@class gopher.ConfigIfErr
|
||||
iferr = {
|
||||
-- choose a custom error message, nil to use default
|
||||
-- e.g: `message = 'fmt.Errorf("failed to %w", err)'`
|
||||
---@type string|nil
|
||||
message = nil,
|
||||
},
|
||||
---@class gopher.ConfigJson2Go
|
||||
json2go = {
|
||||
-- command used to open interactive input.
|
||||
-- e.g: `split`, `botright split`, `tabnew`
|
||||
interactive_cmd = "vsplit",
|
||||
|
||||
-- name of autogenerated struct, if nil none, will the default one of json2go.
|
||||
-- e.g: "MySuperCoolName"
|
||||
---@type string|nil
|
||||
type_name = nil,
|
||||
},
|
||||
}
|
||||
<
|
||||
Class ~
|
||||
|
|
@ -157,6 +171,42 @@ Example:
|
|||
}
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
------------------------------------------------------------------------------
|
||||
*gopher.nvim-json2go*
|
||||
|
||||
Convert json to go type annotations.
|
||||
|
||||
Usage ~
|
||||
|
||||
`:GoJson` opens a temporary buffer where you can paste or write JSON.
|
||||
Saving the buffer (`:w` or `:wq`) automatically closes it and inserts the
|
||||
generated Go struct into the original buffer at the cursor position.
|
||||
|
||||
Alternatively, you can pass JSON directly as an argument:
|
||||
>vim
|
||||
:GoJson {"name": "Alice", "age": 30}
|
||||
<
|
||||
------------------------------------------------------------------------------
|
||||
*json2go.transform()*
|
||||
`json2go.transform`({json_str})
|
||||
|
||||
Parameters ~
|
||||
{json_str} `(string)` Json string that is going to be converted to go type.
|
||||
Return ~
|
||||
`(string)` `(optional)` Go type, or nil if failed.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*json2go.json2go()*
|
||||
`json2go.json2go`({json_str})
|
||||
Converts json string to go type, and puts result under the cursor. If
|
||||
[json_str] is nil, will open an interactive prompt (with cmd set in
|
||||
config).
|
||||
|
||||
Parameters ~
|
||||
{json_str} `(optional)` `(string)`
|
||||
|
||||
|
||||
==============================================================================
|
||||
------------------------------------------------------------------------------
|
||||
*gopher.nvim-impl*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue