Implementation:2giosangmitom Sqmeow nvim Core emit
| Knowledge Sources | |
|---|---|
| Domains | RPC, Event_Emission |
| Last Updated | 2026-10-16 14:00 GMT |
Overview
Concrete tool for sending event notifications from the engine to Neovim through MessagePack RPC provided by the sqmeow-core engine.
Description
The Core::emit method sends a named event with a MessagePack payload to the Neovim instance through the Nvim client. It is the primary mechanism for communicating completion of long operations back to the editor. Short operations return values directly through the RPC reply; long operations return an acknowledgement first, then spawn async work that emits completion events. The reply is queued before the work starts so Lua can record the accepted id before handling its events.
emit_call is a convenience wrapper that builds a standard call:state event payload with call_id, conn_id, state, and extra fields. emit_export builds an export:done event.
Usage
- Connection lifecycle: Emits
conn:statewith "connecting", "connected", or "error". - Query execution:
emit_callemitscall:statewith "executing", "done", "error", or "cancelled". - In-grid editing: Emits
apply:donewith apply outcome. - Local result processing: Emits
call:viewwith view metadata. - Result export:
emit_exportemitsexport:done. - Schema discovery: Emits
schema:nodesandstructure:done.
Code Reference
Source Location
- Repository: sqmeow.nvim
- File: core/sqmeow-core/src/server/mod.rs
- Lines: L142-146 (emit), calls.rs L807-815 (emit_call), exports.rs L153-160 (emit_export)
Signature
impl Core {
fn emit(&self, event: &str, payload: Value);
// In calls.rs:
fn emit_call(&self, call_id: CallId, conn_id: ConnId, state: &str, extra: Vec<(&str, Value)>);
// In exports.rs:
fn emit_export(&self, call_id: CallId, outcome: Result<Vec<(&str, Value)>, String>);
}
Import
// Internal to Core; called from handler modules.
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| event | &str | Yes | Event name (e.g. "call:state", "conn:state", "apply:done") |
| payload | Value | Yes | MessagePack map with event data |
| call_id | CallId | Yes | (emit_call/emit_export) Result id |
| conn_id | ConnId | Yes /// (emit_call) Connection id | |
| state | &str | Yes /// (emit_call) State string |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effect) | () /// Notification sent to Neovim; logged on failure |
Usage Examples
Emitting a call state event
self.emit_call(call_id, conn_id, "done", vec![
("columns", Value::Array(columns)),
("rows", Value::from(row_count)),
("elapsed_ms", Value::from(elapsed)),
]);
// Sends: call:state { call_id, conn_id, state: "done", columns, rows, elapsed_ms }
Emitting a custom event
self.emit("schema:nodes", map(vec![
("conn_id", Value::from(conn_id)),
("path", strings(path)),
("nodes", Value::Array(nodes)),
]));
Related Pages
Implements Principle
- Principle:2giosangmitom_Sqmeow_nvim_Session_Registration
- Principle:2giosangmitom_Sqmeow_nvim_Event_Emission
- Principle:2giosangmitom_Sqmeow_nvim_View_Caching
Requires Environment
- Environment:2giosangmitom_Sqmeow_nvim_Nix_Development_Shell
- Environment:2giosangmitom_Sqmeow_nvim_Tokio_Multi_Thread_Runtime