Yes it’s possible using the editor:complete event listener
Here is the complete space-lua which does what you ask for, not perfect but it does the job:
event.listen {
name = "editor:complete",
run = function(e)
local linePrefix = e.data.linePrefix or ""
local pos = e.data.pos or 0
local match = string.match(linePrefix, "@([a-zA-Z0-9_]*)$")
if not match then
return
end
local people = query[[ from p = index.tag("person")]]
local opts = {}
for _, p in ipairs(people) do
local label = (p.FirstName or "") .. " " .. (p.LastName or "")
local completionText = "[[" .. p.ref .. "|" .. label .. "]]"
table.insert(opts, {
label = label,
detail = p.ref,
apply = function()
editor.dispatch({
changes = {
from = pos - string.len(match) - 1,
to = pos,
insert = completionText
}
})
end
})
end
return {
from = pos - string.len(match),
options = opts
}
end
}
