diff --git a/crates/pglt_lsp/src/handlers/text_document.rs b/crates/pglt_lsp/src/handlers/text_document.rs index d777cf65..78279cd1 100644 --- a/crates/pglt_lsp/src/handlers/text_document.rs +++ b/crates/pglt_lsp/src/handlers/text_document.rs @@ -10,14 +10,7 @@ use tower_lsp::lsp_types; use tracing::{error, field}; /// Handler for `textDocument/didOpen` LSP notification -#[tracing::instrument( - level = "debug", - skip_all, - fields( - text_document_uri = display(params.text_document.uri.as_ref()), - text_document_language_id = display(¶ms.text_document.language_id), - ) -)] +#[tracing::instrument(level = "debug", skip(session), err)] pub(crate) async fn did_open( session: &Session, params: lsp_types::DidOpenTextDocumentParams, @@ -45,7 +38,7 @@ pub(crate) async fn did_open( } // Handler for `textDocument/didChange` LSP notification -#[tracing::instrument(level = "debug", skip_all, fields(url = field::display(¶ms.text_document.uri), version = params.text_document.version), err)] +#[tracing::instrument(level = "debug", skip(session), err)] pub(crate) async fn did_change( session: &Session, params: lsp_types::DidChangeTextDocumentParams, diff --git a/crates/pglt_workspace/src/workspace/server.rs b/crates/pglt_workspace/src/workspace/server.rs index 4e15158c..0db5023d 100644 --- a/crates/pglt_workspace/src/workspace/server.rs +++ b/crates/pglt_workspace/src/workspace/server.rs @@ -456,6 +456,8 @@ impl Workspace for WorkspaceServer { let schema_cache = self.schema_cache.load(pool)?; + tracing::debug!("Loaded schema cache for completions"); + let result = pglt_completions::complete(pglt_completions::CompletionParams { position, schema: schema_cache.as_ref(), diff --git a/crates/pglt_workspace/src/workspace/server/schema_cache_manager.rs b/crates/pglt_workspace/src/workspace/server/schema_cache_manager.rs index b2dad857..e1f10c1d 100644 --- a/crates/pglt_workspace/src/workspace/server/schema_cache_manager.rs +++ b/crates/pglt_workspace/src/workspace/server/schema_cache_manager.rs @@ -55,10 +55,16 @@ impl SchemaCacheManager { let maybe_refreshed = run_async(async move { SchemaCache::load(&pool).await })?; let refreshed = maybe_refreshed?; - let mut inner = self.inner.write().unwrap(); + { + // write lock must be dropped before we return the reference below, hence the block + let mut inner = self.inner.write().unwrap(); - inner.cache = refreshed; - inner.conn_str = new_conn_str; + // Double-check that we still need to refresh (another thread might have done it) + if new_conn_str != inner.conn_str { + inner.cache = refreshed; + inner.conn_str = new_conn_str; + } + } Ok(SchemaCacheHandle::new(&self.inner)) }