2022-05-13 09:27:02 +00:00
|
|
|
-- this file allow a setup load per project
|
|
|
|
--[[
|
|
|
|
-- sample cfg
|
|
|
|
return {
|
|
|
|
go = "go", -- set to go1.18beta1 if necessary
|
|
|
|
goimport = "gopls", -- if set to 'gopls' will use gopls format, also goimport
|
|
|
|
fillstruct = "gopls",
|
|
|
|
gofmt = "gofumpt", -- if set to gopls will use gopls format
|
|
|
|
max_line_len = 120,
|
|
|
|
tag_transform = false,
|
|
|
|
test_dir = "",
|
|
|
|
gocoverage_sign_priority = 5,
|
|
|
|
launch_json = nil, -- the launch.json file path, default to .vscode/launch.json
|
2022-06-01 11:29:13 +00:00
|
|
|
-- launch_json = vfn.getcwd() .. "/.vscode/launch.json",
|
2022-05-13 15:07:44 +00:00
|
|
|
|
2022-05-13 09:27:02 +00:00
|
|
|
build_tags = "", --- you can provide extra build tags for tests or debugger
|
2022-05-13 15:07:44 +00:00
|
|
|
|
2022-05-13 09:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
-- if the file existed, load it into config
|
2022-06-01 11:29:13 +00:00
|
|
|
local vfn = vim.fn
|
2022-05-13 09:27:02 +00:00
|
|
|
local util = require("go.utils")
|
|
|
|
local log = util.log
|
|
|
|
local M = {}
|
|
|
|
local sep = require("go.utils").sep()
|
|
|
|
|
2022-05-13 15:07:44 +00:00
|
|
|
function M.project_existed()
|
2022-06-01 11:29:13 +00:00
|
|
|
local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vfn.getcwd()
|
2022-05-13 15:07:44 +00:00
|
|
|
local gocfgfd = workfolder .. sep .. ".gonvim"
|
|
|
|
local gocfgbrks = gocfgfd .. sep .. "breakpoints.lua"
|
|
|
|
local gocfg = gocfgfd .. sep .. "init.lua"
|
2022-06-01 11:29:13 +00:00
|
|
|
if vfn.filereadable(gocfg) == 1 or vfn.filereadable(gocfgbrks) == 1 then
|
2022-05-13 15:07:44 +00:00
|
|
|
log("projects existed", gocfg, gocfgbrks)
|
|
|
|
return gocfg, gocfgbrks
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-15 04:09:07 +00:00
|
|
|
function M.setup()
|
2022-06-01 11:29:13 +00:00
|
|
|
local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vfn.getcwd()
|
2022-05-13 15:07:44 +00:00
|
|
|
local gocfgfd = workfolder .. sep .. ".gonvim"
|
|
|
|
local gocfg = gocfgfd .. sep .. "init.lua"
|
2022-05-13 09:27:02 +00:00
|
|
|
|
2022-06-01 11:29:13 +00:00
|
|
|
if vfn.isdirectory(gocfgfd) == 0 then
|
|
|
|
vfn.mkdir(gocfgfd)
|
2022-05-13 15:07:44 +00:00
|
|
|
end
|
2022-06-01 11:29:13 +00:00
|
|
|
if vfn.filereadable(gocfg) == 0 then
|
2022-05-13 09:27:02 +00:00
|
|
|
local f = io.open(gocfg, "w")
|
|
|
|
f:write("return {}")
|
|
|
|
f:close()
|
|
|
|
end
|
2022-05-13 15:07:44 +00:00
|
|
|
return gocfg, gocfgfd
|
2022-05-13 09:27:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.load_project()
|
2022-06-01 11:29:13 +00:00
|
|
|
local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vfn.getcwd()
|
2022-05-15 04:19:05 +00:00
|
|
|
local gocfg = workfolder .. sep .. ".gonvim" .. sep .. "init.lua"
|
2022-07-08 10:30:23 +00:00
|
|
|
if _GO_NVIM_CFG.disable_per_project_cfg then
|
|
|
|
log("project setup existed but disabled")
|
|
|
|
return
|
|
|
|
end
|
2022-06-01 11:29:13 +00:00
|
|
|
if vfn.filereadable(gocfg) == 1 then
|
2022-05-13 09:27:02 +00:00
|
|
|
local f = assert(loadfile(gocfg))
|
2022-05-15 04:19:05 +00:00
|
|
|
log(f())
|
2022-05-13 09:27:02 +00:00
|
|
|
_GO_NVIM_CFG = vim.tbl_deep_extend("force", _GO_NVIM_CFG, f())
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
M.load_project()
|
|
|
|
|
|
|
|
return M
|