Implementation:2giosangmitom Sqmeow nvim Session
| Knowledge Sources | |
|---|---|
| Domains | Session_Management, Connection_Management, Query_Execution, Editing, View_Processing |
| Last Updated | 2026-10-16 14:00 GMT |
Overview
Concrete tool for managing editor session state — connections, result history, running calls, and view generations — provided by the sqmeow-core engine.
Description
The Session struct owns all state for one editor session. Connections and completed results are shared through Arc so asynchronous work can outlive the RPC handler that started it. Mutex-protected collections own session membership; cloned handles remain valid after eviction or disconnect but are no longer discoverable by id.
Key method groups:
- Connection management:
insert_connectionregisters an open connection;connectionlooks it up;remove_connectionforgets it. - Call lifecycle:
next_call_idallocates a unique id;begin_callregisters a running call with a cancellation token;canceltrips it. - Result history:
store_runstores results of one run as a history group (multi-statement = one slot); eviction removes the oldest run when history is full. - View generation:
begin_view/finish_vieworder view requests independently of their computation, discarding stale results. - Insert stash:
stash_inserted/take_insertedkeep rows from INSERT RETURNING for the next query run to display. - Options:
configureapplies settings patches (max_rows, history_size, timeout_ms).
The Call struct represents one finished result with its immutable ResultSet, optional View, and view generation counter. display() snapshots the current view under one lock.
Usage
- Connection lifecycle:
insert_connectionafter successful connect. - Query execution:
next_call_id,begin_call,store_runfor results. - In-grid editing:
stash_insertedfor INSERT RETURNING rows. - Local result processing:
begin_view,finish_view,with_call,call. - Result export:
with_call,callto read stored results.
Code Reference
Source Location
- Repository: sqmeow.nvim
- File: core/sqmeow-core/src/server/session.rs
- Lines: L1-408
Signature
pub struct Session { /* connections, calls, running, options, next_call_id, inserted */ }
impl Session {
pub fn options(&self) -> Options;
pub fn configure(&self, patch: OptionsPatch) -> Options;
pub fn insert_connection(&self, connection: Connection);
pub fn connection(&self, id: ConnId) -> Option<Arc<Connection>>;
pub fn remove_connection(&self, id: ConnId) -> Option<Arc<Connection>>;
pub fn next_call_id(&self) -> CallId;
pub fn begin_call(&self, id: CallId) -> RunningCall<'_>;
pub fn cancel(&self, id: CallId) -> bool;
pub fn store_run(&self, calls: Vec<Call>) -> Vec<Arc<Call>>;
pub fn stash_inserted(&self, conn_id: ConnId, rows: Vec<ResultSet>);
pub fn take_inserted(&self, conn_id: ConnId) -> Vec<ResultSet>;
pub fn with_call<T>(&self, id: CallId, read: impl FnOnce(&Call) -> T) -> Option<T>;
pub fn call(&self, id: CallId) -> Option<Arc<Call>>;
}
impl Call {
pub fn display(&self) -> (Option<Arc<ResultSet>>, Option<Arc<Vec<usize>>>);
pub fn begin_view(&self) -> u64;
pub fn finish_view(&self, generation: u64, finish: impl FnOnce());
}
Import
use crate::server::session::{Session, Call, CallId, ConnId, Connection, View, Options, OptionsPatch};
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| connection | Connection | Yes | Open connection with id, name, Backend, read_only, optional Tunnel |
| calls | Vec<Call> | Yes | Results of one run to store (multi-statement = one history slot) |
| id | CallId | Yes /// Result/connection id to look up | |
| patch | OptionsPatch | Yes /// Settings patch (max_rows, history_size, timeout_ms) |
Outputs
| Name | Type | Description |
|---|---|---|
| store_run | Vec<Arc<Call>> /// Shared handles; oldest run evicted when full | |
| with_call | Option<T> /// Result of reading the stored call, or None if evicted | |
| begin_view | u64 /// Generation number to gate stale completions | |
| finish_view | () /// Calls finish() only if generation is current |
Usage Examples
Storing a multi-statement run
let calls = vec![call1, call2, call3]; // 3 statements, 1 history slot
let stored = session.store_run(calls);
// All 3 calls share one history group; evicted together
View generation ordering
let gen = call.begin_view(); // Increment generation
// ... async computation ...
call.finish_view(gen, || {
// Only runs if no newer view request superseded this one
*call.view.lock().unwrap() = Some(View::Rows(Arc::new(indices)));
});
Related Pages
Implements Principle
- Principle:2giosangmitom_Sqmeow_nvim_Session_Registration
- Principle:2giosangmitom_Sqmeow_nvim_Result_Retention
- Principle:2giosangmitom_Sqmeow_nvim_View_Caching
Requires Environment
- Environment:2giosangmitom_Sqmeow_nvim_Nix_Development_Shell
- Environment:2giosangmitom_Sqmeow_nvim_Tokio_Multi_Thread_Runtime