+19
README.md
+19
README.md
···
20
20
21
21
Also, run `TSInstall go` if install the `go` parser if not installed yet.
22
22
23
+
## Config
24
+
25
+
By `.setup` function you can configure the plugin.
26
+
27
+
Note:
28
+
29
+
- Installer does not install the tool in user set path
30
+
31
+
```lua
32
+
require("gopher").setup {
33
+
commands = {
34
+
go = "go",
35
+
gomodifytags = "gomodifytags",
36
+
gotests = "~/go/bin/gotests", -- also you can set custom command path
37
+
impl = "impl",
38
+
},
39
+
}
40
+
```
41
+
23
42
## Features
24
43
25
44
1. Install requires go tools:
+19
lua/gopher/config.lua
+19
lua/gopher/config.lua
···
1
+
local M = {
2
+
config = {
3
+
---set custom commands for tools
4
+
commands = {
5
+
go = "go",
6
+
gomodifytags = "gomodifytags",
7
+
gotests = "gotests",
8
+
impl = "impl",
9
+
},
10
+
},
11
+
}
12
+
13
+
---Plugin setup function
14
+
---@param opts table user options
15
+
function M.setup(opts)
16
+
M.config = vim.tbl_deep_extend("force", M.config, opts)
17
+
end
18
+
19
+
return M
+2
-1
lua/gopher/gogenerate.lua
+2
-1
lua/gopher/gogenerate.lua
···
1
1
local Job = require "plenary.job"
2
+
local c = require("gopher.config").config.commands
2
3
local u = require "gopher._utils"
3
4
4
5
---run "go generate"
···
12
13
13
14
Job
14
15
:new({
15
-
command = "go",
16
+
command = c.go,
16
17
args = cmd_args,
17
18
on_exit = function(_, retval)
18
19
if retval ~= 0 then
+2
-1
lua/gopher/goget.lua
+2
-1
lua/gopher/goget.lua
···
1
1
local Job = require "plenary.job"
2
+
local c = require("gopher.config").config.commands
2
3
local u = require "gopher._utils"
3
4
4
5
---run "go get"
···
19
20
20
21
Job
21
22
:new({
22
-
command = "go",
23
+
command = c.go,
23
24
args = cmd_args,
24
25
on_exit = function(_, retval)
25
26
if retval ~= 0 then
+2
-1
lua/gopher/gomod.lua
+2
-1
lua/gopher/gomod.lua
···
1
1
local Job = require "plenary.job"
2
+
local c = require("gopher.config").config.commands
2
3
local u = require "gopher._utils"
3
4
4
5
---run "go mod"
···
13
14
14
15
Job
15
16
:new({
16
-
command = "go",
17
+
command = c.go,
17
18
args = cmd_args,
18
19
on_exit = function(_, retval)
19
20
if retval ~= 0 then
+2
-1
lua/gopher/gotests.lua
+2
-1
lua/gopher/gotests.lua
···
1
1
local Job = require "plenary.job"
2
2
local ts_utils = require "gopher._utils.ts"
3
+
local c = require("gopher.config").config.commands
3
4
local u = require "gopher._utils"
4
5
local M = {}
5
6
···
7
8
local function run(cmd_args)
8
9
Job
9
10
:new({
10
-
command = "gotests",
11
+
command = c.gotests,
11
12
args = cmd_args,
12
13
on_exit = function(_, retval)
13
14
if retval ~= 0 then
+5
-4
lua/gopher/health.lua
+5
-4
lua/gopher/health.lua
···
1
1
local utils = require "gopher._utils"
2
+
local c = require("gopher.config").config.commands
2
3
local M = {
3
4
_required = {
4
5
plugins = {
···
6
7
{ lib = "nvim-treesitter" },
7
8
},
8
9
binarys = {
9
-
{ bin = "go", help = "required for GoMod, GoGet, GoGenerate command" },
10
-
{ bin = "gomodifytags", help = "required for modify struct tags" },
11
-
{ bin = "impl", help = "required for interface implementing" },
12
-
{ bin = "gotests", help = "required for test(s) generation" },
10
+
{ bin = c.go, help = "required for GoMod, GoGet, GoGenerate command" },
11
+
{ bin = c.gomodifytags, help = "required for modify struct tags" },
12
+
{ bin = c.impl, help = "required for interface implementing" },
13
+
{ bin = c.gotests, help = "required for test(s) generation" },
13
14
},
14
15
},
15
16
}
+2
-1
lua/gopher/impl.lua
+2
-1
lua/gopher/impl.lua
···
1
1
local Job = require "plenary.job"
2
2
local ts_utils = require "gopher._utils.ts"
3
+
local c = require("gopher.config").config.commands
3
4
local u = require "gopher._utils"
4
5
5
6
---@return string
···
55
56
local res_data
56
57
Job
57
58
:new({
58
-
command = "impl",
59
+
command = c.impl,
59
60
args = cmd_args,
60
61
on_exit = function(data, retval)
61
62
if retval ~= 0 then
+1
lua/gopher/init.lua
+1
lua/gopher/init.lua
+41
spec/gopher_config_spec.lua
+41
spec/gopher_config_spec.lua
···
1
+
describe("gopher.config", function()
2
+
it("can be required", function()
3
+
require "gopher.config"
4
+
end)
5
+
6
+
it(".setup() when gets empty table not edit config", function()
7
+
local c = require "gopher.config"
8
+
c.setup {}
9
+
10
+
assert.are.same(c.config.commands.go, "go")
11
+
assert.are.same(c.config.commands.gomodifytags, "gomodifytags")
12
+
assert.are.same(c.config.commands.gotests, "gotests")
13
+
assert.are.same(c.config.commands.impl, "impl")
14
+
end)
15
+
16
+
it(".setup() when get one custom value sets that", function()
17
+
local c = require "gopher.config"
18
+
c.setup { commands = {
19
+
go = "custom_go",
20
+
} }
21
+
22
+
assert.are.same(c.config.commands.go, "custom_go")
23
+
end)
24
+
25
+
it(".setup() when get all custom values sets it", function()
26
+
local c = require "gopher.config"
27
+
c.setup {
28
+
commands = {
29
+
go = "go1.18",
30
+
gomodifytags = "user-gomodifytags",
31
+
gotests = "gotests",
32
+
impl = "goimpl",
33
+
},
34
+
}
35
+
36
+
assert.are.same(c.config.commands.go, "go1.18")
37
+
assert.are.same(c.config.commands.gomodifytags, "user-gomodifytags")
38
+
assert.are.same(c.config.commands.gotests, "gotests")
39
+
assert.are.same(c.config.commands.impl, "goimpl")
40
+
end)
41
+
end)