Add back zettelkasten markdown file completion

main
Hektor Misplon 2025-11-04 23:31:13 +01:00
parent fa6c4d786b
commit 5d88ea6f11
3 changed files with 52 additions and 0 deletions

View File

@ -63,6 +63,7 @@ cmp.setup({
}), }),
sources = { sources = {
{ name = "copilot", group_index = 2 }, { name = "copilot", group_index = 2 },
{ name = "zk" },
{ name = "nvim_lsp", keyword_length = 8 }, { name = "nvim_lsp", keyword_length = 8 },
{ name = "luasnip", max_item_count = 16 }, { name = "luasnip", max_item_count = 16 },
{ name = "path" }, { name = "path" },

View File

@ -0,0 +1,49 @@
local cmp = require("cmp")
local source = {}
local function get_markdown_files(base)
local items = {}
local pattern = base .. "/**/*.md"
local files = vim.fn.glob(pattern, false, true)
for _, file in ipairs(files) do
local label = file:gsub("^%./", ""):gsub("%.md$", "")
table.insert(items, { label = label })
end
return items
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
callback({})
end
end
function source:get_trigger_characters()
return { "(" }
end
function source:is_available()
local ft = vim.bo.filetype
return ft == "markdown" or ft == "pandoc"
end
cmp.register_source("zk", source)

View File

@ -1,3 +1,5 @@
require("zk.cmp")
vim.cmd([[ vim.cmd([[
let s:zk_preview_enabled = 0 let s:zk_preview_enabled = 0
let s:live_server_job = -1 let s:live_server_job = -1