Resolvers are user-provided functions used to choose or acquire input before an action continues. Unlike callbacks, which observe lifecycle events and emit autocmds, resolvers are not hooks. They receive a context object and must call a done() callback with normalized data to proceed with the running action.
Resolvers can be synchronous or asynchronous. To handle the done callback:
- Success: Call
done({ data }) with the normalized result. - Cancel: Call
done(nil) to cancel the action. - Failure: Call
done(nil, "error message") to fail with a specific message.
require("obsidian").setup {
resolvers = {
attachment = function(ctx, done)
done { path = "/tmp/image.png" }
end,
date = function(ctx, done)
done { timestamp = os.time(), precision = "day" }
end,
},
}