diff --git a/README.md b/README.md index a541f85..44fcfb7 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Requirements: - [impl](https://github.com/josharian/impl) - [gotests](https://github.com/cweill/gotests) - [iferr](https://github.com/koron/iferr) + - [json2go](https://github.com/olexsmir/json2go)
@@ -185,6 +186,24 @@ Requirements: ```
+
+ + Convert json to Go types + + + ![Convert JSON to Go types](./vhs/json2go.gif) + + `: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} + ``` + + Additionally, `gopher.json2go` provides lua api, see `:h gopher.nvim-json2go` for details. +
+
@@ -253,6 +272,15 @@ require("gopher").setup { -- e.g: `message = 'fmt.Errorf("failed to %w", err)'` message = nil, }, + json2go = { + -- command used to open interactive input. + -- e.g: `split`, `botright split`, `tabnew` + interactive_cmd = "vsplit", + + -- name of autogenerated struct + -- e.g: "MySuperCoolName" + type_name = nil, + }, } ``` diff --git a/vhs/Taskfile.yml b/vhs/Taskfile.yml index 2dfb107..b9cc588 100644 --- a/vhs/Taskfile.yml +++ b/vhs/Taskfile.yml @@ -18,3 +18,6 @@ tasks: impl: cmd: vhs impl.tape + + json2go: + cmd: vhs json2go.tape diff --git a/vhs/json2go.gif b/vhs/json2go.gif new file mode 100644 index 0000000..908f7dc Binary files /dev/null and b/vhs/json2go.gif differ diff --git a/vhs/json2go.go b/vhs/json2go.go new file mode 100644 index 0000000..c9ecbf5 --- /dev/null +++ b/vhs/json2go.go @@ -0,0 +1,2 @@ +package main + diff --git a/vhs/json2go.tape b/vhs/json2go.tape new file mode 100644 index 0000000..309856e --- /dev/null +++ b/vhs/json2go.tape @@ -0,0 +1,27 @@ +Output json2go.gif +Require nvim +Require json2go + +Set FontFamily "JetBrains Mono" +Set Height 800 +Set Width 1500 +Set Padding 20 +Set Shell "bash" +Set Theme "tokyonight" +Set TypingSpeed 250ms + +Hide Type@0ms "./nvim.sh json2go.go" Enter Show + +Type@0ms "G" +Type@400ms ":GoJson" Sleep 500ms Enter +Type@70ms "{" Enter +Type@70ms `"json": true,` Enter +Type@70ms `"user": {"name": "Name", "of_age": true}` Enter +Type@70ms "}" +Escape Type@500ms ":wq" Enter +Sleep 1s + +Type@25ms "G2o" Escape +Type@120ms `:GoJson {"json": true}` Enter + +Sleep 5s