add go boilerplate

pull/117/head
ray-x 2 years ago
parent 86d7b26846
commit dead9e2c70

@ -35,6 +35,7 @@ _GO_NVIM_CFG = {
lsp_diag_virtual_text = { space = 0, prefix = "" },
lsp_diag_signs = true,
lsp_diag_update_in_insert = false,
go_boilplater_url = "https://github.com/thockin/go-build-template.git",
gopls_cmd = nil, --- you can provide gopls path and cmd if it not in PATH, e.g. cmd = { "/home/ray/.local/nvim/data/lspinstall/go/gopls" }
gopls_remote_auto = true,
gocoverage_sign = "",
@ -132,7 +133,9 @@ function go.setup(cfg)
-- e.g. GoTestFile unit
vim.cmd([[command! -nargs=* GoTestFile lua require('go.gotest').test_file(<f-args>)]])
vim.cmd([[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoTestPkg lua require('go.gotest').test_package(<f-args>)]])
vim.cmd(
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoTestPkg lua require('go.gotest').test_package(<f-args>)]]
)
vim.cmd([[command! -nargs=* GoAddTest lua require("go.gotests").fun_test(<f-args>)]])
vim.cmd([[command! -nargs=* GoAddExpTest lua require("go.gotests").exported_test(<f-args>)]])
vim.cmd([[command! -nargs=* GoAddAllTest lua require("go.gotests").all_test(<f-args>)]])

@ -0,0 +1,17 @@
local M = {}
local util = require("go.utils")
local log = util.log
local warn = require("go.utils").warn
local function create_boilerplate(name)
if not _GO_NVIM_CFG.go_boilplater_url then
return warn("go boilerplate url missing")
end
local path = name or vim.fn.expand("%:p:h")
local cmd = 'git clone --depth 1 --branch master ' .. _GO_NVIM_CFG.go_boilplater_url .. ' ' .. path
log(cmd)
vim.notify( "create boilerplate project: " .. vim.fn.system(cmd))
util.deletedir(path .. "/.git")
end
return {create_boilerplate=create_boilerplate}

@ -492,4 +492,22 @@ function util.restart(cmd_args)
end
end
util.deletedir = function(dir)
local lfs = require("lfs")
for file in lfs.dir(dir) do
local file_path = dir .. "/" .. file
if file ~= "." and file ~= ".." then
if lfs.attributes(file_path, "mode") == "file" then
os.remove(file_path)
print("remove file", file_path)
elseif lfs.attributes(file_path, "mode") == "directory" then
print("dir", file_path)
util.deletedir(file_path)
end
end
end
lfs.rmdir(dir)
util.log("remove dir", dir)
end
return util

Loading…
Cancel
Save