all repos

gopher.nvim @ 40a2839

Minimalistic plugin for Go development
11 files changed, 97 insertions(+), 10 deletions(-)
feat(config): add base implementation

* feat(config): naive implementation

feat(config): get command for a run from config

* docs: add config

* fix typo [skip ci]

* test: add config
Author: Smirnov Oleksandr ss2316544@gmail.com
Committed by: GitHub noreply@github.com
Committed at: 2022-06-27 20:28:35 +0300
Parent: 1db0914
M README.md

@@ -20,6 +20,25 @@ ```

Also, run `TSInstall go` if install the `go` parser if not installed yet. +## Config + +By `.setup` function you can configure the plugin. + +Note: + +- Installer does not install the tool in user set path + +```lua +require("gopher").setup { + commands = { + go = "go", + gomodifytags = "gomodifytags", + gotests = "~/go/bin/gotests", -- also you can set custom command path + impl = "impl", + }, +} +``` + ## Features 1. Install requires go tools:
A lua/gopher/config.lua

@@ -0,0 +1,19 @@

+local M = { + config = { + ---set custom commands for tools + commands = { + go = "go", + gomodifytags = "gomodifytags", + gotests = "gotests", + impl = "impl", + }, + }, +} + +---Plugin setup function +---@param opts table user options +function M.setup(opts) + M.config = vim.tbl_deep_extend("force", M.config, opts) +end + +return M
M lua/gopher/gogenerate.lua

@@ -1,4 +1,5 @@

local Job = require "plenary.job" +local c = require("gopher.config").config.commands local u = require "gopher._utils" ---run "go generate"

@@ -12,7 +13,7 @@ local cmd_args = vim.list_extend({ "generate" }, args)

Job :new({ - command = "go", + command = c.go, args = cmd_args, on_exit = function(_, retval) if retval ~= 0 then
M lua/gopher/goget.lua

@@ -1,4 +1,5 @@

local Job = require "plenary.job" +local c = require("gopher.config").config.commands local u = require "gopher._utils" ---run "go get"

@@ -19,7 +20,7 @@ local cmd_args = vim.list_extend({ "get" }, args)

Job :new({ - command = "go", + command = c.go, args = cmd_args, on_exit = function(_, retval) if retval ~= 0 then
M lua/gopher/gomod.lua

@@ -1,4 +1,5 @@

local Job = require "plenary.job" +local c = require("gopher.config").config.commands local u = require "gopher._utils" ---run "go mod"

@@ -13,7 +14,7 @@ local cmd_args = vim.list_extend({ "mod" }, args)

Job :new({ - command = "go", + command = c.go, args = cmd_args, on_exit = function(_, retval) if retval ~= 0 then
M lua/gopher/gotests.lua

@@ -1,5 +1,6 @@

local Job = require "plenary.job" local ts_utils = require "gopher._utils.ts" +local c = require("gopher.config").config.commands local u = require "gopher._utils" local M = {}

@@ -7,7 +8,7 @@ ---@param cmd_args table

local function run(cmd_args) Job :new({ - command = "gotests", + command = c.gotests, args = cmd_args, on_exit = function(_, retval) if retval ~= 0 then
M lua/gopher/health.lua

@@ -1,4 +1,5 @@

local utils = require "gopher._utils" +local c = require("gopher.config").config.commands local M = { _required = { plugins = {

@@ -6,10 +7,10 @@ { lib = "plenary" },

{ lib = "nvim-treesitter" }, }, binarys = { - { bin = "go", help = "required for GoMod, GoGet, GoGenerate command" }, - { bin = "gomodifytags", help = "required for modify struct tags" }, - { bin = "impl", help = "required for interface implementing" }, - { bin = "gotests", help = "required for test(s) generation" }, + { bin = c.go, help = "required for GoMod, GoGet, GoGenerate command" }, + { bin = c.gomodifytags, help = "required for modify struct tags" }, + { bin = c.impl, help = "required for interface implementing" }, + { bin = c.gotests, help = "required for test(s) generation" }, }, }, }
M lua/gopher/impl.lua

@@ -1,5 +1,6 @@

local Job = require "plenary.job" local ts_utils = require "gopher._utils.ts" +local c = require("gopher.config").config.commands local u = require "gopher._utils" ---@return string

@@ -55,7 +56,7 @@

local res_data Job :new({ - command = "impl", + command = c.impl, args = cmd_args, on_exit = function(data, retval) if retval ~= 0 then
M lua/gopher/init.lua

@@ -12,5 +12,6 @@ gopher.generate = require "gopher.gogenerate"

gopher.test_add = gotests.func_test gopher.test_exported = gotests.all_exported_tests gopher.tests_all = gotests.all_tests +gopher.setup = require("gopher.config").setup return gopher
M lua/gopher/struct_tags.lua

@@ -1,6 +1,7 @@

local Job = require "plenary.job" local ts_utils = require "gopher._utils.ts" local u = require "gopher._utils" +local c = require("gopher.config").config.commands local M = {} local function modify(...)

@@ -42,7 +43,7 @@ -- get result of "gomodifytags" works

local res_data Job :new({ - command = "gomodifytags", + command = c.gomodifytags, args = cmd_args, on_exit = function(data, retval) if retval ~= 0 then
A spec/gopher_config_spec.lua

@@ -0,0 +1,41 @@

+describe("gopher.config", function() + it("can be required", function() + require "gopher.config" + end) + + it(".setup() when gets empty table not edit config", function() + local c = require "gopher.config" + c.setup {} + + assert.are.same(c.config.commands.go, "go") + assert.are.same(c.config.commands.gomodifytags, "gomodifytags") + assert.are.same(c.config.commands.gotests, "gotests") + assert.are.same(c.config.commands.impl, "impl") + end) + + it(".setup() when get one custom value sets that", function() + local c = require "gopher.config" + c.setup { commands = { + go = "custom_go", + } } + + assert.are.same(c.config.commands.go, "custom_go") + end) + + it(".setup() when get all custom values sets it", function() + local c = require "gopher.config" + c.setup { + commands = { + go = "go1.18", + gomodifytags = "user-gomodifytags", + gotests = "gotests", + impl = "goimpl", + }, + } + + assert.are.same(c.config.commands.go, "go1.18") + assert.are.same(c.config.commands.gomodifytags, "user-gomodifytags") + assert.are.same(c.config.commands.gotests, "gotests") + assert.are.same(c.config.commands.impl, "goimpl") + end) +end)