go.nvim/lua/go/project.lua
ray-x fe8196f9d1 [goimport->goimports] Enduring the frustration of a longstanding typo, I've finally resolved to correct it. The change updates "goimport" to "goimport," including all related documentation and tests.
Additionally, I've set gopls as the default tool for both gofmt and goimports. This integration will be quicker than executing a separate command in the background and analyzing its output.
2024-03-19 13:15:58 +11:00

73 lines
2.0 KiB
Lua

-- this file allow a setup load per project
--[[
-- sample cfg
return {
go = "go", -- set to go1.18beta1 if necessary
goimports = "gopls", -- if set to 'gopls' will use gopls format, also goimports
gofmt = "gofumpt", -- if set to gopls will use gopls format
tag_transform = false,
test_dir = "",
sign_priority = 5,
launch_json = nil, -- the launch.json file path, default to .vscode/launch.json
-- launch_json = vfn.getcwd() .. "/.vscode/launch.json",
build_tags = "", --- you can provide extra build tags for tests or debugger
}
]]
-- if the file existed, load it into config
local vfn = vim.fn
local util = require("go.utils")
local log = util.log
local M = {}
local sep = require("go.utils").sep()
function M.project_existed()
local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vfn.getcwd()
local gocfgfd = workfolder .. sep .. ".gonvim"
local gocfgbrks = gocfgfd .. sep .. "breakpoints.lua"
local gocfg = gocfgfd .. sep .. "init.lua"
if vfn.filereadable(gocfg) == 1 or vfn.filereadable(gocfgbrks) == 1 then
log("projects existed", gocfg, gocfgbrks)
return gocfg, gocfgbrks
end
end
function M.setup()
local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vfn.getcwd()
local gocfgfd = workfolder .. sep .. ".gonvim"
local gocfg = gocfgfd .. sep .. "init.lua"
if vfn.isdirectory(gocfgfd) == 0 then
vfn.mkdir(gocfgfd)
end
if vfn.filereadable(gocfg) == 0 then
local f = io.open(gocfg, "w")
f:write("return {}")
f:close()
end
return gocfg, gocfgfd
end
function M.load_project()
local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vfn.getcwd()
local gocfg = workfolder .. sep .. ".gonvim" .. sep .. "init.lua"
if _GO_NVIM_CFG.disable_per_project_cfg then
log("project setup existed but disabled")
return
end
if vfn.filereadable(gocfg) == 1 then
local f = assert(loadfile(gocfg))
log(f())
_GO_NVIM_CFG = vim.tbl_deep_extend("force", _GO_NVIM_CFG, f())
else
return false
end
end
M.load_project()
return M