@@ -22,6 +22,7 @@ use tower_lsp_server::{
2222mod capabilities;
2323mod code_actions;
2424mod commands;
25+ mod file_system;
2526mod formatter;
2627mod linter;
2728mod options;
@@ -36,6 +37,8 @@ use linter::server_linter::ServerLinterRun;
3637use options:: { Options , WorkspaceOption } ;
3738use worker:: WorkspaceWorker ;
3839
40+ use crate :: file_system:: LSPFileSystem ;
41+
3942type ConcurrentHashMap < K , V > = papaya:: HashMap < K , V , FxBuildHasher > ;
4043
4144const OXC_CONFIG_FILE : & str = ".oxlintrc.json" ;
@@ -51,6 +54,7 @@ struct Backend {
5154 // 2. `workspace/didChangeWorkspaceFolders` request
5255 workspace_workers : Arc < RwLock < Vec < WorkspaceWorker > > > ,
5356 capabilities : OnceCell < Capabilities > ,
57+ file_system : Arc < RwLock < LSPFileSystem > > ,
5458}
5559
5660impl LanguageServer for Backend {
@@ -203,6 +207,7 @@ impl LanguageServer for Backend {
203207
204208 async fn shutdown ( & self ) -> Result < ( ) > {
205209 self . clear_all_diagnostics ( ) . await ;
210+ self . file_system . write ( ) . await . clear ( ) ;
206211 Ok ( ( ) )
207212 }
208213
@@ -444,6 +449,10 @@ impl LanguageServer for Backend {
444449 let Some ( worker) = workers. iter ( ) . find ( |worker| worker. is_responsible_for_uri ( uri) ) else {
445450 return ;
446451 } ;
452+
453+ // saving the file means we can read again from the file system
454+ self . file_system . write ( ) . await . remove ( uri) ;
455+
447456 if let Some ( diagnostics) = worker. lint_file ( uri, None , ServerLinterRun :: OnSave ) . await {
448457 self . client
449458 . publish_diagnostics (
@@ -464,6 +473,11 @@ impl LanguageServer for Backend {
464473 return ;
465474 } ;
466475 let content = params. content_changes . first ( ) . map ( |c| c. text . clone ( ) ) ;
476+
477+ if let Some ( content) = & content {
478+ self . file_system . write ( ) . await . set ( uri, content. to_string ( ) ) ;
479+ }
480+
467481 if let Some ( diagnostics) = worker. lint_file ( uri, content, ServerLinterRun :: OnType ) . await {
468482 self . client
469483 . publish_diagnostics (
@@ -483,6 +497,9 @@ impl LanguageServer for Backend {
483497 } ;
484498
485499 let content = params. text_document . text ;
500+
501+ self . file_system . write ( ) . await . set ( uri, content. to_string ( ) ) ;
502+
486503 if let Some ( diagnostics) =
487504 worker. lint_file ( uri, Some ( content) , ServerLinterRun :: Always ) . await
488505 {
@@ -502,6 +519,7 @@ impl LanguageServer for Backend {
502519 let Some ( worker) = workers. iter ( ) . find ( |worker| worker. is_responsible_for_uri ( uri) ) else {
503520 return ;
504521 } ;
522+ self . file_system . write ( ) . await . remove ( uri) ;
505523 worker. remove_diagnostics ( & params. text_document . uri ) . await ;
506524 }
507525
@@ -626,6 +644,7 @@ async fn main() {
626644 client,
627645 workspace_workers : Arc :: new ( RwLock :: new ( vec ! [ ] ) ) ,
628646 capabilities : OnceCell :: new ( ) ,
647+ file_system : Arc :: new ( RwLock :: new ( LSPFileSystem :: new ( ) ) ) ,
629648 } )
630649 . finish ( ) ;
631650
0 commit comments