From eba7daeb16ca7d82c84078327a6555e030ad8727 Mon Sep 17 00:00:00 2001 From: Marco Mayer Date: Sat, 14 May 2022 12:52:12 +0200 Subject: [PATCH 01/10] fix gotests template parameters, better names(?), small formatting fixes, update README (#125) --- README.md | 42 +++++++++++++++++++++++------------------- lua/go.lua | 9 +++++++-- lua/go/gotests.lua | 14 +++++++------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index d5c4327..11c2e68 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ The plugin covers most features required for a gopher. - Test with ginkgo, richgo inside floaterm (to enable floaterm, guihua.lua has to be installed) - Go 1.18 support, configure your go to `go1.18` in config - GoFixPlural, FixStruct, FxiSwitch, Add comment, IfErr, ModTidy, GoGet ... Most of the tools are built on top of -treesitter AST or go AST. It is fast and accurate. + treesitter AST or go AST. It is fast and accurate. ## Installation @@ -85,9 +85,11 @@ require('go').setup() ![gotest](https://user-images.githubusercontent.com/1681295/143160335-b8046ffa-82cd-4d84-af3e-3b0dbb4c609e.png) Use: + ```vim :GoTermClose ``` + To close the floating term. ## refactor gorename @@ -198,7 +200,7 @@ first run of `GoFmt` may fail. It is recommended to run `GoInstallBinaries` to i | GoBuild | | | GoGenerate | | | GoRun | e.g. GoRun equal to `go run .`; or `GoRun ./cmd` equal to `go run ./cmd` | -| GoStop {job_id} | `stop the job started with GoRun` | +| GoStop {job_id} | `stop the job started with GoRun` | | GoTest | go test ./... | | GoTest -c | go test -c current_file_path | | GoTest -tags=yourtags | go test ./... -tags=yourtags | @@ -263,11 +265,11 @@ Modify struct tags by [`gomodifytags`](https://github.com/fatih/gomodifytags) an nvim-lsp support goimport by default. The plugin provided a new formatter, goline + gofumpt (stricter version of gofmt) -| command | Description | -| -------- | --------------------------- | -| GoFmt | goline + gofumpt | -| GoImport | goline + goimport + gofumpt | -| GoImport package_path | gopls add_import package | +| command | Description | +| --------------------- | --------------------------- | +| GoFmt | goline + gofumpt | +| GoImport | goline + goimport + gofumpt | +| GoImport package_path | gopls add_import package | ## GoImpl @@ -295,15 +297,15 @@ e.g: | command | Description | | ---------------- | ------------------------------------------------ | | GoDebug | start debug session | -| GoDebug -t | start debug session for go test file | -| GoDebug -R | restart debug session for go test file | -| GoDebug -n | start debug session for nearest go test function | -| GoDebug -f | same as GoDebug | -| GoDebug -p | debug package | -| GoDebug -a | attach to remote process | -| GoDebug -s | stop debug session and unmap debug keymap | -| GoBreakToggle | GoDebug -b | -| GoBreakCondition | conditional break | +| GoDebug -t | start debug session for go test file | +| GoDebug -R | restart debug session for go test file | +| GoDebug -n | start debug session for nearest go test function | +| GoDebug -f | same as GoDebug | +| GoDebug -p | debug package | +| GoDebug -a | attach to remote process | +| GoDebug -s | stop debug session and unmap debug keymap | +| GoBreakToggle | GoDebug -b | +| GoBreakCondition | conditional break | ## Switch between go and test file @@ -335,11 +337,12 @@ type GoLintComplaining struct{} ``` ## GoModeTidy + run `go mod tidy` and restart gopls ## GoModeVendor -run `go mod vendor` and restart gopls +run `go mod vendor` and restart gopls ## LSP @@ -349,6 +352,7 @@ The goal of go.nvim is more provide unique functions releated to gopls instead o The lsp config in go.nvim has a none default setup and contains some improvement and I would suggest you to use. ## LSP cmp support + The latest version enabled lsp snippets (and other setups) by default. In case you need flowing the setup from cmp README.md, please use flowing command: @@ -469,8 +473,8 @@ require('go').setup({ gofmt = 'gofumpt', --gofmt cmd, max_line_len = 120, -- max line length in goline format tag_transform = false, -- can be transform option("snakecase", "camelcase", etc) check gomodifytags for details and more options - test_template = '', -- g:go_nvim_tests_template check gotests for details - test_template_dir = '', -- default to nil if not set; g:go_nvim_tests_template_dir check gotests for details + gotests_template = "", -- sets gotests -template parameter (check gotests for details) + gotests_template_dir = "", -- sets gotests -template_dir parameter (check gotests for details) comment_placeholder = '' , -- comment_placeholder your cool placeholder e.g. ﳑ     icons = {breakpoint = '🧘', currentpos = '🏃'}, -- setup to `false` to disable icons setup verbose = false, -- output loginf in messages diff --git a/lua/go.lua b/lua/go.lua index d08547e..9e4ce3e 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -10,7 +10,10 @@ _GO_NVIM_CFG = { gofmt = "gofumpt", -- if set to gopls will use gopls format max_line_len = 120, tag_transform = false, - test_dir = "", + + gotests_template = "", -- sets gotests -template parameter (check gotests for details) + gotests_template_dir = "", -- sets gotests -template_dir parameter (check gotests for details) + comment_placeholder = "  ", icons = { breakpoint = "🧘", currentpos = "🏃" }, -- set to false to disable icons setup verbose = false, @@ -132,7 +135,9 @@ function go.setup(cfg) -- e.g. GoTestFile unit vim.cmd([[command! -nargs=* GoTestFile lua require('go.gotest').test_file()]]) - vim.cmd([[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoTestPkg lua require('go.gotest').test_package()]]) + vim.cmd( + [[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoTestPkg lua require('go.gotest').test_package()]] + ) vim.cmd([[command! -nargs=* GoAddTest lua require("go.gotests").fun_test()]]) vim.cmd([[command! -nargs=* GoAddExpTest lua require("go.gotests").exported_test()]]) vim.cmd([[command! -nargs=* GoAddAllTest lua require("go.gotests").all_test()]]) diff --git a/lua/go/gotests.lua b/lua/go/gotests.lua index 99546be..b37783a 100644 --- a/lua/go/gotests.lua +++ b/lua/go/gotests.lua @@ -2,13 +2,13 @@ -- https://github.com/cweill/gotests local ut = {} local gotests = "gotests" -local test_dir = _GO_NVIM_CFG.test_dir or "" -local test_template = vim.go_nvim_test_template or "" +local gotests_template = _GO_NVIM_CFG.gotests_template or "" +local gotests_template_dir = _GO_NVIM_CFG.gotests_template_dir or "" local utils = require("go.utils") local empty = utils.empty local run = function(setup) print(vim.inspect(setup)) - vim.fn.jobstart(setup, { + vim.fn.jobstart(setup, { stdout_buffered = true, on_stdout = function(_, data, _) print("unit tests generate " .. vim.inspect(data)) @@ -29,12 +29,12 @@ local new_gotests_args = function(parallel) if parallel then table.insert(args, "-parallel") end - if string.len(test_template) > 0 then + if string.len(gotests_template) > 0 then table.insert(args, "-template") - table.insert(args, test_template) - if string.len(test_dir) > 0 then + table.insert(args, gotests_template) + if string.len(gotests_template_dir) > 0 then table.insert(args, "-template_dir") - table.insert(args, test_dir) + table.insert(args, gotests_template_dir) end end return args From 0c8ffc2b8693364cd96b9f906a85961ab96b0be2 Mon Sep 17 00:00:00 2001 From: ray-x Date: Tue, 10 May 2022 17:59:48 +1000 Subject: [PATCH 02/10] add go boilerplate --- lua/go.lua | 1 + lua/go/boilerplate.lua | 17 +++++++++++++++++ lua/go/utils.lua | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 lua/go/boilerplate.lua diff --git a/lua/go.lua b/lua/go.lua index 9e4ce3e..ea1ebc2 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -38,6 +38,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 = "█", diff --git a/lua/go/boilerplate.lua b/lua/go/boilerplate.lua new file mode 100644 index 0000000..efdd46e --- /dev/null +++ b/lua/go/boilerplate.lua @@ -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} diff --git a/lua/go/utils.lua b/lua/go/utils.lua index ba96b55..cb773c7 100644 --- a/lua/go/utils.lua +++ b/lua/go/utils.lua @@ -495,4 +495,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 From 0dd08fddc51db07609cce288c2465469968bf03f Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 13 May 2022 19:27:02 +1000 Subject: [PATCH 03/10] add gonvim project file parser --- .gonvim | 10 +++++ README.md | 24 ++++++++++- lua/go.lua | 13 ++++++ lua/go/env.lua | 41 ++++++++++++++++++ lua/go/lsp.lua | 8 +++- lua/go/project_setup.lua | 91 ++++++++++++++++++++++++++++++++++++++++ lua/go/utils.lua | 38 +++++++++++++++++ 7 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 .gonvim create mode 100644 lua/go/env.lua create mode 100644 lua/go/project_setup.lua diff --git a/.gonvim b/.gonvim new file mode 100644 index 0000000..bf12230 --- /dev/null +++ b/.gonvim @@ -0,0 +1,10 @@ +vim.g.null_ls_disable = true + +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 + null_ls_document_formatting_disable = true +} diff --git a/README.md b/README.md index 11c2e68..ecd004b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A modern go neovim plugin based on treesitter, nvim-lsp and dap debugger. It is written in Lua and async as much as possible. PR & Suggestions welcome. The plugin covers most features required for a gopher. - +- Perproject setup. Allows you setup plugin behavior per project based on project files(launch.json, .gonvim) - Async jobs with libuv - Syntax highlight & Texobject: Native treesitter support is faster and more accurate. All you need is a theme support treesitter, try [aurora](https://github.com/ray-x/aurora). Also, there are quite a few listed in [awesome-neovim](https://github.com/rockerBOO/awesome-neovim) @@ -69,6 +69,28 @@ To startup/setup the plugin ```lua 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 +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 +vim.g.null_ls_disable = true + +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 + null_ls_document_formatting_disable = 'golines' +} +``` +This will override your global `go.nvim` setup + + ## Screenshots diff --git a/lua/go.lua b/lua/go.lua index ea1ebc2..98d70a6 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -26,11 +26,17 @@ _GO_NVIM_CFG = { -- when lsp_cfg is true -- if lsp_on_attach is a function: use this function as on_attach function for gopls, -- when lsp_cfg is true + lsp_on_client_start = nil, -- it is a function with same signature as on_attach, will be called at end of + -- on_attach and allows you override some setup lsp_format_on_save = 1, lsp_document_formatting = true, -- set to true: use gopls to format -- false if you want to use other formatter tool(e.g. efm, nulls) + null_ls_document_formatting_disable = false, -- true: disable null-ls formatting + -- if enable gopls to format the code and you also instlled and enabled null-ls, you may + -- want to disable null-ls by setting this to true + -- it can be a nulls source name e.g. `golines` or a nulls query table lsp_keymaps = true, -- true: use default keymaps defined in go/lsp.lua lsp_codelens = true, lsp_diag_hdlr = true, -- hook lsp diag handler @@ -56,6 +62,9 @@ _GO_NVIM_CFG = { test_runner = "go", -- richgo, go test, richgo, dlv, ginkgo verbose_tests = true, -- set to add verbose flag to tests run_in_floaterm = false, -- set to true to run in float window. + + username = "", + useremail = "", } local dap_config = function() @@ -202,10 +211,14 @@ function go.setup(cfg) vim.cmd([[command! GoDbgStop lua require'go.dap'.stop()]]) end + require("go.project_setup").load_project() + if _GO_NVIM_CFG.run_in_floaterm then vim.cmd([[command! -nargs=* GoTermClose lua require("go.term").close()]]) end + require("go.utils").set_nulls() + if _GO_NVIM_CFG.lsp_cfg then require("go.lsp").setup() if _GO_NVIM_CFG.lsp_diag_hdlr then diff --git a/lua/go/env.lua b/lua/go/env.lua new file mode 100644 index 0000000..54b64bb --- /dev/null +++ b/lua/go/env.lua @@ -0,0 +1,41 @@ +-- env fileread +local util = require("go.utils") +local log = util.log +local M = {} +local sep = require("go.utils").sep() + +function M.envfile(f) + local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vim.fn.getcwd() + local goenv = workfolder .. sep .. (f or ".env") + + if vim.fn.filereadable(goenv) == 1 then + return goenv + end +end + +function M.load_env(env, setToEnv) + 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 envs = {} + for _, line in ipairs(lines) do + for k, v in string.gmatch(line, "(%w+)=(%w+)") do + envs[k] = v + end + end + + if setToEnv then + for key, val in pairs(envs) do + vim.fn.setenv(key, val) + end + end + + return envs +end + +M.load_project() + +return M diff --git a/lua/go/lsp.lua b/lua/go/lsp.lua index 94884c9..f786f82 100644 --- a/lua/go/lsp.lua +++ b/lua/go/lsp.lua @@ -78,7 +78,7 @@ end local M = {} function M.client() - local clients = vim.lsp.get_active_clients() + local clients = vim.lsp.get_active_clients() for _, cl in pairs(clients) do if cl.name == "gopls" then return cl @@ -98,6 +98,12 @@ function M.config() if type(_GO_NVIM_CFG.lsp_on_attach) == "function" then gopls.on_attach = _GO_NVIM_CFG.lsp_on_attach end + if _GO_NVIM_CFG.lsp_on_client_start and type( type(_GO_NVIM_CFG.lsp_on_attach)) == "function" then + gopls.on_attach = function(client, bufnr) + gopls.on_attach(client, bufnr) + _GO_NVIM_CFG.lsp_on_client_start(client, bufnr) + end + end if _GO_NVIM_CFG.gopls_cmd then gopls.cmd = _GO_NVIM_CFG.gopls_cmd diff --git a/lua/go/project_setup.lua b/lua/go/project_setup.lua new file mode 100644 index 0000000..41625c9 --- /dev/null +++ b/lua/go/project_setup.lua @@ -0,0 +1,91 @@ +-- 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 = "", + comment_placeholder = "  ", + icons = { breakpoint = "🧘", currentpos = "🏃" }, -- set to false to disable icons setup + verbose = false, + log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log", + lsp_cfg = false, -- false: do nothing + -- true: apply non-default gopls setup defined in go/lsp.lua + -- if lsp_cfg is a table, merge table with with non-default gopls setup in go/lsp.lua, e.g. + lsp_gofumpt = false, -- true: set default gofmt in gopls format to gofumpt + lsp_on_attach = nil, -- nil: use on_attach function defined in go/lsp.lua for gopls, + -- when lsp_cfg is true + -- if lsp_on_attach is a function: use this function as on_attach function for gopls, + -- when lsp_cfg is true + lsp_format_on_save = 1, + lsp_document_formatting = true, + -- set to true: use gopls to format + -- false if you want to use other formatter tool(e.g. efm, nulls) + + lsp_keymaps = true, -- true: use default keymaps defined in go/lsp.lua + lsp_codelens = true, + lsp_diag_hdlr = true, -- hook lsp diag handler + -- virtual text setup + 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 = "█", + gocoverage_sign_priority = 5, + launch_json = nil, -- the launch.json file path, default to .vscode/launch.json + -- launch_json = vim.fn.getcwd() .. "/.vscode/launch.json", + dap_debug = true, + dap_debug_gui = true, + dap_debug_keymap = true, -- true: use keymap for debugger defined in go/dap.lua + -- false: do not use keymap in go/dap.lua. you must define your own. + dap_vt = true, -- false, true and 'all frames' + dap_port = 38697, -- can be set to a number or `-1` so go.nvim will pickup a random port + build_tags = "", --- you can provide extra build tags for tests or debugger + textobjects = true, -- treesitter binding for text objects + test_runner = "go", -- richgo, go test, richgo, dlv, ginkgo + verbose_tests = true, -- set to add verbose flag to tests + run_in_floaterm = false, -- set to true to run in float window. +} + +]] + +-- if the file existed, load it into config + +local util = require("go.utils") +local log = util.log +local M = {} +local sep = require("go.utils").sep() + +function M.setup_project() + local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vim.fn.getcwd() + local gocfg = workfolder .. sep .. ".gonvim" + + if vim.fn.filereadable(gocfg) == 1 then + return gocfg + else + local f = io.open(gocfg, "w") + f:write("return {}") + f:close() + end +end + +function M.load_project() + local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vim.fn.getcwd() + local gocfg = workfolder .. sep .. ".gonvim" + if vim.fn.filereadable(gocfg) == 1 then + local f = assert(loadfile(gocfg)) + _GO_NVIM_CFG = vim.tbl_deep_extend("force", _GO_NVIM_CFG, f()) + else + return false + end +end + +M.load_project() + +return M diff --git a/lua/go/utils.lua b/lua/go/utils.lua index cb773c7..4d15e1b 100644 --- a/lua/go/utils.lua +++ b/lua/go/utils.lua @@ -513,4 +513,42 @@ util.deletedir = function(dir) util.log("remove dir", dir) end +function util.file_exists(file) + local f = io.open(file, "rb") + if f then f:close() end + return f ~= nil +end + +-- get all lines from a file, returns an empty +-- list/table if the file does not exist +function util.lines_from(file) + if not util.file_exists(file) then return {} end + local lines = {} + for line in io.lines(file) do + lines[#lines + 1] = line + end + return lines +end + +function util.set_env(key, val) +end + +function util.list_directory() + local fn = vim.fn + local dirs = fn.map(fn.glob(fn.fnameescape('./')..'/{,.}*/', 1, 1), 'fnamemodify(v:val, ":h:t")') +end + +function util.set_nulls() + if _GO_NVIM_CFG.null_ls_document_formatting_disable then + local query = {} + if type( _GO_NVIM_CFG.null_ls_document_formatting_disable) ~= 'boolean' + then + query = _GO_NVIM_CFG.null_ls_document_formatting_disable + end + local ok, nulls = pcall(require, "null-ls") + if ok then + nulls.disable(query) + end + end +end return util From e54ed67325d6b549981dafc2e88e41b94a474d0e Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 13 May 2022 20:13:59 +1000 Subject: [PATCH 04/10] remove fixplurals gotool and using treesitter --- lua/go/install.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/go/install.lua b/lua/go/install.lua index 948d4ec..d09854e 100644 --- a/lua/go/install.lua +++ b/lua/go/install.lua @@ -14,7 +14,6 @@ local url = { iferr = "github.com/koron/iferr", impl = "github.com/josharian/impl", fillstruct = "github.com/davidrjenni/reftools/cmd/fillstruct", - fixplurals = "github.com/davidrjenni/reftools/cmd/fixplurals", fillswitch = "github.com/davidrjenni/reftools/cmd/fillswitch", dlv = "github.com/go-delve/delve/cmd/dlv", ginkgo = "github.com/onsi/ginkgo/ginkgo", From f3e1da9968bb710c972b72f7be72f7e6b72a5d8e Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 14 May 2022 01:07:44 +1000 Subject: [PATCH 05/10] save and load breaks --- lua/go.lua | 3 ++ lua/go/dap.lua | 37 ++++++++++++++++++++++++ lua/go/project_setup.lua | 62 +++++++++++++--------------------------- 3 files changed, 60 insertions(+), 42 deletions(-) diff --git a/lua/go.lua b/lua/go.lua index 98d70a6..34681cd 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -198,6 +198,9 @@ function go.setup(cfg) vim.cmd( [[command! -nargs=* -complete=custom,v:lua.package.loaded.go.dbg_complete GoDebug lua require"go.dap".run()]] ) + vim.cmd([[command! GoBreakSave lua require"go.dap".save_brks()]]) + vim.cmd([[command! GoBreakLoad lua require"go.dap".load_brks()]]) + vim.cmd([[command! GoDebugConfig lua require"go.launch".config()]]) vim.cmd([[command! GoBreakToggle lua require"go.dap".breakpt()]]) vim.cmd([[command! BreakCondition lua require"dap".set_breakpoint(vim.fn.input("Breakpoint condition: "))]]) diff --git a/lua/go/dap.lua b/lua/go/dap.lua index e7d817a..3927f89 100644 --- a/lua/go/dap.lua +++ b/lua/go/dap.lua @@ -123,6 +123,43 @@ M.breakpt = function() require("dap").toggle_breakpoint() end +M.save_bks = function() + local bks = require("dap.breakpoints").get() + local all_bks = {} + if bks and next(bks) then + local cfg, fld = require("go.project_setup").setup_project() + for bufnr, bk in pairs(bks) do + local uri = vim.uri_from_bufnr(bufnr) + all_bks[uri] = bk + end + local bkfile = fld .. utils.sep() .. "breakpoints.lua" + local writeStr = "return " .. vim.inspect(all_bks) + + local writeLst = vim.split(writeStr, "\n") + + vim.fn.writefile(writeLst, bkfile, "b") + end +end + +M.load_bks = function() + utils.load_plugin("nvim-dap", "dap") + 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 + local stdout, stderr, handle M.run = function(...) local args = { ... } diff --git a/lua/go/project_setup.lua b/lua/go/project_setup.lua index 41625c9..1ad97ed 100644 --- a/lua/go/project_setup.lua +++ b/lua/go/project_setup.lua @@ -9,48 +9,12 @@ return { max_line_len = 120, tag_transform = false, test_dir = "", - comment_placeholder = "  ", - icons = { breakpoint = "🧘", currentpos = "🏃" }, -- set to false to disable icons setup - verbose = false, - log_path = vim.fn.expand("$HOME") .. "/tmp/gonvim.log", - lsp_cfg = false, -- false: do nothing - -- true: apply non-default gopls setup defined in go/lsp.lua - -- if lsp_cfg is a table, merge table with with non-default gopls setup in go/lsp.lua, e.g. - lsp_gofumpt = false, -- true: set default gofmt in gopls format to gofumpt - lsp_on_attach = nil, -- nil: use on_attach function defined in go/lsp.lua for gopls, - -- when lsp_cfg is true - -- if lsp_on_attach is a function: use this function as on_attach function for gopls, - -- when lsp_cfg is true - lsp_format_on_save = 1, - lsp_document_formatting = true, - -- set to true: use gopls to format - -- false if you want to use other formatter tool(e.g. efm, nulls) - - lsp_keymaps = true, -- true: use default keymaps defined in go/lsp.lua - lsp_codelens = true, - lsp_diag_hdlr = true, -- hook lsp diag handler - -- virtual text setup - 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 = "█", gocoverage_sign_priority = 5, launch_json = nil, -- the launch.json file path, default to .vscode/launch.json -- launch_json = vim.fn.getcwd() .. "/.vscode/launch.json", - dap_debug = true, - dap_debug_gui = true, - dap_debug_keymap = true, -- true: use keymap for debugger defined in go/dap.lua - -- false: do not use keymap in go/dap.lua. you must define your own. - dap_vt = true, -- false, true and 'all frames' - dap_port = 38697, -- can be set to a number or `-1` so go.nvim will pickup a random port + build_tags = "", --- you can provide extra build tags for tests or debugger - textobjects = true, -- treesitter binding for text objects - test_runner = "go", -- richgo, go test, richgo, dlv, ginkgo - verbose_tests = true, -- set to add verbose flag to tests - run_in_floaterm = false, -- set to true to run in float window. + } ]] @@ -62,17 +26,31 @@ 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 vim.fn.getcwd() + local gocfgfd = workfolder .. sep .. ".gonvim" + local gocfgbrks = gocfgfd .. sep .. "breakpoints.lua" + local gocfg = gocfgfd .. sep .. "init.lua" + if vim.fn.filereadable(gocfg) == 1 or vim.fn.filereadable(gocfgbrks) == 1 then + log("projects existed", gocfg, gocfgbrks) + return gocfg, gocfgbrks + end +end + function M.setup_project() local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vim.fn.getcwd() - local gocfg = workfolder .. sep .. ".gonvim" + local gocfgfd = workfolder .. sep .. ".gonvim" + local gocfg = gocfgfd .. sep .. "init.lua" - if vim.fn.filereadable(gocfg) == 1 then - return gocfg - else + if vim.fn.isdirectory(gocfgfd) == 0 then + vim.fn.mkdir(gocfgfd) + end + if vim.fn.filereadable(gocfg) == 0 then local f = io.open(gocfg, "w") f:write("return {}") f:close() end + return gocfg, gocfgfd end function M.load_project() From de1306a986ac4018e75cf53f8eea3089257c5f6b Mon Sep 17 00:00:00 2001 From: ray-x Date: Sat, 14 May 2022 21:24:19 +1000 Subject: [PATCH 06/10] goenv and load breakpoints --- README.md | 4 ++-- lua/go.lua | 2 ++ lua/go/dap.lua | 22 ++++++++++++++++++++++ lua/go/env.lua | 9 ++++----- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ecd004b..dac2321 100644 --- a/README.md +++ b/README.md @@ -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 { diff --git a/lua/go.lua b/lua/go.lua index 34681cd..442d0a8 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -152,6 +152,8 @@ function go.setup(cfg) vim.cmd([[command! -nargs=* GoAddExpTest lua require("go.gotests").exported_test()]]) vim.cmd([[command! -nargs=* GoAddAllTest lua require("go.gotests").all_test()]]) 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()]]) vim.cmd([[command! GoCodeLenAct lua require("go.codelens").run_action()]]) vim.cmd([[command! GoCodeAction lua require("go.codeaction").run_action()]]) diff --git a/lua/go/dap.lua b/lua/go/dap.lua index 3927f89..f4fdddb 100644 --- a/lua/go/dap.lua +++ b/lua/go/dap.lua @@ -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 diff --git a/lua/go/env.lua b/lua/go/env.lua index 54b64bb..9d681ee 100644 --- a/lua/go/env.lua +++ b/lua/go/env.lua @@ -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 From f187f106782aad296dd0cf6d21f9ed20413e87fb Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 15 May 2022 14:09:07 +1000 Subject: [PATCH 07/10] Update GoModxxx cmds --- README.md | 32 ++++++++++++++++++----- doc/go.txt | 11 +++++++- lua/go.lua | 3 ++- lua/go/dap.lua | 6 ++--- lua/go/gopls.lua | 4 +++ lua/go/mod.lua | 3 ++- lua/go/{project_setup.lua => project.lua} | 2 +- 7 files changed, 47 insertions(+), 14 deletions(-) rename lua/go/{project_setup.lua => project.lua} (98%) diff --git a/README.md b/README.md index dac2321..7ff9ac6 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ first run of `GoFmt` may fail. It is recommended to run `GoInstallBinaries` to i | command | Description | | --------------------------------------------- | ------------------------------------------------------------------------ | -| GoMake | make | +| GoMake | async make, use with other commands | | GoBuild | | | GoGenerate | | | GoRun | e.g. GoRun equal to `go run .`; or `GoRun ./cmd` equal to `go run ./cmd` | @@ -261,8 +261,18 @@ Support table based unit test auto generate, parse current function/method name | GoAddExpTest [-parallel] | Add tests for exported funcs | | GoAddAllTest [-parallel] | Add tests for all funcs | +GoTestXXX Arugments + +| arguments | Description | +| ------------------------ | ------------------------------------------------------- | +| -v | verbose mode | +| -c | compile | +| -t | tags | +| -b | bench | +| -F | floaterm mode | + Note: For GoTestXXX -You can add avaliable arguments e.g. `GoTest -tags=integration ./internal/web -bench=. -count=1 -` +You can add available arguments e.g. `GoTest -tags=integration ./internal/web -bench=. -count=1 -` ## GoDoc @@ -357,14 +367,19 @@ The code will be: // GoLintComplaining struct no more complaint ;P type GoLintComplaining struct{} ``` +| command | Description | +| ---------------- | ------------------------------------------------------- | +| GoCmt | Add comment| -## GoModeTidy +## GoModTidy -run `go mod tidy` and restart gopls - -## GoModeVendor +| command | Description | +| ---------------- | ------------------------------------------------------- | +| GoModInit | run `go mod init` and restart gopls | +| GoModTidy | run `go mod tidy` and restart gopls | +| GoModVendor | run `go mod vendor` and restart gopls | -run `go mod vendor` and restart gopls +run `go mod tidy` and restart gopls ## LSP @@ -450,6 +465,9 @@ Here is a sample [launch.json](https://github.com/ray-x/go.nvim/blob/master/play | GoDebug | Start debugger, to debug test, run `GoDebug test`, to add addition args run `GoDebug arg1 arg2` | | GoDebugConfig | Open launch.json file | | GoBreakToggle | toggle break point | +| GoBreakSave | save all breakpoints to project file point | +| GoBreakLoad | load all breakpoints from project file point | +| GoBreakToggle | toggle break point | | BreakCondition | conditional break point | | ReplRun | dap repl run_last | | ReplToggle | dap repl toggle | diff --git a/doc/go.txt b/doc/go.txt index 5f04e9f..6b59b34 100644 --- a/doc/go.txt +++ b/doc/go.txt @@ -199,7 +199,7 @@ COMMANDS *go-nvim-commands* current line and use it as url if valid :GoLint *:GoLint* - Run Golint + Run golangci-lint :GoRename *:GoRename* @@ -259,6 +259,15 @@ COMMANDS *go-nvim-commands* :GoBreakToggle *:GoBreakToggle* Debuger breakpoint toggle +:GoBreakSave *:GoBreakSave* + Debuger breakpoint save to project file + +:GoBreakLoad *:GoBreakLoad* + Debuger breakpoint load from project file + +:GoEnv {envfile} {load} *:GoEnv* + Load envfile and set environment variable + :GoAlt *:GoAlt* Open alternative file (test/go), Also GoAltS/GoAltV diff --git a/lua/go.lua b/lua/go.lua index 442d0a8..9e4bd39 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -140,6 +140,7 @@ function go.setup(cfg) [[command! GoLint :setl makeprg=golangci-lint\ run\ --print-issued-lines=false\ --exclude-use-default=false | :GoMake]] ) + vim.cmd([[command! -nargs=* GoProject lua require('go.project').setup()]]) -- e.g. GoTestFunc unit vim.cmd([[command! -nargs=* GoTestFunc lua require('go.gotest').test_fun()]]) @@ -216,7 +217,7 @@ function go.setup(cfg) vim.cmd([[command! GoDbgStop lua require'go.dap'.stop()]]) end - require("go.project_setup").load_project() + require("go.project").load_project() if _GO_NVIM_CFG.run_in_floaterm then vim.cmd([[command! -nargs=* GoTermClose lua require("go.term").close()]]) diff --git a/lua/go/dap.lua b/lua/go/dap.lua index f4fdddb..745ca73 100644 --- a/lua/go/dap.lua +++ b/lua/go/dap.lua @@ -127,7 +127,7 @@ M.save_bks = function() local bks = require("dap.breakpoints").get() local all_bks = {} if bks and next(bks) then - local cfg, fld = require("go.project_setup").setup_project() + local cfg, fld = require("go.project").setup() for bufnr, bk in pairs(bks) do local uri = vim.uri_from_bufnr(bufnr) all_bks[uri] = bk @@ -143,7 +143,7 @@ end M.load_bks = function() M.prepare() - local _, brkfile = require("go.project_setup").project_existed() + local _, brkfile = require("go.project").project_existed() if vim.fn.filereadable(brkfile) == 0 then return end @@ -165,7 +165,7 @@ M.clear_bks = function() require("dap.breakpoints").clear() M.save_bks() - local _, brkfile = require("go.project_setup").project_existed() + local _, brkfile = require("go.project").project_existed() if vim.fn.filereadable(brkfile) == 0 then return end diff --git a/lua/go/gopls.lua b/lua/go/gopls.lua index b2b2c5f..f777581 100644 --- a/lua/go/gopls.lua +++ b/lua/go/gopls.lua @@ -102,6 +102,10 @@ M.list_pkgs = function() return pkgs end +M.tidy = function() + cmds.tidy() +end + -- check_for_upgrades({Modules = {'package'}}) function M.version() local cache_dir = vim.fn.stdpath("cache") diff --git a/lua/go/mod.lua b/lua/go/mod.lua index faae613..3aa0aef 100644 --- a/lua/go/mod.lua +++ b/lua/go/mod.lua @@ -6,7 +6,8 @@ local M = {} function M.run(...) local args = { ... } local cmd = { "go", "mod" } - vim.list_extend(cmd, args) + cmd = vim.list_extend(cmd, args) + utils.log(cmd) local opts = { after = function() vim.schedule(function() diff --git a/lua/go/project_setup.lua b/lua/go/project.lua similarity index 98% rename from lua/go/project_setup.lua rename to lua/go/project.lua index 1ad97ed..7343f11 100644 --- a/lua/go/project_setup.lua +++ b/lua/go/project.lua @@ -37,7 +37,7 @@ function M.project_existed() end end -function M.setup_project() +function M.setup() local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vim.fn.getcwd() local gocfgfd = workfolder .. sep .. ".gonvim" local gocfg = gocfgfd .. sep .. "init.lua" From e3551f08bc5f7643dd3ceb0a502f92e5456d054a Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 15 May 2022 14:19:05 +1000 Subject: [PATCH 08/10] add logs --- lua/go/project.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/go/project.lua b/lua/go/project.lua index 7343f11..0fbff53 100644 --- a/lua/go/project.lua +++ b/lua/go/project.lua @@ -55,9 +55,10 @@ end function M.load_project() local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vim.fn.getcwd() - local gocfg = workfolder .. sep .. ".gonvim" + local gocfg = workfolder .. sep .. ".gonvim" .. sep .. "init.lua" if vim.fn.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 From 1449635984351fd29f051f6c1af63f509f326ef4 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 15 May 2022 14:38:55 +1000 Subject: [PATCH 09/10] launch.json create folder if not existed --- lua/go/launch.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lua/go/launch.lua b/lua/go/launch.lua index 1049572..9ce7af1 100644 --- a/lua/go/launch.lua +++ b/lua/go/launch.lua @@ -75,8 +75,15 @@ end function M.config() local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vim.fn.getcwd() local launch_json = _GO_NVIM_CFG.launch_json or (workfolder .. sep .. ".vscode" .. sep .. "launch.json") + local launch_dir = string.match(launch_json, ".*" .. sep) local cmd = "e " .. launch_json + + log(launch_json, launch_dir) + if vim.fn.isdirectory(launch_dir) == 0 then + vim.fn.mkdir(launch_dir) + end + if vim.fn.filereadable(launch_json) == 1 then return vim.cmd(cmd) end From 669ad39639c73ea0b1e03f6f44d956a61ebf8fb3 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 15 May 2022 21:43:59 +1000 Subject: [PATCH 10/10] update launch.json and readme.md for the new commands --- README.md | 9 ++++++--- doc/go.txt | 2 ++ lua/go.lua | 1 + lua/go/dap.lua | 9 +++++++-- lua/go/launch.lua | 50 +++++++++++++++++++++++++++++++++++------------ 5 files changed, 53 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7ff9ac6..5e91859 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ require('go').setup() `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 +setup. You can check the youtube video [here](https://www.youtube.com/watch?v=XrxSUp0E9Qw) on how to use this feature. ```lua -- .gonvim/init.lua project config @@ -85,7 +85,7 @@ return { fillstruct = "gopls", gofmt = "gofumpt", -- if set to gopls will use gopls format max_line_len = 120 - null_ls_document_formatting_disable = 'golines' + null_ls_document_formatting_disable = true } ``` This will override your global `go.nvim` setup @@ -167,6 +167,9 @@ Note: auto fill struct also supported by gopls lsp-action | GoIfErr | Add if err | | GoFixPlurals | change func foo(b int, a int, r int) -> func foo(b, a, r int) | +![GoFixPlurals Youtube video](https://www.youtube.com/watch?v=IP67Gkb5-qA) + + ```go package foo @@ -684,7 +687,7 @@ local install_root_dir = path.concat {vim.fn.stdpath 'data', 'lsp_servers'} require('go').setup({ gopls_cmd = {install_root_dir .. '/go/gopls'}, - filstruct = 'gopls', + fillstruct = 'gopls', dap_debug = true, dap_debug_gui = true }) diff --git a/doc/go.txt b/doc/go.txt index 6b59b34..c1f3dfc 100644 --- a/doc/go.txt +++ b/doc/go.txt @@ -255,6 +255,8 @@ COMMANDS *go-nvim-commands* :GoDebugConfig *:GoDebugConfig* Open launch.json +:GoCreateLaunch *:GoCreateLaunch* + Create alaunch.json :GoBreakToggle *:GoBreakToggle* Debuger breakpoint toggle diff --git a/lua/go.lua b/lua/go.lua index 9e4bd39..efd80d2 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -201,6 +201,7 @@ function go.setup(cfg) vim.cmd( [[command! -nargs=* -complete=custom,v:lua.package.loaded.go.dbg_complete GoDebug lua require"go.dap".run()]] ) + vim.cmd([[command! GoCreateLaunch lua require"go.launch".config()]]) vim.cmd([[command! GoBreakSave lua require"go.dap".save_brks()]]) vim.cmd([[command! GoBreakLoad lua require"go.dap".load_brks()]]) diff --git a/lua/go/dap.lua b/lua/go/dap.lua index 745ca73..bdb0c8a 100644 --- a/lua/go/dap.lua +++ b/lua/go/dap.lua @@ -123,13 +123,18 @@ M.breakpt = function() require("dap").toggle_breakpoint() end -M.save_bks = function() +M.save_brks = function() + M.prepare() local bks = require("dap.breakpoints").get() local all_bks = {} if bks and next(bks) then local cfg, fld = require("go.project").setup() for bufnr, bk in pairs(bks) do local uri = vim.uri_from_bufnr(bufnr) + local _bk ={} + for _, value in pairs(bk) do + table.insert(_bk, {line = value.line}) + end all_bks[uri] = bk end local bkfile = fld .. utils.sep() .. "breakpoints.lua" @@ -141,7 +146,7 @@ M.save_bks = function() end end -M.load_bks = function() +M.load_brks = function() M.prepare() local _, brkfile = require("go.project").project_existed() if vim.fn.filereadable(brkfile) == 0 then diff --git a/lua/go/launch.lua b/lua/go/launch.lua index 9ce7af1..bfb8537 100644 --- a/lua/go/launch.lua +++ b/lua/go/launch.lua @@ -3,39 +3,50 @@ local launch_json_content = [[ "version": "0.2.0", "configurations": [ { - "name": "Launch main", + "name": "Launch package", "type": "go", "request": "launch", - "mode": "exec", + "mode": "auto", "remotePath": "", "port": 38697, "host": "127.0.0.1", - "program": "${workspaceFolder}/main.go", + "program": "${workspaceFolder}", "env": { }, "args": [], - "cwd": ${workspaceFolder}", - "envFile", "${workspaceFolder}/.env" + "cwd": "${workspaceFolder}", + "envFile": "${workspaceFolder}/.env", "buildFlags":"" }, { - "name": "debug main", + "name": "Debug current package", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 38697, "host": "127.0.0.1", - "program": "${workspaceFolder}/main.go", + "program": "${fileDirname}", "env": { }, "args": [], - "cwd": ${workspaceFolder}", - "envFile", "${workspaceFolder}/.env" + "cwd": "${workspaceFolder}", + "envFile": "${workspaceFolder}/.env", "buildFlags":"" }, { - "name": "debug main", + "name": "Launch test function", + "type": "go", + "request": "launch", + "mode": "test", + "program": "${workspaceFolder}", + "args": [ + "-test.run", + "MyTestFunction" + ] + }, + { + "name": "Attach main", "type": "go", "request": "attach", "mode": "debug", @@ -46,10 +57,24 @@ local launch_json_content = [[ "env": { }, "args": [], - "cwd": ${workspaceFolder}", + "cwd": "${workspaceFolder}", "processId":"", - "envFile", "${workspaceFolder}/.env" + "envFile": "${workspaceFolder}/.env", "buildFlags":"" + }, + { + "name": "Attach to Process", + "type": "go", + "request": "attach", + "mode": "local", + "processId": 0 + }, + { + "name": "Launch file", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${file}" } ] } @@ -79,7 +104,6 @@ function M.config() local cmd = "e " .. launch_json - log(launch_json, launch_dir) if vim.fn.isdirectory(launch_dir) == 0 then vim.fn.mkdir(launch_dir) end