@@ -7,6 +7,7 @@ use lib_ruby_parser::source::DecodedInput;
77use lib_ruby_parser:: { nodes:: * , Node , Parser , ParserOptions , Loc } ;
88use log:: info;
99use phf:: phf_map;
10+ use tower_lsp:: Client ;
1011use tower_lsp:: lsp_types:: InitializeParams ;
1112use std:: collections:: { HashMap , HashSet } ;
1213use std:: fs;
@@ -149,6 +150,7 @@ pub struct Persistence {
149150 gems_indexed : bool ,
150151 index_interface_only : bool ,
151152 class_scope : Vec < String > ,
153+ pub report_diagnostics : bool ,
152154}
153155
154156struct SchemaFields {
@@ -269,6 +271,7 @@ impl Persistence {
269271 let gems_indexed = false ;
270272 let index_interface_only = false ;
271273 let class_scope = vec ! [ ] ;
274+ let report_diagnostics = true ;
272275
273276 Ok ( Self {
274277 schema,
@@ -282,6 +285,7 @@ impl Persistence {
282285 gems_indexed,
283286 index_interface_only,
284287 class_scope,
288+ report_diagnostics,
285289 } )
286290 }
287291
@@ -313,6 +317,11 @@ impl Persistence {
313317 if skip_indexing_gems {
314318 self . gems_indexed = true ;
315319 }
320+
321+ let report_diagnostics = user_config. get ( "reportDiagnostics" ) . unwrap ( ) . as_bool ( ) . unwrap ( ) ;
322+ if !report_diagnostics {
323+ self . report_diagnostics = false ;
324+ }
316325 }
317326
318327 pub fn reindex_modified_files ( & mut self ) -> tantivy:: Result < ( ) > {
@@ -378,7 +387,7 @@ impl Persistence {
378387 let files_deleted = self . indexed_file_paths . len ( ) > 0 ;
379388
380389 if files_added || files_deleted {
381- let mut index_writer = index. writer ( 100_000_000 ) . unwrap ( ) ;
390+ let mut index_writer = index. writer ( 256_000_000 ) . unwrap ( ) ;
382391
383392 for path in & self . indexed_file_paths {
384393 let relative_path = path. replace ( & self . workspace_path , "" ) ;
@@ -470,11 +479,9 @@ impl Persistence {
470479 }
471480 } ;
472481
473- let mut index_writer = index. writer ( 100_000_000 ) . unwrap ( ) ;
482+ let mut index_writer = index. writer ( 256_000_000 ) . unwrap ( ) ;
474483
475484 for gem_path in gem_paths {
476- info ! ( "Starting indexing gem path: {:#?}" , gem_path) ;
477-
478485 let walk_dir = WalkDirGeneric :: < ( usize , bool ) > :: new ( gem_path. clone ( ) ) . process_read_dir (
479486 move |_depth, _path, _read_dir_state, children| {
480487 children. retain ( |dir_entry_result| {
@@ -527,8 +534,6 @@ impl Persistence {
527534 self . reindex_modified_file_without_commit ( & text, relative_path, & index_writer, false ) ;
528535 }
529536 }
530-
531- info ! ( "Finished indexing gem path: {:#?}" , gem_path) ;
532537 }
533538
534539 index_writer. commit ( ) . unwrap ( ) ;
@@ -618,23 +623,43 @@ impl Persistence {
618623 }
619624 }
620625
621- pub fn reindex_modified_file (
626+ pub async fn reindex_modified_file (
622627 & mut self ,
628+ client : & Client ,
623629 text : & String ,
624630 uri : & Url ,
625- ) -> tantivy:: Result < Vec < Option < tower_lsp:: lsp_types:: Diagnostic > > > {
626- if let Some ( index) = & self . index {
627- let mut index_writer = index. writer ( 100_000_000 ) ?;
628- let mut documents = Vec :: new ( ) ;
631+ ) {
632+ let mut documents = Vec :: new ( ) ;
633+ let diagnostics = match self . parse ( text, & mut documents) {
634+ Ok ( diagnostics) => diagnostics,
635+ Err ( diagnostics) => {
636+ // Return early so existing documents are not deleted when
637+ // there is a syntax error
638+ // return Ok(diagnostics);
639+ diagnostics
640+ }
641+ } ;
629642
630- let diagnostics = match self . parse ( text , & mut documents ) {
631- Ok ( diagnostics ) => diagnostics ,
632- Err ( diagnostics ) => {
633- // Return early so existing documents are not deleted when
634- // there is a syntax error
635- return Ok ( diagnostics ) ;
643+ if self . report_diagnostics {
644+ let mut reported_diagnostics = vec ! [ ] ;
645+
646+ for diagnostic in & diagnostics {
647+ for unwrapped_diagnostic in diagnostic {
648+ reported_diagnostics . push ( unwrapped_diagnostic . clone ( ) ) ;
636649 }
637- } ;
650+ }
651+
652+ client
653+ . publish_diagnostics ( uri. clone ( ) , reported_diagnostics, None ) . await ;
654+ // .await;
655+ }
656+
657+ if diagnostics. len ( ) > 0 {
658+ return ;
659+ }
660+
661+ if let Some ( index) = & self . index {
662+ let mut index_writer = index. writer_with_num_threads ( 1 , 30_000_000 ) . unwrap ( ) ;
638663
639664 let user_space: bool ;
640665 let relative_path: String ;
@@ -700,14 +725,10 @@ impl Persistence {
700725 fuzzy_doc. add_u64 ( self . schema_fields . columns_field , col as u64 ) ;
701726 }
702727
703- index_writer. add_document ( fuzzy_doc) ? ;
728+ index_writer. add_document ( fuzzy_doc) . unwrap ( ) ;
704729 }
705730
706- index_writer. commit ( ) ?;
707-
708- Ok ( diagnostics)
709- } else {
710- Ok ( vec ! [ ] )
731+ index_writer. commit ( ) . unwrap ( ) ;
711732 }
712733 }
713734
@@ -717,14 +738,9 @@ impl Persistence {
717738 _uri : & Url ,
718739 ) -> tantivy:: Result < Vec < Option < tower_lsp:: lsp_types:: Diagnostic > > > {
719740 let mut documents = Vec :: new ( ) ;
720-
721- if let Some ( _) = & self . index {
722- match self . parse ( text, & mut documents) {
723- Ok ( diagnostics) => Ok ( diagnostics) ,
724- Err ( diagnostics) => Ok ( diagnostics) ,
725- }
726- } else {
727- Ok ( Vec :: new ( ) )
741+ match self . parse ( text, & mut documents) {
742+ Ok ( diagnostics) => Ok ( diagnostics) ,
743+ Err ( diagnostics) => Ok ( diagnostics) ,
728744 }
729745 }
730746
0 commit comments