Skip to content

Commit d17f1da

Browse files
fixed the issue
1 parent 1bed5d2 commit d17f1da

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
use serde::Deserialize;
22

3-
// TODO: Check that the Opts are correct (existed in server.rs)
43
#[derive(Deserialize, Debug)]
54
pub struct ClientConfigurationOptions {
6-
pub db_connection_string: Option<String>,
5+
#[serde(rename(deserialize = "databaseUrl"))]
6+
pub(crate) db_connection_string: Option<String>,
7+
}
8+
9+
#[cfg(test)]
10+
mod tests {
11+
use serde_json::json;
12+
13+
use crate::client::client_config_opts::ClientConfigurationOptions;
14+
15+
#[test]
16+
fn test_json_parsing() {
17+
let config = json!({
18+
"databaseUrl": "cool-shit"
19+
});
20+
21+
let parsed: ClientConfigurationOptions = serde_json::from_value(config).unwrap();
22+
23+
assert_eq!(parsed.db_connection_string, Some("cool-shit".into()));
24+
}
725
}

crates/pg_lsp/src/db_connection.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ pub(crate) struct DbConnection {
1313
}
1414

1515
impl DbConnection {
16+
#[tracing::instrument(name = "Setting up new Database Connection…", skip(ide))]
1617
pub(crate) async fn new(
1718
connection_string: String,
1819
ide: Arc<RwLock<Workspace>>,
1920
) -> Result<Self, sqlx::Error> {
21+
tracing::info!("Trying to connect to pool…");
2022
let pool = PgPool::connect(&connection_string).await?;
23+
tracing::info!("Connected to Pool.");
2124

2225
let mut listener = PgListener::connect_with(&pool).await?;
26+
tracing::info!("Connected to Listener.");
27+
2328
listener.listen_all(["postgres_lsp", "pgrst"]).await?;
29+
tracing::info!("Listening!");
2430

2531
let (close_tx, close_rx) = tokio::sync::oneshot::channel::<()>();
2632

@@ -52,6 +58,7 @@ impl DbConnection {
5258
}
5359
}
5460
});
61+
tracing::info!("Set up schema update handle.");
5562

5663
Ok(Self {
5764
pool,

crates/pg_lsp/src/server.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::fmt::format;
21
use std::sync::Arc;
32

43
use notification::ShowMessage;
@@ -126,10 +125,10 @@ impl LspServer {
126125
Ok(()) => {}
127126
Err(e) => {
128127
self.client
129-
.send_notification::<ShowMessage>(ShowMessageParams {
130-
typ: MessageType::ERROR,
131-
message: format!("Unable to process config received from client: {e:?}"),
132-
})
128+
.log_message(
129+
MessageType::ERROR,
130+
format!("Unable to process config from client: {e:?}"),
131+
)
133132
.await
134133
}
135134
};

crates/pg_lsp/src/session.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,20 @@ impl Session {
5656
return Ok(());
5757
}
5858

59+
tracing::info!("Setting up new Database connection");
5960
let new_db = DbConnection::new(connection_string, Arc::clone(&self.ide)).await?;
61+
tracing::info!("Set up new connection, trying to acquire write lock…");
6062

6163
let mut current_db = self.db.write().await;
6264
let old_db = current_db.replace(new_db);
63-
drop(current_db);
6465

6566
if old_db.is_some() {
67+
tracing::info!("Dropping previous Database Connection.");
6668
let old_db = old_db.unwrap();
6769
old_db.close().await;
6870
}
6971

72+
tracing::info!("Successfully set up new connection.");
7073
Ok(())
7174
}
7275

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
version: "3.8"
22
services:
33
db:
4+
# postgres://postgres:postgres@127.0.0.1:5432/postgres
45
image: postgres
56
restart: always
67
environment:

0 commit comments

Comments
 (0)