@@ -22,6 +22,7 @@ use tower_lsp_server::{
22
22
mod capabilities;
23
23
mod code_actions;
24
24
mod commands;
25
+ mod file_system;
25
26
mod formatter;
26
27
mod linter;
27
28
mod options;
@@ -36,6 +37,8 @@ use linter::server_linter::ServerLinterRun;
36
37
use options:: { Options , WorkspaceOption } ;
37
38
use worker:: WorkspaceWorker ;
38
39
40
+ use crate :: file_system:: LSPFileSystem ;
41
+
39
42
type ConcurrentHashMap < K , V > = papaya:: HashMap < K , V , FxBuildHasher > ;
40
43
41
44
const OXC_CONFIG_FILE : & str = ".oxlintrc.json" ;
@@ -51,6 +54,7 @@ struct Backend {
51
54
// 2. `workspace/didChangeWorkspaceFolders` request
52
55
workspace_workers : Arc < RwLock < Vec < WorkspaceWorker > > > ,
53
56
capabilities : OnceCell < Capabilities > ,
57
+ file_system : Arc < RwLock < LSPFileSystem > > ,
54
58
}
55
59
56
60
impl LanguageServer for Backend {
@@ -203,6 +207,7 @@ impl LanguageServer for Backend {
203
207
204
208
async fn shutdown ( & self ) -> Result < ( ) > {
205
209
self . clear_all_diagnostics ( ) . await ;
210
+ self . file_system . write ( ) . await . clear ( ) ;
206
211
Ok ( ( ) )
207
212
}
208
213
@@ -444,6 +449,10 @@ impl LanguageServer for Backend {
444
449
let Some ( worker) = workers. iter ( ) . find ( |worker| worker. is_responsible_for_uri ( uri) ) else {
445
450
return ;
446
451
} ;
452
+
453
+ // saving the file means we can read again from the file system
454
+ self . file_system . write ( ) . await . remove ( uri) ;
455
+
447
456
if let Some ( diagnostics) = worker. lint_file ( uri, None , ServerLinterRun :: OnSave ) . await {
448
457
self . client
449
458
. publish_diagnostics (
@@ -464,6 +473,11 @@ impl LanguageServer for Backend {
464
473
return ;
465
474
} ;
466
475
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
+
467
481
if let Some ( diagnostics) = worker. lint_file ( uri, content, ServerLinterRun :: OnType ) . await {
468
482
self . client
469
483
. publish_diagnostics (
@@ -483,6 +497,9 @@ impl LanguageServer for Backend {
483
497
} ;
484
498
485
499
let content = params. text_document . text ;
500
+
501
+ self . file_system . write ( ) . await . set ( uri, content. to_string ( ) ) ;
502
+
486
503
if let Some ( diagnostics) =
487
504
worker. lint_file ( uri, Some ( content) , ServerLinterRun :: Always ) . await
488
505
{
@@ -502,6 +519,7 @@ impl LanguageServer for Backend {
502
519
let Some ( worker) = workers. iter ( ) . find ( |worker| worker. is_responsible_for_uri ( uri) ) else {
503
520
return ;
504
521
} ;
522
+ self . file_system . write ( ) . await . remove ( uri) ;
505
523
worker. remove_diagnostics ( & params. text_document . uri ) . await ;
506
524
}
507
525
@@ -626,6 +644,7 @@ async fn main() {
626
644
client,
627
645
workspace_workers : Arc :: new ( RwLock :: new ( vec ! [ ] ) ) ,
628
646
capabilities : OnceCell :: new ( ) ,
647
+ file_system : Arc :: new ( RwLock :: new ( LSPFileSystem :: new ( ) ) ) ,
629
648
} )
630
649
. finish ( ) ;
631
650
0 commit comments