aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-08-29 19:08:37 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-08-29 19:11:38 -0700
commitc9327f2af541e4a17a6e2e05682122f8c8455d29 (patch)
tree87e5bf7d368a47bd232436296089289d7a748562
parentb426bfff29cd67ceedfb2e67401a1fce2e0fdb60 (diff)
feat: display last few lines of the log file in :ConformInfo
-rw-r--r--lua/conform/health.lua18
-rw-r--r--lua/conform/runner.lua16
2 files changed, 26 insertions, 8 deletions
diff --git a/lua/conform/health.lua b/lua/conform/health.lua
index f285011..195a331 100644
--- a/lua/conform/health.lua
+++ b/lua/conform/health.lua
@@ -43,7 +43,21 @@ M.show_window = function()
local lines = {}
local highlights = {}
local log = require("conform.log")
- table.insert(lines, string.format("Log file: %s", log.get_logfile()))
+ local logfile = log.get_logfile()
+ table.insert(lines, string.format("Log file: %s", logfile))
+ table.insert(highlights, { "Title", #lines, 0, 10 })
+ if vim.fn.filereadable(logfile) == 1 then
+ local f = io.open(logfile, "r")
+ if f then
+ f:seek("end", -1024)
+ local text = f:read("*a")
+ f:close()
+ local log_lines = vim.split(text, "\n", { plain = true, trimempty = true })
+ for i = 2, #log_lines do
+ table.insert(lines, string.rep(" ", 10) .. log_lines[i])
+ end
+ end
+ end
table.insert(lines, "")
---@param formatters conform.FormatterInfo[]
@@ -69,6 +83,7 @@ M.show_window = function()
end
table.insert(lines, "Formatters for this buffer:")
+ table.insert(highlights, { "Title", #lines, 0, -1 })
local seen = {}
local buf_formatters = conform.list_formatters_for_buffer()
for _, formatter in ipairs(buf_formatters) do
@@ -78,6 +93,7 @@ M.show_window = function()
table.insert(lines, "")
table.insert(lines, "Other formatters:")
+ table.insert(highlights, { "Title", #lines, 0, -1 })
local all_formatters = vim.tbl_filter(function(f)
return not seen[f.name]
end, conform.list_all_formatters())
diff --git a/lua/conform/runner.lua b/lua/conform/runner.lua
index d546a41..8c2bfaf 100644
--- a/lua/conform/runner.lua
+++ b/lua/conform/runner.lua
@@ -160,14 +160,16 @@ local function run_formatter(bufnr, formatter, config, ctx, input_lines, callbac
log.debug("%s exited with code %d", formatter.name, code)
callback(nil, output)
else
- log.error("%s exited with code %d", formatter.name, code)
- log.warn("%s stdout: %s", formatter.name, stdout)
- log.warn("%s stderr: %s", formatter.name, stderr)
- local stderr_str
- if stderr then
- stderr_str = table.concat(stderr, "\n")
+ log.info("%s exited with code %d", formatter.name, code)
+ log.debug("%s stdout: %s", formatter.name, stdout)
+ log.debug("%s stderr: %s", formatter.name, stderr)
+ local err_str
+ if stderr and not vim.tbl_isempty(stderr) then
+ err_str = table.concat(stderr, "\n")
+ elseif stdout and not vim.tbl_isempty(stdout) then
+ err_str = table.concat(stdout, "\n")
end
- callback(string.format("Formatter '%s' error: %s", formatter.name, stderr_str))
+ callback(string.format("Formatter '%s' error: %s", formatter.name, err_str))
end
end,
})