Skip to content

Commit 88255aa

Browse files
author
Ruslan Hrabovyi
committed
distinguish between availability and initialization error
- use `error` instead of `unavailable` message type in case of initialization error - highlight with error color
1 parent 1a7f603 commit 88255aa

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lua/conform/health.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,15 @@ M.show_window = function()
101101
---@param formatter conform.FormatterInfo
102102
local function append_formatter_info(formatter)
103103
if not formatter.available then
104-
local line = string.format("%s unavailable: %s", formatter.name, formatter.available_msg)
104+
local type_label = formatter.error and "error" or "unavailable"
105+
106+
local line = string.format("%s %s: %s", formatter.name, type_label, formatter.available_msg)
107+
105108
table.insert(lines, line)
106-
table.insert(
107-
highlights,
108-
{ "DiagnosticWarn", #lines, formatter.name:len(), formatter.name:len() + 12 }
109-
)
109+
110+
local hl = formatter.error and "DiagnosticError" or "DiagnosticWarn"
111+
local hl_start = formatter.name:len() + 1
112+
table.insert(highlights, { hl, #lines, hl_start, hl_start + type_label:len() })
110113
else
111114
local filetypes = get_formatter_filetypes(formatter.name)
112115
local filetypes_list = table.concat(filetypes, ", ")

lua/conform/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ M.get_formatter_info = function(formatter, bufnr)
767767
command = formatter,
768768
available = false,
769769
available_msg = "Unknown formatter. Formatter config missing or incomplete",
770+
error = true,
770771
}
771772
end
772773

tests/api_spec.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ describe("api", function()
1212
assert.equal("stylua", info.name)
1313
assert.equal("stylua", info.command)
1414
assert.equal("boolean", type(info.available))
15+
assert.is_nil(info.error)
1516
end)
1617

1718
it("retrieves unavailable info if formatter does not exist", function()
1819
local info = conform.get_formatter_info("asdf")
1920
assert.equal("asdf", info.name)
2021
assert.equal("asdf", info.command)
2122
assert.falsy(info.available)
23+
assert.truthy(info.error)
2224
end)
2325

2426
describe("list_formatters", function()

0 commit comments

Comments
 (0)