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 1
1
use serde:: Deserialize ;
2
2
3
- // TODO: Check that the Opts are correct (existed in server.rs)
4
3
#[ derive( Deserialize , Debug ) ]
5
4
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
+ }
7
25
}
Original file line number Diff line number Diff line change @@ -13,14 +13,20 @@ pub(crate) struct DbConnection {
13
13
}
14
14
15
15
impl DbConnection {
16
+ #[ tracing:: instrument( name = "Setting up new Database Connection…" , skip( ide) ) ]
16
17
pub ( crate ) async fn new (
17
18
connection_string : String ,
18
19
ide : Arc < RwLock < Workspace > > ,
19
20
) -> Result < Self , sqlx:: Error > {
21
+ tracing:: info!( "Trying to connect to pool…" ) ;
20
22
let pool = PgPool :: connect ( & connection_string) . await ?;
23
+ tracing:: info!( "Connected to Pool." ) ;
21
24
22
25
let mut listener = PgListener :: connect_with ( & pool) . await ?;
26
+ tracing:: info!( "Connected to Listener." ) ;
27
+
23
28
listener. listen_all ( [ "postgres_lsp" , "pgrst" ] ) . await ?;
29
+ tracing:: info!( "Listening!" ) ;
24
30
25
31
let ( close_tx, close_rx) = tokio:: sync:: oneshot:: channel :: < ( ) > ( ) ;
26
32
@@ -52,6 +58,7 @@ impl DbConnection {
52
58
}
53
59
}
54
60
} ) ;
61
+ tracing:: info!( "Set up schema update handle." ) ;
55
62
56
63
Ok ( Self {
57
64
pool,
Original file line number Diff line number Diff line change 1
- use std:: fmt:: format;
2
1
use std:: sync:: Arc ;
3
2
4
3
use notification:: ShowMessage ;
@@ -126,10 +125,10 @@ impl LspServer {
126
125
Ok ( ( ) ) => { }
127
126
Err ( e) => {
128
127
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
+ )
133
132
. await
134
133
}
135
134
} ;
Original file line number Diff line number Diff line change @@ -56,17 +56,20 @@ impl Session {
56
56
return Ok ( ( ) ) ;
57
57
}
58
58
59
+ tracing:: info!( "Setting up new Database connection" ) ;
59
60
let new_db = DbConnection :: new ( connection_string, Arc :: clone ( & self . ide ) ) . await ?;
61
+ tracing:: info!( "Set up new connection, trying to acquire write lock…" ) ;
60
62
61
63
let mut current_db = self . db . write ( ) . await ;
62
64
let old_db = current_db. replace ( new_db) ;
63
- drop ( current_db) ;
64
65
65
66
if old_db. is_some ( ) {
67
+ tracing:: info!( "Dropping previous Database Connection." ) ;
66
68
let old_db = old_db. unwrap ( ) ;
67
69
old_db. close ( ) . await ;
68
70
}
69
71
72
+ tracing:: info!( "Successfully set up new connection." ) ;
70
73
Ok ( ( ) )
71
74
}
72
75
Original file line number Diff line number Diff line change 1
1
version : " 3.8"
2
2
services :
3
3
db :
4
+ # postgres://postgres:postgres@127.0.0.1:5432/postgres
4
5
image : postgres
5
6
restart : always
6
7
environment :
You can’t perform that action at this time.
0 commit comments