vis-lint

vis plugin for linting code
git clone anongit@rnpnr.xyz:vis-lint.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 38cdd791e31c41040f5db020e4e5f3f07859da0b
Parent: 202d3efba68441fd119a6897f4d7a712aa2ac4eb
Author: Hugo O. Rivera
Date:   Sun, 14 May 2023 10:34:56 -0600

Cleaner and quicker vis:message output, and run all linters even if one fails

- Less newlines
- No more `$ [cmd]...`. Use description that indicates file is piped to the given command.
  since we are now piping to the commands, not running shell commands.
- Show output as soon as it's ready instead of waiting on all linters/fixers.
- Fix bug if vis.win.syntax is undefined
- Print which file is being worked on
- Print header before most of our plugin's output: such as "--- linters: " ...
- Print message when done
- Use fixer status code to see if the fixer failed and exit early
  Do not use stderr, since some fixers print to stderr even on success

Diffstat:
Minit.lua | 38++++++++++++++++++++++++++------------
1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/init.lua b/init.lua @@ -25,33 +25,47 @@ fixers["rust"] = {"rustfmt"} run_actions_on_file = function(action, actions, file, modify) local cmds = actions[vis.win.syntax] if cmds == nil or #cmds == 0 then - vis:info(action .. " not defined for " .. vis.win.syntax) + vis:info(action + .. " not defined for vis.win.syntax=" + .. (vis.win.syntax or "undefined") + .. " in file " + .. (file.name or "unnamed file")) return false end + -- Print this for clarity and separate different outputs in the vis:message buffer + local header = "--- " .. action .. ": " + vis:message(header .. "running " .. action .. " (" .. os.date() .. ")") + local all_succeeded = true for i, cmd in ipairs(cmds) do - vis:message("$ " .. cmd .. "\n") - local _, ostr, estr = vis:pipe(file, {start = 0, finish = file.size}, cmd) + vis:message(header .. "piping " + .. (file.name or "unnamed file") + .. " to `" .. cmd .. "`") + local status, ostr, estr = vis:pipe(file, {start = 0, finish = file.size}, cmd) - if ostr == nil and estr == nil then - vis:message("[no output]") - else + if ostr ~= nil or estr ~= nil then if (modify and ostr) then local pos = vis.win.selection.pos file:delete(0, file.size) file:insert(0, ostr) vis.win.selection.pos = pos else - vis:message(ostr or "") + if ostr then vis:message(ostr) end end - vis:message(estr or "") + if estr then vis:message(estr) end + vis:redraw() end - vis:message("\n") - if estr then - return false + if status then + all_succeeded = false + -- Exit early if any fixer fails as indicated by the exit status + if modify then + vis:message("Fixer failed with status code " .. status) + return false + end end end - return true + vis:message(header .. "done") + return all_succeeded end vis:command_register("lint", function(argv, force, win, selection, range)