From 781f379aff465324b3fc72130ab8f7aecba879f4 Mon Sep 17 00:00:00 2001 From: hektor Date: Sun, 26 Apr 2026 16:07:18 +0200 Subject: [PATCH] refactor: simplify zk file completion --- dots/.config/nvim/lua/zk/cmp.lua | 35 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/dots/.config/nvim/lua/zk/cmp.lua b/dots/.config/nvim/lua/zk/cmp.lua index e3e234dd..d17d979a 100644 --- a/dots/.config/nvim/lua/zk/cmp.lua +++ b/dots/.config/nvim/lua/zk/cmp.lua @@ -13,28 +13,31 @@ local function get_markdown_files(base) return items end +function source:get_keyword_pattern() + return "[%w%./%-]*" +end + function source:complete(params, callback) local cursor_before_line = params.context.cursor_before_line local cursor_after_line = params.context.cursor_after_line or "" - local trigger = cursor_before_line:match("%[[^%]]*%]%(([^)]*)$") - - if trigger ~= nil then - local items = get_markdown_files(".") - local next_char = cursor_after_line:sub(1, 1) - - for _, item in ipairs(items) do - if next_char == ")" then - item.insertText = item.label - else - item.insertText = item.label .. ")" - end - end - - callback(items) - else + if not cursor_before_line:match("%[[^%]]*%]%(") then callback({}) + return end + + local items = get_markdown_files(".") + local next_char = cursor_after_line:sub(1, 1) + + for _, item in ipairs(items) do + if next_char == ")" then + item.insertText = item.label + else + item.insertText = item.label .. ")" + end + end + + callback(items) end function source:get_trigger_characters()