1
1
use std:: {
2
+ collections:: HashMap ,
2
3
fs,
3
4
panic:: RefUnwindSafe ,
4
5
path:: { Path , PathBuf } ,
@@ -8,7 +9,6 @@ use std::{
8
9
use analyser:: AnalyserVisitorBuilder ;
9
10
use async_helper:: run_async;
10
11
use connection_manager:: ConnectionManager ;
11
- use dashmap:: DashMap ;
12
12
use document:: {
13
13
AsyncDiagnosticsMapper , CursorPositionFilter , DefaultMapper , Document , ExecuteStatementMapper ,
14
14
SyncDiagnosticsMapper ,
@@ -67,7 +67,7 @@ pub(super) struct WorkspaceServer {
67
67
/// Stores the schema cache for this workspace
68
68
schema_cache : SchemaCacheManager ,
69
69
70
- documents : DashMap < PgTPath , Document > ,
70
+ documents : RwLock < HashMap < PgTPath , Document > > ,
71
71
72
72
connection : ConnectionManager ,
73
73
}
@@ -89,7 +89,7 @@ impl WorkspaceServer {
89
89
pub ( crate ) fn new ( ) -> Self {
90
90
Self {
91
91
settings : RwLock :: default ( ) ,
92
- documents : DashMap :: default ( ) ,
92
+ documents : RwLock :: new ( HashMap :: new ( ) ) ,
93
93
schema_cache : SchemaCacheManager :: new ( ) ,
94
94
connection : ConnectionManager :: new ( ) ,
95
95
}
@@ -262,7 +262,8 @@ impl Workspace for WorkspaceServer {
262
262
/// Add a new file to the workspace
263
263
#[ tracing:: instrument( level = "info" , skip_all, fields( path = params. path. as_path( ) . as_os_str( ) . to_str( ) ) , err) ]
264
264
fn open_file ( & self , params : OpenFileParams ) -> Result < ( ) , WorkspaceError > {
265
- self . documents
265
+ let mut documents = self . documents . write ( ) . unwrap ( ) ;
266
+ documents
266
267
. entry ( params. path . clone ( ) )
267
268
. or_insert_with ( || Document :: new ( params. content , params. version ) ) ;
268
269
@@ -275,7 +276,8 @@ impl Workspace for WorkspaceServer {
275
276
276
277
/// Remove a file from the workspace
277
278
fn close_file ( & self , params : super :: CloseFileParams ) -> Result < ( ) , WorkspaceError > {
278
- self . documents
279
+ let mut documents = self . documents . write ( ) . unwrap ( ) ;
280
+ documents
279
281
. remove ( & params. path )
280
282
. ok_or_else ( WorkspaceError :: not_found) ?;
281
283
@@ -288,13 +290,15 @@ impl Workspace for WorkspaceServer {
288
290
version = params. version
289
291
) , err) ]
290
292
fn change_file ( & self , params : super :: ChangeFileParams ) -> Result < ( ) , WorkspaceError > {
291
- match self . documents . entry ( params. path . clone ( ) ) {
292
- dashmap:: mapref:: entry:: Entry :: Occupied ( mut entry) => {
293
+ let mut documents = self . documents . write ( ) . unwrap ( ) ;
294
+
295
+ match documents. entry ( params. path . clone ( ) ) {
296
+ std:: collections:: hash_map:: Entry :: Occupied ( mut entry) => {
293
297
entry
294
298
. get_mut ( )
295
299
. update_content ( params. content , params. version ) ;
296
300
}
297
- dashmap :: mapref :: entry :: Entry :: Vacant ( entry) => {
301
+ std :: collections :: hash_map :: Entry :: Vacant ( entry) => {
298
302
entry. insert ( Document :: new ( params. content , params. version ) ) ;
299
303
}
300
304
}
@@ -307,8 +311,8 @@ impl Workspace for WorkspaceServer {
307
311
}
308
312
309
313
fn get_file_content ( & self , params : GetFileContentParams ) -> Result < String , WorkspaceError > {
310
- let document = self
311
- . documents
314
+ let documents = self . documents . read ( ) . unwrap ( ) ;
315
+ let document = documents
312
316
. get ( & params. path )
313
317
. ok_or ( WorkspaceError :: not_found ( ) ) ?;
314
318
Ok ( document. get_document_content ( ) . to_string ( ) )
@@ -322,8 +326,8 @@ impl Workspace for WorkspaceServer {
322
326
& self ,
323
327
params : code_actions:: CodeActionsParams ,
324
328
) -> Result < code_actions:: CodeActionsResult , WorkspaceError > {
325
- let parser = self
326
- . documents
329
+ let documents = self . documents . read ( ) . unwrap ( ) ;
330
+ let parser = documents
327
331
. get ( & params. path )
328
332
. ok_or ( WorkspaceError :: not_found ( ) ) ?;
329
333
@@ -364,8 +368,8 @@ impl Workspace for WorkspaceServer {
364
368
& self ,
365
369
params : ExecuteStatementParams ,
366
370
) -> Result < ExecuteStatementResult , WorkspaceError > {
367
- let parser = self
368
- . documents
371
+ let documents = self . documents . read ( ) . unwrap ( ) ;
372
+ let parser = documents
369
373
. get ( & params. path )
370
374
. ok_or ( WorkspaceError :: not_found ( ) ) ?;
371
375
@@ -422,8 +426,8 @@ impl Workspace for WorkspaceServer {
422
426
}
423
427
} ;
424
428
425
- let doc = self
426
- . documents
429
+ let documents = self . documents . read ( ) . unwrap ( ) ;
430
+ let doc = documents
427
431
. get ( & params. path )
428
432
. ok_or ( WorkspaceError :: not_found ( ) ) ?;
429
433
@@ -607,8 +611,8 @@ impl Workspace for WorkspaceServer {
607
611
& self ,
608
612
params : GetCompletionsParams ,
609
613
) -> Result < CompletionsResult , WorkspaceError > {
610
- let parsed_doc = self
611
- . documents
614
+ let documents = self . documents . read ( ) . unwrap ( ) ;
615
+ let parsed_doc = documents
612
616
. get ( & params. path )
613
617
. ok_or ( WorkspaceError :: not_found ( ) ) ?;
614
618
@@ -621,7 +625,7 @@ impl Workspace for WorkspaceServer {
621
625
622
626
let schema_cache = self . schema_cache . load ( pool) ?;
623
627
624
- match get_statement_for_completions ( & parsed_doc, params. position ) {
628
+ match get_statement_for_completions ( parsed_doc, params. position ) {
625
629
None => {
626
630
tracing:: debug!( "No statement found." ) ;
627
631
Ok ( CompletionsResult :: default ( ) )
0 commit comments