+27
-7
README.md
+27
-7
README.md
···
23
23
## Features
24
24
25
25
1. Install requires go tools:
26
+
27
+
```vim
28
+
:GoInstallDeps
29
+
```
30
+
26
31
This will install next tools:
27
32
28
33
- [gomodifytags](https://github.com/fatih/gomodifytags)
29
-
30
-
```viml
31
-
:GoInstallDeps
32
-
```
34
+
- [impl](https://github.com/josharian/impl)
33
35
34
36
2. Modify struct tags:
35
37
By default be added/removed `json` tag, if not set.
36
38
37
-
```viml
39
+
```vim
38
40
:GoTagAdd json " For add json tag
39
41
:GoTagRm yaml " For remove yaml tag
40
42
```
41
43
42
44
3. Run `go mod` command
43
45
44
-
```viml
46
+
```vim
45
47
:GoMod tidy " Runs `go mod tidy`
46
48
:GoMod init asdf " Runs `go mod init asdf`
47
49
```
···
52
54
53
55
You can provide more that one package url.
54
56
55
-
```viml
57
+
```vim
56
58
:GoGet github.com/gorilla/mux
59
+
```
60
+
61
+
5. Interface implementation
62
+
63
+
Command syntax:
64
+
```vim
65
+
:GoImpl [receiver] [interface]
66
+
67
+
" Also you can put cursor on the struct and run:
68
+
:GoImpl [interface]
69
+
```
70
+
71
+
Example of usage:
72
+
```vim
73
+
" Example
74
+
:GoImpl r Read io.Reader
75
+
" or simply put your cursor in the struct and run:
76
+
:GoImpl io.Reader
57
77
```
58
78
59
79
## Thanks
+74
lua/gopher/impl.lua
+74
lua/gopher/impl.lua
···
1
+
local Job = require "plenary.job"
2
+
local ts_utils = require "gopher._utils.ts"
3
+
4
+
local function get_struct()
5
+
local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0)))
6
+
if ns == nil then
7
+
print "put cursor on struct or specify a receiver"
8
+
return ""
9
+
end
10
+
11
+
vim.api.nvim_win_set_cursor(0, {
12
+
ns.dim.e.r,
13
+
ns.dim.e.c,
14
+
})
15
+
16
+
return ns.name
17
+
end
18
+
19
+
return function(...)
20
+
local args = { ... }
21
+
local iface, recv_name = "", ""
22
+
local recv = get_struct()
23
+
24
+
if #args == 0 then
25
+
iface = vim.fn.input "impl: generating method stubs for interface: "
26
+
vim.cmd "redeaw!"
27
+
if iface == "" then
28
+
print "usage: GoImpl f *File io.Reader"
29
+
end
30
+
elseif #args == 1 then -- :GoImpl io.Reader
31
+
recv = string.lower(recv) .. " *" .. recv
32
+
vim.cmd "redraw!"
33
+
iface = select(1, ...)
34
+
elseif #args == 2 then -- :GoImpl w io.Writer
35
+
recv_name = select(1, ...)
36
+
recv = string.format("%s *%s", recv_name, recv)
37
+
iface = select(#args, ...)
38
+
elseif #args > 2 then
39
+
iface = select(#args, ...)
40
+
recv = select(#args - 1, ...)
41
+
recv_name = select(#args - 2, ...)
42
+
recv = string.format("%s %s", recv_name, recv)
43
+
end
44
+
45
+
-- stylua: ignore
46
+
local cmd_args = {
47
+
"-dir", vim.fn.fnameescape(vim.fn.expand "%:p:h"), ---@diagnostic disable-line: missing-parameter
48
+
recv,
49
+
iface
50
+
}
51
+
52
+
local res_data
53
+
Job
54
+
:new({
55
+
command = "impl",
56
+
args = cmd_args,
57
+
on_exit = function(data, retval)
58
+
if retval ~= 0 then
59
+
print("command exited with code " .. retval)
60
+
return
61
+
end
62
+
63
+
res_data = data:result()
64
+
end,
65
+
})
66
+
:sync()
67
+
68
+
local pos = vim.fn.getcurpos()[2]
69
+
table.insert(res_data, 1, "")
70
+
vim.fn.append(pos, res_data)
71
+
72
+
-- table.insert(res_data, 1, "")
73
+
-- vim.fn.append(vim.fn.getcurpos()[2], res_data)
74
+
end
+1
lua/gopher/init.lua
+1
lua/gopher/init.lua
+1
lua/gopher/installer.lua
+1
lua/gopher/installer.lua
+1
plugin/gopher.vim
+1
plugin/gopher.vim
···
2
2
command! -nargs=* GoTagRm :lua require"gopher".tags_rm(<f-args>)
3
3
command! -nargs=* GoMod :lua require"gopher".mod(<f-args>)
4
4
command! -nargs=* GoGet :lua require"gopher".get(<f-args>)
5
+
command! -nargs=* GoImpl :lua require"gopher".impl(<f-args>)
5
6
command! GoInstallDeps :lua require"gopher".install_deps()