Skip to content

Commit e1c19c0

Browse files
authored
fix: lock (#229)
* fix: lock * cleanup
1 parent 93052b3 commit e1c19c0

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

crates/pglt_lsp/src/handlers/text_document.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ use tower_lsp::lsp_types;
1010
use tracing::{error, field};
1111

1212
/// Handler for `textDocument/didOpen` LSP notification
13-
#[tracing::instrument(
14-
level = "debug",
15-
skip_all,
16-
fields(
17-
text_document_uri = display(params.text_document.uri.as_ref()),
18-
text_document_language_id = display(&params.text_document.language_id),
19-
)
20-
)]
13+
#[tracing::instrument(level = "debug", skip(session), err)]
2114
pub(crate) async fn did_open(
2215
session: &Session,
2316
params: lsp_types::DidOpenTextDocumentParams,
@@ -45,7 +38,7 @@ pub(crate) async fn did_open(
4538
}
4639

4740
// Handler for `textDocument/didChange` LSP notification
48-
#[tracing::instrument(level = "debug", skip_all, fields(url = field::display(&params.text_document.uri), version = params.text_document.version), err)]
41+
#[tracing::instrument(level = "debug", skip(session), err)]
4942
pub(crate) async fn did_change(
5043
session: &Session,
5144
params: lsp_types::DidChangeTextDocumentParams,

crates/pglt_workspace/src/workspace/server.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ impl Workspace for WorkspaceServer {
456456

457457
let schema_cache = self.schema_cache.load(pool)?;
458458

459+
tracing::debug!("Loaded schema cache for completions");
460+
459461
let result = pglt_completions::complete(pglt_completions::CompletionParams {
460462
position,
461463
schema: schema_cache.as_ref(),

crates/pglt_workspace/src/workspace/server/schema_cache_manager.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ impl SchemaCacheManager {
5555
let maybe_refreshed = run_async(async move { SchemaCache::load(&pool).await })?;
5656
let refreshed = maybe_refreshed?;
5757

58-
let mut inner = self.inner.write().unwrap();
58+
{
59+
// write lock must be dropped before we return the reference below, hence the block
60+
let mut inner = self.inner.write().unwrap();
5961

60-
inner.cache = refreshed;
61-
inner.conn_str = new_conn_str;
62+
// Double-check that we still need to refresh (another thread might have done it)
63+
if new_conn_str != inner.conn_str {
64+
inner.cache = refreshed;
65+
inner.conn_str = new_conn_str;
66+
}
67+
}
6268

6369
Ok(SchemaCacheHandle::new(&self.inner))
6470
}

0 commit comments

Comments
 (0)