-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathgo.lua
More file actions
91 lines (86 loc) · 2.44 KB
/
go.lua
File metadata and controls
91 lines (86 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
local M = {}
local methods = require "null-ls.methods"
local code_action = methods.internal.CODE_ACTION
local helpers = require "user.null_ls.helpers"
M.gostructhelper = helpers.make_code_action {
name = "gostructhelper",
method = code_action,
filetypes = { "go" },
action_fn = function(params)
local typ = helpers.extract_struct_name(params)
if not typ then
return
end
local command = "gostructhelper"
local actions = {
{
title = "[gostructhelper] Generate constructor",
command = command,
stdin = true,
args = { "-stdin", "-file", params.bufname, "-type", typ, "-constructor" },
},
{
title = "[gostructhelper] Generate getter",
command = command,
stdin = true,
args = { "-stdin", "-file", params.bufname, "-type", typ, "-getter" },
},
}
return actions
end,
}
M.gomodifytags = helpers.make_code_action {
name = "gomodifytags",
filetypes = { "go" },
method = code_action,
action_fn = function(params)
local typ = helpers.extract_struct_name(params)
if not typ then
return
end
-- local tool = "gomodifytags"
-- local config = {
-- cmd = "./" .. tool,
-- install_script = [[
-- GOPATH=$(pwd) GOBIN=$(pwd) GO111MODULE=on go get -v github.com/fatih/gomodifytags
-- GOPATH=$(pwd) GO111MODULE=on go clean -modcache
-- ]],
-- }
local command = "gomodifytags"
local actions = {
{
title = "[gomodifytags] Add struct tags",
callback = function(invoke_cli)
local tag = helpers.prompt_tag_name()
if not tag then
return
end
invoke_cli {
command = command,
args = { "-file", params.bufname, "-struct", typ, "-skip-unexported", "-add-tags", tag },
}
end,
},
{
title = "[gomodifytags] Remove struct tags",
callback = function(invoke_cli)
local tag = helpers.prompt_tag_name()
if not tag then
return
end
invoke_cli {
command = command,
args = { "-file", params.bufname, "-struct", typ, "-skip-unexported", "-remove-tags", tag },
}
end,
},
{
title = "[gomodifytags] Clear struct tags",
command = command,
args = { "-file", params.bufname, "-struct", typ, "-skip-unexported", "-clear-tags" },
},
}
return actions
end,
}
return M