diff options
| -rw-r--r-- | lua/clever_f/feedback_service.lua | 45 | ||||
| -rw-r--r-- | tests/run.lua | 23 |
2 files changed, 67 insertions, 1 deletions
diff --git a/lua/clever_f/feedback_service.lua b/lua/clever_f/feedback_service.lua index d1fa9d6..d09c287 100644 --- a/lua/clever_f/feedback_service.lua +++ b/lua/clever_f/feedback_service.lua @@ -1,3 +1,5 @@ +local policy = require("clever_f.policy") + local M = {} local FeedbackService = {} FeedbackService.__index = FeedbackService @@ -7,6 +9,12 @@ M.DEFAULT_LABEL_GROUP = "CleverFDefaultLabel" local service_records = setmetatable({}, { __mode = "k" }) +local FEATURE_GROUPS = { + "CleverFCursor", + "CleverFChar", + "CleverFDirect", +} + local DEFAULT_LABEL_DEFINITION = { guifg = "red", guibg = "NONE", @@ -61,14 +69,26 @@ local function require_host(host) return host end +local function require_policy(service, host) + service = service or policy.new(host) + if type(service) ~= "table" + or type(service.evaluate_highlight_links) ~= "function" + then + fail("FeedbackService policy must evaluate highlight links", 3) + end + return service +end + function FeedbackService.new(options) if FeedbackService.is(options) then return options end options = normalize_options(options) local service = setmetatable({}, FeedbackService) + local host = require_host(options.host) service_records[service] = { - host = require_host(options.host), + host = host, + policy = require_policy(options.policy or options.policy_service, host), } return service end @@ -77,6 +97,29 @@ function FeedbackService.is(value) return type(value) == "table" and service_records[value] ~= nil end +function FeedbackService:evaluate_feature_links() + local record = service_records[self] + local rules = record.policy:evaluate_highlight_links() + local results = {} + for _, group in ipairs(FEATURE_GROUPS) do + local rule = rules[group] + if rule.configured_target ~= nil then + record.host:define_highlight_group( + group, + { link = rule.configured_target }, + { force = true } + ) + results[group] = { + group = group, + target = rule.configured_target, + source = "configured", + applied = true, + } + end + end + return results +end + function FeedbackService:ensure_default_label() local existing = service_records[self].host:read_highlight_group( M.DEFAULT_LABEL_GROUP diff --git a/tests/run.lua b/tests/run.lua index de48f0b..7a245f9 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -4281,6 +4281,29 @@ test("Default label evaluation defines the fallback when absent", function() truthy(operations[2].options.default) end) +test("Explicit color configuration forces its feature link", function() + local host = MemoryHost.new({ + configuration = { + mark_cursor_color = "Search", + }, + highlight_groups = { + CleverFCursor = { guifg = "blue" }, + }, + }) + local feedback = feedback_service.new(host) + + local results = feedback:evaluate_feature_links() + same("configured", results.CleverFCursor.source) + same("Search", results.CleverFCursor.target) + same("Search", host:highlight_groups().CleverFCursor.link) + + local operations = host:operations() + local definition = operations[#operations] + same("define_highlight_group", definition.operation) + same("CleverFCursor", definition.name) + truthy(definition.options.force) +end) + for _, item in ipairs(tests) do local ok, failure = xpcall(item.body, debug.traceback) if not ok then |
