ensure_document_loaded

Function ensure_document_loaded 

Source
pub async fn ensure_document_loaded(
    uri: &Uri,
    state: Arc<ServerState>,
    client: Client,
    config: Arc<RwLock<DepsConfig>>,
) -> bool
Expand 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 URI
  • state - Server state
  • client - LSP client for notifications
  • config - 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");
}