Skip to content

fix: lock #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions crates/pglt_lsp/src/handlers/text_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&params.text_document.language_id),
)
)]
#[tracing::instrument(level = "debug", skip(session), err)]
pub(crate) async fn did_open(
session: &Session,
params: lsp_types::DidOpenTextDocumentParams,
Expand Down Expand Up @@ -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(&params.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,
Expand Down
2 changes: 2 additions & 0 deletions crates/pglt_workspace/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down