Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lua/conform/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@ M.show_window = function()
---@param formatter conform.FormatterInfo
local function append_formatter_info(formatter)
if not formatter.available then
local line = string.format("%s unavailable: %s", formatter.name, formatter.available_msg)
local type_label = formatter.error and "error" or "unavailable"

local line = string.format("%s %s: %s", formatter.name, type_label, formatter.available_msg)

table.insert(lines, line)
table.insert(
highlights,
{ "DiagnosticWarn", #lines, formatter.name:len(), formatter.name:len() + 12 }
)

local hl = formatter.error and "DiagnosticError" or "DiagnosticWarn"
local hl_start = formatter.name:len() + 1
table.insert(highlights, { hl, #lines, hl_start, hl_start + type_label:len() })
else
local filetypes = get_formatter_filetypes(formatter.name)
local filetypes_list = table.concat(filetypes, ", ")
Expand Down
3 changes: 2 additions & 1 deletion lua/conform/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ M.get_formatter_info = function(formatter, bufnr)
name = formatter,
command = formatter,
available = false,
available_msg = "Formatter config missing or incomplete",
available_msg = "Unknown formatter. Formatter config missing or incomplete",
error = true,
}
end

Expand Down
1 change: 1 addition & 0 deletions lua/conform/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
---@field cwd? string
---@field available boolean
---@field available_msg? string
---@field error? boolean

---@class (exact) conform.JobFormatterConfig
---@field command string|fun(self: conform.JobFormatterConfig, ctx: conform.Context): string
Expand Down
2 changes: 2 additions & 0 deletions tests/api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ describe("api", function()
assert.equal("stylua", info.name)
assert.equal("stylua", info.command)
assert.equal("boolean", type(info.available))
assert.is_nil(info.error)
end)

it("retrieves unavailable info if formatter does not exist", function()
local info = conform.get_formatter_info("asdf")
assert.equal("asdf", info.name)
assert.equal("asdf", info.command)
assert.falsy(info.available)
assert.truthy(info.error)
end)

describe("list_formatters", function()
Expand Down