init.lua/lua/scratch/ledger.lua(view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
local t = require("blink.cmp.types").CompletionItemKind
---@module 'blink.cmp'
---@class blink.cmp.Source
local source = {}
function source.new(_)
return setmetatable({}, { __index = source })
end
function source:enabled()
return vim.bo.filetype == "ledger"
end
function source:get_trigger_characters()
return { ":", "as", "eq", "li", "in", "ex" }
end
function source:get_completions(_, callback)
local rs = vim
.system({ "hledger", "accounts", "--flat" }, { text = true })
:wait()
---@type lsp.CompletionItem[]
local items = rs.code == 0
and vim
.iter(vim.split(rs.stdout, "\n"))
:map(function(acc)
return {
label = acc,
kind = t.Property,
insertTextFormat = vim.lsp.protocol.InsertTextFormat.PlainText,
}
end)
:totable()
or {}
callback {
items = items,
is_incomplete_backward = false,
is_incomplete_forward = false,
}
return function() end
end
return source
|