From 753f248eb30350eb9ba6ca108e466be8e54a51c8 Mon Sep 17 00:00:00 2001 From: Jackson Moore Date: Fri, 4 Sep 2026 11:35:32 +0200 Subject: Apply missing default label fallback --- lua/clever_f/capabilities.lua | 6 +++++- lua/clever_f/feedback_service.lua | 19 +++++++++++++++++-- lua/clever_f/testing/memory_host.lua | 32 ++++++++++++++++++++++++++++++++ tests/run.lua | 24 ++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/lua/clever_f/capabilities.lua b/lua/clever_f/capabilities.lua index 194de0b..3e770bd 100644 --- a/lua/clever_f/capabilities.lua +++ b/lua/clever_f/capabilities.lua @@ -22,7 +22,11 @@ M.effect_methods = { prompt = { "show_prompt" }, redraw = { "redraw" }, diagnostics = { "emit_diagnostic" }, - highlights = { "create_highlight", "remove_highlight" }, + highlights = { + "define_highlight_group", + "create_highlight", + "remove_highlight", + }, cursor_presentation = { "suppress_cursor_presentation", "restore_cursor_presentation", diff --git a/lua/clever_f/feedback_service.lua b/lua/clever_f/feedback_service.lua index f7e1dd6..d1fa9d6 100644 --- a/lua/clever_f/feedback_service.lua +++ b/lua/clever_f/feedback_service.lua @@ -52,7 +52,10 @@ local function normalize_options(options) end local function require_host(host) - if type(host) ~= "table" or type(host.read_highlight_group) ~= "function" then + if type(host) ~= "table" + or type(host.read_highlight_group) ~= "function" + or type(host.define_highlight_group) ~= "function" + then fail("FeedbackService host must provide highlight groups", 3) end return host @@ -86,7 +89,19 @@ function FeedbackService:ensure_default_label() applied = false, } end - return nil + + local definition = M.default_label_definition() + service_records[self].host:define_highlight_group( + M.DEFAULT_LABEL_GROUP, + definition, + { default = true } + ) + return { + group = M.DEFAULT_LABEL_GROUP, + definition = definition, + source = "fallback", + applied = true, + } end function M.new(options) diff --git a/lua/clever_f/testing/memory_host.lua b/lua/clever_f/testing/memory_host.lua index 459c9a8..0f8fc2d 100644 --- a/lua/clever_f/testing/memory_host.lua +++ b/lua/clever_f/testing/memory_host.lua @@ -663,6 +663,38 @@ function MemoryHost:highlight_groups() return copy(self._highlight_groups) end +function MemoryHost:define_highlight_group(name, definition, options) + if type(name) ~= "string" or name == "" then + error("highlight group name must be a nonempty string", 2) + end + if type(definition) ~= "table" then + error("highlight group definition must be a table", 2) + end + options = options or {} + if type(options) ~= "table" then + error("highlight group options must be a table", 2) + end + if options.default ~= nil and type(options.default) ~= "boolean" then + error("highlight group default option must be a Boolean", 2) + end + if options.force ~= nil and type(options.force) ~= "boolean" then + error("highlight group force option must be a Boolean", 2) + end + + local exists = self._highlight_groups[name] ~= nil + local applied = not (exists and options.default) + if applied then + self._highlight_groups[name] = copy(definition) + end + self:_record("define_highlight_group", { + name = name, + definition = definition, + options = options, + applied = applied, + }) + return applied +end + function MemoryHost:create_highlight(specification) if type(specification) ~= "table" then error("highlight specification must be a table", 2) diff --git a/tests/run.lua b/tests/run.lua index 696026e..de48f0b 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -4257,6 +4257,30 @@ test("Default label evaluation preserves a colorscheme definition", function() same("read_highlight_group", operations[1].operation) end) +test("Default label evaluation defines the fallback when absent", function() + local host = MemoryHost.new() + local feedback = feedback_service.new(host) + + local result = feedback:ensure_default_label() + same("fallback", result.source) + truthy(result.applied) + local definition = host:highlight_groups().CleverFDefaultLabel + same("red", definition.guifg) + same("NONE", definition.guibg) + truthy(definition.gui.bold) + truthy(definition.gui.underline) + same("red", definition.ctermfg) + same("NONE", definition.ctermbg) + truthy(definition.cterm.bold) + truthy(definition.cterm.underline) + + local operations = host:operations() + same(2, #operations) + same("read_highlight_group", operations[1].operation) + same("define_highlight_group", operations[2].operation) + truthy(operations[2].options.default) +end) + for _, item in ipairs(tests) do local ok, failure = xpcall(item.body, debug.traceback) if not ok then -- cgit v1.2.3