11use std:: {
2+ collections:: HashMap ,
23 fs,
34 panic:: RefUnwindSafe ,
45 path:: { Path , PathBuf } ,
@@ -8,7 +9,6 @@ use std::{
89use analyser:: AnalyserVisitorBuilder ;
910use async_helper:: run_async;
1011use connection_manager:: ConnectionManager ;
11- use dashmap:: DashMap ;
1212use document:: {
1313 AsyncDiagnosticsMapper , CursorPositionFilter , DefaultMapper , Document , ExecuteStatementMapper ,
1414 SyncDiagnosticsMapper ,
@@ -67,7 +67,7 @@ pub(super) struct WorkspaceServer {
6767 /// Stores the schema cache for this workspace
6868 schema_cache : SchemaCacheManager ,
6969
70- documents : DashMap < PgTPath , Document > ,
70+ documents : RwLock < HashMap < PgTPath , Document > > ,
7171
7272 connection : ConnectionManager ,
7373}
@@ -89,7 +89,7 @@ impl WorkspaceServer {
8989 pub ( crate ) fn new ( ) -> Self {
9090 Self {
9191 settings : RwLock :: default ( ) ,
92- documents : DashMap :: default ( ) ,
92+ documents : RwLock :: new ( HashMap :: new ( ) ) ,
9393 schema_cache : SchemaCacheManager :: new ( ) ,
9494 connection : ConnectionManager :: new ( ) ,
9595 }
@@ -262,7 +262,8 @@ impl Workspace for WorkspaceServer {
262262 /// Add a new file to the workspace
263263 #[ tracing:: instrument( level = "info" , skip_all, fields( path = params. path. as_path( ) . as_os_str( ) . to_str( ) ) , err) ]
264264 fn open_file ( & self , params : OpenFileParams ) -> Result < ( ) , WorkspaceError > {
265- self . documents
265+ let mut documents = self . documents . write ( ) . unwrap ( ) ;
266+ documents
266267 . entry ( params. path . clone ( ) )
267268 . or_insert_with ( || Document :: new ( params. content , params. version ) ) ;
268269
@@ -275,7 +276,8 @@ impl Workspace for WorkspaceServer {
275276
276277 /// Remove a file from the workspace
277278 fn close_file ( & self , params : super :: CloseFileParams ) -> Result < ( ) , WorkspaceError > {
278- self . documents
279+ let mut documents = self . documents . write ( ) . unwrap ( ) ;
280+ documents
279281 . remove ( & params. path )
280282 . ok_or_else ( WorkspaceError :: not_found) ?;
281283
@@ -288,13 +290,15 @@ impl Workspace for WorkspaceServer {
288290 version = params. version
289291 ) , err) ]
290292 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) => {
293297 entry
294298 . get_mut ( )
295299 . update_content ( params. content , params. version ) ;
296300 }
297- dashmap :: mapref :: entry :: Entry :: Vacant ( entry) => {
301+ std :: collections :: hash_map :: Entry :: Vacant ( entry) => {
298302 entry. insert ( Document :: new ( params. content , params. version ) ) ;
299303 }
300304 }
@@ -307,8 +311,8 @@ impl Workspace for WorkspaceServer {
307311 }
308312
309313 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
312316 . get ( & params. path )
313317 . ok_or ( WorkspaceError :: not_found ( ) ) ?;
314318 Ok ( document. get_document_content ( ) . to_string ( ) )
@@ -322,8 +326,8 @@ impl Workspace for WorkspaceServer {
322326 & self ,
323327 params : code_actions:: CodeActionsParams ,
324328 ) -> Result < code_actions:: CodeActionsResult , WorkspaceError > {
325- let parser = self
326- . documents
329+ let documents = self . documents . read ( ) . unwrap ( ) ;
330+ let parser = documents
327331 . get ( & params. path )
328332 . ok_or ( WorkspaceError :: not_found ( ) ) ?;
329333
@@ -364,8 +368,8 @@ impl Workspace for WorkspaceServer {
364368 & self ,
365369 params : ExecuteStatementParams ,
366370 ) -> Result < ExecuteStatementResult , WorkspaceError > {
367- let parser = self
368- . documents
371+ let documents = self . documents . read ( ) . unwrap ( ) ;
372+ let parser = documents
369373 . get ( & params. path )
370374 . ok_or ( WorkspaceError :: not_found ( ) ) ?;
371375
@@ -422,8 +426,8 @@ impl Workspace for WorkspaceServer {
422426 }
423427 } ;
424428
425- let doc = self
426- . documents
429+ let documents = self . documents . read ( ) . unwrap ( ) ;
430+ let doc = documents
427431 . get ( & params. path )
428432 . ok_or ( WorkspaceError :: not_found ( ) ) ?;
429433
@@ -607,8 +611,8 @@ impl Workspace for WorkspaceServer {
607611 & self ,
608612 params : GetCompletionsParams ,
609613 ) -> Result < CompletionsResult , WorkspaceError > {
610- let parsed_doc = self
611- . documents
614+ let documents = self . documents . read ( ) . unwrap ( ) ;
615+ let parsed_doc = documents
612616 . get ( & params. path )
613617 . ok_or ( WorkspaceError :: not_found ( ) ) ?;
614618
@@ -621,7 +625,7 @@ impl Workspace for WorkspaceServer {
621625
622626 let schema_cache = self . schema_cache . load ( pool) ?;
623627
624- match get_statement_for_completions ( & parsed_doc, params. position ) {
628+ match get_statement_for_completions ( parsed_doc, params. position ) {
625629 None => {
626630 tracing:: debug!( "No statement found." ) ;
627631 Ok ( CompletionsResult :: default ( ) )
0 commit comments