goenv and load breakpoints

pull/117/head
ray-x 2 years ago
parent f3e1da9968
commit de1306a986

@ -71,12 +71,12 @@ require('go').setup()
```
## Project setup
`go.nvim` allow you override your setup by a project file. Put `.gonvim` in your root folder. It is a small lua
`go.nvim` allow you override your setup by a project file. Put `.gonvim/init.lua` in your root folder. It is a small lua
script and will be run durning go.setup(). The return value is used to override `go.nvim` setup. The sample project
setup
```lua
-- .gonvim project config
-- .gonvim/init.lua project config
vim.g.null_ls_disable = true
return {

@ -152,6 +152,8 @@ function go.setup(cfg)
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>)]])
vim.cmd([[command! -nargs=* GoModVendor lua require("go.mod").run('vendor')]])
vim.cmd([[command! -nargs=* GoModInit lua require"go.mod".run('init')]])
vim.cmd([[command! -nargs=* GoEnv lua require"go.env".load_env(<f-args>)]])
vim.cmd([[command! GoCodeLenAct lua require("go.codelens").run_action()]])
vim.cmd([[command! GoCodeAction lua require("go.codeaction").run_action()]])

@ -142,7 +142,29 @@ M.save_bks = function()
end
M.load_bks = function()
M.prepare()
local _, brkfile = require("go.project_setup").project_existed()
if vim.fn.filereadable(brkfile) == 0 then
return
end
local f = assert(loadfile(brkfile))
local brks = f()
for uri, brk in pairs(brks) do
local bufnr = vim.uri_to_bufnr(uri)
if not vim.api.nvim_buf_is_loaded(bufnr) then
vim.fn.bufload(bufnr)
end
for index, lnum in ipairs(brk) do
require("dap.breakpoints").set({}, bufnr, lnum.line)
end
end
end
M.clear_bks = function()
utils.load_plugin("nvim-dap", "dap")
require("dap.breakpoints").clear()
M.save_bks()
local _, brkfile = require("go.project_setup").project_existed()
if vim.fn.filereadable(brkfile) == 0 then
return

@ -14,19 +14,20 @@ function M.envfile(f)
end
function M.load_env(env, setToEnv)
setToEnv = setToEnv or true
env = env or M.envfile()
if vim.fn.filereadable(env) == 0 then
return false
end
local e = io.open(env, "r")
local lines = util.lines_from(e)
local lines = util.lines_from(env)
local envs = {}
for _, line in ipairs(lines) do
for k, v in string.gmatch(line, "(%w+)=(%w+)") do
for k, v in string.gmatch(line, "([%w_]+)=([%w%c%p%z]+)") do
envs[k] = v
end
end
log(envs)
if setToEnv then
for key, val in pairs(envs) do
vim.fn.setenv(key, val)
@ -36,6 +37,4 @@ function M.load_env(env, setToEnv)
return envs
end
M.load_project()
return M

Loading…
Cancel
Save