pub async fn ensure_document_loaded(
uri: &Uri,
state: Arc<ServerState>,
client: Client,
config: Arc<RwLock<DepsConfig>>,
) -> boolExpand description
Ensures a document is loaded in state.
If the document is not already in state, loads it from disk, parses it, and spawns a background task to fetch version information.
This function is idempotent - calling it multiple times with the same URI is safe and will only load once.
§Arguments
uri- Document URIstate- Server stateclient- LSP client for notificationsconfig- Server configuration
§Returns
true- Document is now loaded (either already existed or was just loaded)false- Document could not be loaded (unsupported file type, read error, etc.)
§Behavior
- If document exists in state → Return true immediately (no-op)
- If document doesn’t exist → Load from disk, parse, update state, spawn bg task
- If load fails → Log warning and return false (graceful degradation)
§Examples
use deps_lsp::document::ensure_document_loaded;
use deps_lsp::document::ServerState;
use tower_lsp_server::ls_types::Uri;
use std::sync::Arc;
let loaded = ensure_document_loaded(uri, state, client, config).await;
if loaded {
println!("Document is available for processing");
}