File tree Expand file tree Collapse file tree 5 files changed +36
-8
lines changed Expand file tree Collapse file tree 5 files changed +36
-8
lines changed Original file line number Diff line number Diff line change 11use serde:: Deserialize ;
22
3- // TODO: Check that the Opts are correct (existed in server.rs)
43#[ derive( Deserialize , Debug ) ]
54pub 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}
Original file line number Diff line number Diff line change @@ -13,14 +13,20 @@ pub(crate) struct DbConnection {
1313}
1414
1515impl 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,
Original file line number Diff line number Diff line change 1- use std:: fmt:: format;
21use std:: sync:: Arc ;
32
43use 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 } ;
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11version : " 3.8"
22services :
33 db :
4+ # postgres://postgres:[email protected] :5432/postgres 45 image : postgres
56 restart : always
67 environment :
You can’t perform that action at this time.
0 commit comments