From 483b56f4a22747aa0f84fe8230a336ce92c871a4 Mon Sep 17 00:00:00 2001 From: Craig Rodrigues Date: Tue, 21 Dec 2021 19:34:10 -0800 Subject: [PATCH] Replace print() with vim.notify() (#64) --- lua/go.lua | 4 ++-- lua/go/alternate.lua | 6 +++--- lua/go/asyncmake.lua | 2 +- lua/go/coverage.lua | 8 ++++---- lua/go/dap.lua | 2 +- lua/go/doc.lua | 2 +- lua/go/format.lua | 8 ++++---- lua/go/godoc.lua | 2 +- lua/go/impl.lua | 2 +- lua/go/install.lua | 10 +++++----- lua/go/reftool.lua | 4 ++-- lua/go/rename.lua | 8 ++++---- lua/go/runner.lua | 2 +- lua/go/tags.lua | 12 ++++++------ lua/go/ts/nodes.lua | 4 ++-- lua/go/utils.lua | 4 ++-- 16 files changed, 40 insertions(+), 40 deletions(-) diff --git a/lua/go.lua b/lua/go.lua index aabba7c..3ca03be 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -48,7 +48,7 @@ end function go.setup(cfg) cfg = cfg or {} if cfg.max_len then - print("go.nvim max_len renamed to max_line_len") + vim.notify("go.nvim max_len renamed to max_line_len", vim.lsp.log_levels.WARN) end _GO_NVIM_CFG = vim.tbl_extend("force", _GO_NVIM_CFG, cfg) @@ -192,7 +192,7 @@ go.set_test_runner = function(runner) return end end - print("runner not supported " .. runner) + vim.notify("runner not supported " .. runner, vim.lsp.log_levels.ERROR) end go.dbg_complete = function(arglead, cmdline, cursorpos) diff --git a/lua/go/alternate.lua b/lua/go/alternate.lua index d23009e..14aeaf5 100644 --- a/lua/go/alternate.lua +++ b/lua/go/alternate.lua @@ -4,7 +4,7 @@ function M.switch(bang, cmd) local root = "" local alt_file = "" if #file <= 1 then - print("no buffer name") + vim.notify("no buffer name", vim.lsp.log_levels.ERROR) return end local s, e = string.find(file, "_test%.go$") @@ -16,10 +16,10 @@ function M.switch(bang, cmd) root = vim.fn.split(file, '.go')[1] alt_file = root .. '_test.go' else - print('not a go file') + vim.notify('not a go file', vim.lsp.log_levels.ERROR) end if not vim.fn.filereadable(alt_file) and not vim.fn.bufexists(alt_file) and not bang then - print("couldn't find " .. alt_file) + vim.notify("couldn't find " .. alt_file, vim.lsp.log_levels.ERROR) return elseif #cmd <= 1 then local ocmd = "e " .. alt_file diff --git a/lua/go/asyncmake.lua b/lua/go/asyncmake.lua index 9c00f83..c202827 100644 --- a/lua/go/asyncmake.lua +++ b/lua/go/asyncmake.lua @@ -118,7 +118,7 @@ function M.make(...) if type(cmd) == "table" then cmd = table.concat(cmd, " ") end - print(cmd .. " finished") + vim.notify(cmd .. " finished", vim.lsp.log_levels.WARN) end end diff --git a/lua/go/coverage.lua b/lua/go/coverage.lua index 80ccde2..1f5fd93 100644 --- a/lua/go/coverage.lua +++ b/lua/go/coverage.lua @@ -53,7 +53,7 @@ function M.define(bufnr, name, opts, redefine) sign_define_cache[bufnr] = {} end -- log(bufnr, name, opts, redefine) - -- print(bufnr, name, opts, redefine) + -- vim.notify(bufnr .. name .. opts .. redefine, vim.lsp.log_levels.DEBUG) if redefine then sign_define_cache[bufnr][name] = nil vim.fn.sign_undefine(name) @@ -271,12 +271,12 @@ M.run = function(...) vim.list_extend(lines, data) end, on_stderr = function(job_id, data, event) - print("go coverage finished with message: " .. vim.inspect(tag) .. "error: " .. vim.inspect(data) .. "job" - .. tostring(job_id) .. "ev" .. event) + vim.notify("go coverage finished with message: " .. vim.inspect(tag) .. "error: " .. vim.inspect(data) .. "job" + .. tostring(job_id) .. "ev" .. event, vim.lsp.log_levels.ERROR) end, on_exit = function(job_id, data, event) if event ~= "exit" then - print(job_id, event, vim.inspect(data)) + vim.notify(string.format("%s %s %s", job_id, event, vim.inspect(data)), vim.lsp.log_levels.ERROR) end log("test finished") coverage = M.read_cov(cov) diff --git a/lua/go/dap.lua b/lua/go/dap.lua index 2a5bd09..5b99c75 100644 --- a/lua/go/dap.lua +++ b/lua/go/dap.lua @@ -127,7 +127,7 @@ M.run = function(...) stdout:close() handle:close() if code ~= 0 then - print("Delve exited with exit code: ", code) + vim.notify(string.format("Delve exited with exit code: %d", code), vim.lsp.log_levels.WARN) end end) assert(handle, "Error running dlv: " .. tostring(pid_or_err)) diff --git a/lua/go/doc.lua b/lua/go/doc.lua index 9b841b9..e41454f 100644 --- a/lua/go/doc.lua +++ b/lua/go/doc.lua @@ -100,7 +100,7 @@ M.run = function(type, args) vim.lsp.util.open_floating_preview(data, 'go', config) -- local result = vim.fn.json_decode(data) -- if result.errors ~= nil or result.lines == nil or result["start"] == nil or result["start"] == 0 then - -- print("failed to get doc" .. vim.inspect(result)) + -- vim.notify("failed to get doc" .. vim.inspect(result), vim.lsp.log_levels.ERROR) -- end end }) diff --git a/lua/go/format.lua b/lua/go/format.lua index ddcf988..f848b25 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -18,9 +18,9 @@ local run = function(fmtargs, from_buffer, cmd) local args = vim.deepcopy(fmtargs) if not from_buffer then table.insert(args, api.nvim_buf_get_name(0)) - print('formatting buffer... ' .. api.nvim_buf_get_name(0) .. vim.inspect(args)) + vim.notify('formatting buffer... ' .. api.nvim_buf_get_name(0) .. vim.inspect(args), vim.lsp.log_levels.DEBUG) else - print('formatting... ' .. vim.inspect(args)) + vim.notify('formatting... ' .. vim.inspect(args), vim.lsp.log_levels.DEBUG) end local old_lines = api.nvim_buf_get_lines(0, 0, -1, true) @@ -38,11 +38,11 @@ local run = function(fmtargs, from_buffer, cmd) return end if not utils.check_same(old_lines, data) then - print("updating codes") + vim.notify("updating codes", vim.lsp.log_levels.DEBUG) api.nvim_buf_set_lines(0, 0, -1, false, data) api.nvim_command("write") else - print("already formatted") + vim.notify("already formatted", vim.lsp.log_levels.DEBUG) end -- log("stdout" .. vim.inspect(data)) old_lines = nil diff --git a/lua/go/godoc.lua b/lua/go/godoc.lua index e36cb26..a7c7220 100644 --- a/lua/go/godoc.lua +++ b/lua/go/godoc.lua @@ -7,7 +7,7 @@ function m.help_complete(arglead, cmdline, cursorpos) if #help_items < 1 then local doc = vim.fn.systemlist('go help') if vim.v.shell_error ~= 0 then - print('failed to run go help ', vim.v.shell_error) + vim.notify(string.format("failed to run go help %d", vim.v.shell_error), vim.lsp.log_levels.ERROR) return end diff --git a/lua/go/impl.lua b/lua/go/impl.lua index 4462528..90d7a8b 100644 --- a/lua/go/impl.lua +++ b/lua/go/impl.lua @@ -9,7 +9,7 @@ local run = function(...) local arg = {...} if #arg < 3 then - print("Usage: GoImpl f *File io.Reader") + vim.notify("Usage: GoImpl f *File io.Reader", vim.lsp.log_levels.WARN) end local rec1 = select(1, ...) diff --git a/lua/go/install.lua b/lua/go/install.lua index 074be8c..ee30cce 100644 --- a/lua/go/install.lua +++ b/lua/go/install.lua @@ -40,7 +40,7 @@ end local function go_install(pkg) local u = url[pkg] if u == nil then - print("command " .. pkg .. " not supported, please update install.lua, or manually install it") + vim.notify("command " .. pkg .. " not supported, please update install.lua, or manually install it", vim.lsp.log_levels.WARN) return end @@ -58,19 +58,19 @@ local function go_install(pkg) if #data > 1 then msg = msg .. data end - print(msg) + vim.notify(msg, vim.lsp.log_levels.DEBUG) end, }) end local function install(bin, verbose) if not is_installed(bin) then - print("installing " .. bin) + vim.notify("installing " .. bin, vim.lsp.log_levels.INFO) go_install(bin) else if verbose then - print(bin .. " already install, use GoUpdateBinary to update it") - end + vim.notify(bin .. " already install, use GoUpdateBinary to update it", vim.lsp.log_levels.INFO) + end end end diff --git a/lua/go/reftool.lua b/lua/go/reftool.lua index 610bec6..5859f5c 100644 --- a/lua/go/reftool.lua +++ b/lua/go/reftool.lua @@ -53,7 +53,7 @@ local function fill(cmd) end local json = fn.json_decode(str) if #json == 0 then - print('reftools', cmd, 'finished with no result') + vim.notify('reftools ' .. cmd .. ' finished with no result', vim.lsp.log_levels.DEBUG) end local result = json[1] @@ -89,7 +89,7 @@ function reftool.fixplurals() vim.fn.jobstart(setup, { on_stdout = function(jobid, data, event) vim.cmd(cdback) - -- print("fixplurals finished ") + -- vim.notify('fixplurals finished ', vim.lsp.log_levels.DEBUG) end }) end diff --git a/lua/go/rename.lua b/lua/go/rename.lua index d08945a..ad8618b 100644 --- a/lua/go/rename.lua +++ b/lua/go/rename.lua @@ -41,14 +41,14 @@ local run = function(to_identifier, ...) local setup = {gorename, "-offset", offset, "-to", to_identifier} - -- print("setup: ", vim.inspect(setup)) + -- vim.notify("setup: " .. vim.inspect(setup), vim.lsp.log_levels.DEBUG) -- -- local arg = {...} -- for i, v in ipairs(arg) do -- table.insert(setup, v) -- end -- - -- print(vim.inspect(setup)) + -- vim.notify(vim.inspect(setup), vim.lsp.log_levels.DEBUG) local j = vim.fn.jobstart(setup, { on_stdout = function(jobid, data, event) data = utils.handle_job_data(data) @@ -58,9 +58,9 @@ local run = function(to_identifier, ...) -- local result = vim.fn.json_decode(data) local result = vim.json.decode(data) if result.errors ~= nil or result.lines == nil or result["start"] == nil or result["start"] == 0 then - print("failed to rename" .. vim.inspect(result)) + vim.notify("failed to rename" .. vim.inspect(result), vim.lsp.log_levels.ERROR) end - print("renamed to " .. to_identifier) + vim.notify("renamed to " .. to_identifier, vim.lsp.log_levels.DEBUG) end }) end diff --git a/lua/go/runner.lua b/lua/go/runner.lua index ff73b3e..f94c8e1 100644 --- a/lua/go/runner.lua +++ b/lua/go/runner.lua @@ -90,7 +90,7 @@ local run = function(cmd, opts) uv.read_start(stderr, function(err, data) assert(not err, err) if data then - print("stderr chunk", stderr, data) + vim.notify(string.format("stderr chunk", stderr, data), vim.lsp.log_levels.DEBUG) end end) stdout:read_start(update_chunk) diff --git a/lua/go/tags.lua b/lua/go/tags.lua index 4540059..bed08e3 100644 --- a/lua/go/tags.lua +++ b/lua/go/tags.lua @@ -24,7 +24,7 @@ tags.modify = function(...) return end - -- print("parnode" .. vim.inspect(ns)) + -- vim.notify("parnode" .. vim.inspect(ns), vim.lsp.log_levels.DEBUG) local struct_name = ns.name local rs, re = ns.dim.s.r, ns.dim.e.r local setup = {gomodify, "-format", "json", "-file", fname, '-w'} @@ -49,7 +49,7 @@ tags.modify = function(...) if #arg == 1 and arg[1] ~= "-clear-tags" then table.insert(setup, "json") end - -- print(vim.inspect(setup)) + -- vim.notify(vim.inspect(setup), vim.lsp.log_levels.DEBUG) local j = vim.fn.jobstart(setup, { on_stdout = function(jobid, data, event) data = utils.handle_job_data(data) @@ -57,10 +57,10 @@ tags.modify = function(...) return end local tagged = vim.fn.json_decode(data) - -- print(vim.inspect(tagged)) - -- print(tagged["start"], tagged["end"], tagged.lines) + -- vim.notify(vim.inspect(tagged), vim.lsp.log_levels.DEBUG) + -- vim.notify(tagged["start"] .. " " .. tagged["end"] .. " " .. tagged.lines, vim.lsp.log_levels.ERROR) if tagged.errors ~= nil or tagged.lines == nil or tagged["start"] == nil or tagged["start"] == 0 then - print("failed to set tags" .. vim.inspect(tagged)) + vim.notify("failed to set tags" .. vim.inspect(tagged), vim.lsp.log_levels.ERROR) end for index, value in ipairs(tagged.lines) do tagged.lines[index] = utils.rtrim(value) @@ -68,7 +68,7 @@ tags.modify = function(...) -- trim tail spaces? vim.api.nvim_buf_set_lines(0, tagged["start"] - 1, tagged["start"] - 1 + #tagged.lines, false, tagged.lines) vim.cmd("write") - print("struct updated ") + vim.notify("struct updated ", vim.lsp.log_levels.DEBUG) end }) end diff --git a/lua/go/ts/nodes.lua b/lua/go/ts/nodes.lua index 38e1260..9766497 100644 --- a/lua/go/ts/nodes.lua +++ b/lua/go/ts/nodes.lua @@ -199,13 +199,13 @@ M.nodes_at_cursor = function(query, default, bufnr, row, col) end local nodes = M.get_all_nodes(query, ft, default, bufnr, row, col) if nodes == nil then - print("Unable to find any nodes. place your cursor on a go symbol and try again") + vim.notify("Unable to find any nodes. place your cursor on a go symbol and try again", vim.lsp.log_levels.WARN) return nil end nodes = M.sort_nodes(M.intersect_nodes(nodes, row, col)) if nodes == nil or #nodes == 0 then - print("Unable to find any nodes at pos. " .. tostring(row) .. ":" .. tostring(col)) + vim.notify("Unable to find any nodes at pos. " .. tostring(row) .. ":" .. tostring(col), vim.lsp.log_levels.WARN) return nil end diff --git a/lua/go/utils.lua b/lua/go/utils.lua index 2d8bcb9..34b00b8 100644 --- a/lua/go/utils.lua +++ b/lua/go/utils.lua @@ -128,7 +128,7 @@ util.log = function(...) if log_path ~= nil and #log_path > 3 then local f, err = io.open(log_path, "a+") if err then - print("failed to open log", log_path, err) + vim.notify("failed to open log" .. log_path .. err, vim.lsp.log_levels.ERROR) return end if not f then @@ -138,7 +138,7 @@ util.log = function(...) io.write(str .. "\n") io.close(f) else - print(str .. "\n") + vim.notify(str .. "\n", vim.lsp.log_levels.DEBUG) end end end