pub struct NotificationCache { /* private fields */ }Expand description
Cache for LSP server notifications.
Implementations§
Source§impl NotificationCache
impl NotificationCache
Sourcepub fn set_diagnostics_route_count(&mut self, count: usize)
pub fn set_diagnostics_route_count(&mut self, count: usize)
Configure how many diagnostics-route servers share the global
MAX_DIAGNOSTIC_ENTRIES budget.
Each server’s fair share becomes MAX_DIAGNOSTIC_ENTRIES / count
(minimum 1). This does not cap any server’s entries by itself – the
aggregate cache is only ever trimmed once it reaches
MAX_DIAGNOSTIC_ENTRIES total – it only decides, at that point,
which server’s oldest entry is the one that gets evicted. Call once
after server registration completes and before diagnostics start
flowing. Defaults to 1 if never called (a single implicit server
owns the whole budget).
Sourcepub fn store_diagnostics(
&mut self,
server_id: &ServerId,
uri: &Uri,
version: Option<i32>,
diagnostics: Vec<LspDiagnostic>,
)
pub fn store_diagnostics( &mut self, server_id: &ServerId, uri: &Uri, version: Option<i32>, diagnostics: Vec<LspDiagnostic>, )
Store diagnostics for a document published by server_id.
Each diagnostic’s message is truncated to MAX_ENTRY_TEXT_BYTES,
and the whole list is bounded to MAX_DIAGNOSTICS_ENTRY_BYTES
serialized bytes, before storing (#311). When that bound requires
dropping diagnostics, the survivors come back sorted by severity
(diagnostic_severity_rank: ERROR first), not in the original
publish/file-position order – see Self::get_diagnostics.
If diagnostics already exist for the URI, they are replaced and the entry is repositioned to the back of its owner’s eviction order, so a URI republished on every edit is tracked as most-recently-written and evicted last, not first – and, since it is not a new distinct URI, never triggers eviction on its own.
Eviction is work-conserving (#276): storing diagnostics for a
genuinely new URI only evicts an existing entry once the aggregate
across every server reaches MAX_DIAGNOSTIC_ENTRIES, and then only
the least-recently-written entry of whichever server most exceeds its
fair share, or – per the fallbacks documented on
server_to_evict_from – the writer’s own oldest entry when no
server exceeds its share. A quieter, non-writer server that is within
its fair share is never touched, outside the narrow edge case also
documented there. This lets a single active server use the full
aggregate budget while other registered servers are idle, instead of
being capped at a static equal split regardless of how much of it
they actually use.
§Examples
use mcpls_core::bridge::NotificationCache;
use mcpls_core::config::ServerId;
use lsp_types::Uri;
let mut cache = NotificationCache::new();
let server: ServerId = "rust-analyzer".into();
let uri: Uri = "file:///main.rs".parse().unwrap();
cache.store_diagnostics(&server, &uri, Some(1), vec![]);
assert!(cache.get_diagnostics(uri.as_str()).is_some());Sourcepub fn store_log(&mut self, level: LogLevel, message: String)
pub fn store_log(&mut self, level: LogLevel, message: String)
Store a log entry.
Maintains a maximum of MAX_LOG_ENTRIES entries, removing oldest when full.
message is truncated to MAX_ENTRY_TEXT_BYTES before storing.
Sourcepub fn store_message(&mut self, message_type: MessageType, message: String)
pub fn store_message(&mut self, message_type: MessageType, message: String)
Store a server message.
Maintains a maximum of MAX_SERVER_MESSAGES entries, removing oldest when full.
message is truncated to MAX_ENTRY_TEXT_BYTES before storing.
Sourcepub fn get_diagnostics(&self, uri: &str) -> Option<&DiagnosticInfo>
pub fn get_diagnostics(&self, uri: &str) -> Option<&DiagnosticInfo>
Get diagnostics for a document URI.
If the stored list was ever truncated by store_diagnostics’s
MAX_DIAGNOSTICS_ENTRY_BYTES cap (#311), the diagnostics here are in
severity order (ERROR first), not the original publish/file-position
order – callers that assume file-position order should not rely on
it after a cap-triggered truncation.
Sourcepub fn diagnostics_owner(&self, uri: &str) -> Option<&ServerId>
pub fn diagnostics_owner(&self, uri: &str) -> Option<&ServerId>
Server that published the currently cached diagnostics for uri, if
any. Used to look up that server’s negotiated position encoding for a
cache-only read that has no live LSP round trip of its own to resolve
one from.
Sourcepub const fn messages(&self) -> &VecDeque<ServerMessage>
pub const fn messages(&self) -> &VecDeque<ServerMessage>
All stored server messages.
Sourcepub fn clear_diagnostics(&mut self, uri: &str) -> Option<DiagnosticInfo>
pub fn clear_diagnostics(&mut self, uri: &str) -> Option<DiagnosticInfo>
Clear diagnostics for a specific document URI.
Returns the cleared diagnostics if they existed.
Sourcepub fn clear_server_diagnostics(&mut self, server_id: &ServerId)
pub fn clear_server_diagnostics(&mut self, server_id: &ServerId)
Clear all diagnostics owned by a single server.
Used when a server crashes and respawns: its own stale entries must
be invalidated without disturbing any other server’s cache entries
(#266), unlike Self::clear_all_diagnostics.
§Examples
use mcpls_core::bridge::NotificationCache;
use mcpls_core::config::ServerId;
use lsp_types::Uri;
let mut cache = NotificationCache::new();
let crashed: ServerId = "pyright".into();
let healthy: ServerId = "rust-analyzer".into();
let crashed_uri: Uri = "file:///main.py".parse().unwrap();
let healthy_uri: Uri = "file:///main.rs".parse().unwrap();
cache.store_diagnostics(&crashed, &crashed_uri, Some(1), vec![]);
cache.store_diagnostics(&healthy, &healthy_uri, Some(1), vec![]);
cache.clear_server_diagnostics(&crashed);
assert!(cache.get_diagnostics(crashed_uri.as_str()).is_none());
assert!(cache.get_diagnostics(healthy_uri.as_str()).is_some());Sourcepub fn clear_all_diagnostics(&mut self)
pub fn clear_all_diagnostics(&mut self)
Clear all diagnostics, for every server.
Sourcepub fn clear_logs(&mut self)
pub fn clear_logs(&mut self)
Clear all logs.
Sourcepub fn clear_messages(&mut self)
pub fn clear_messages(&mut self)
Clear all messages.
Sourcepub fn diagnostics_count(&self) -> usize
pub fn diagnostics_count(&self) -> usize
Get the number of documents with stored diagnostics.
Sourcepub fn logs_count(&self) -> usize
pub fn logs_count(&self) -> usize
Get the number of stored log entries.
Sourcepub fn messages_count(&self) -> usize
pub fn messages_count(&self) -> usize
Get the number of stored server messages.