@@ -15,7 +15,7 @@ use hir_def::{
15
15
hir:: { ExprId , PatId } ,
16
16
} ;
17
17
use hir_ty:: { Interner , Substitution , TyExt , TypeFlags } ;
18
- use ide:: { LineCol , RootDatabase } ;
18
+ use ide:: { Analysis , AnnotationConfig , DiagnosticsConfig , InlayHintsConfig , LineCol , RootDatabase } ;
19
19
use ide_db:: {
20
20
base_db:: {
21
21
salsa:: { self , debug:: DebugQueryTable , ParallelDatabase } ,
@@ -30,7 +30,7 @@ use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSourc
30
30
use rayon:: prelude:: * ;
31
31
use rustc_hash:: FxHashSet ;
32
32
use syntax:: { AstNode , SyntaxNode } ;
33
- use vfs:: { AbsPathBuf , Vfs , VfsPath } ;
33
+ use vfs:: { AbsPathBuf , FileId , Vfs , VfsPath } ;
34
34
35
35
use crate :: cli:: {
36
36
flags:: { self , OutputFormat } ,
@@ -149,8 +149,10 @@ impl flags::AnalysisStats {
149
149
let mut bodies = Vec :: new ( ) ;
150
150
let mut adts = Vec :: new ( ) ;
151
151
let mut consts = Vec :: new ( ) ;
152
+ let mut file_ids = Vec :: new ( ) ;
152
153
while let Some ( module) = visit_queue. pop ( ) {
153
154
if visited_modules. insert ( module) {
155
+ file_ids. extend ( module. as_source_file_id ( db) ) ;
154
156
visit_queue. extend ( module. children ( db) ) ;
155
157
156
158
for decl in module. declarations ( db) {
@@ -224,6 +226,10 @@ impl flags::AnalysisStats {
224
226
self . run_const_eval ( db, & consts, verbosity) ;
225
227
}
226
228
229
+ if self . run_all_ide_things {
230
+ self . run_ide_things ( host. analysis ( ) , file_ids) ;
231
+ }
232
+
227
233
let total_span = analysis_sw. elapsed ( ) ;
228
234
eprintln ! ( "{:<20} {total_span}" , "Total:" ) ;
229
235
report_metric ( "total time" , total_span. time . as_millis ( ) as u64 , "ms" ) ;
@@ -729,6 +735,83 @@ impl flags::AnalysisStats {
729
735
report_metric ( "body lowering time" , body_lowering_time. time . as_millis ( ) as u64 , "ms" ) ;
730
736
}
731
737
738
+ fn run_ide_things ( & self , analysis : Analysis , mut file_ids : Vec < FileId > ) {
739
+ file_ids. sort ( ) ;
740
+ file_ids. dedup ( ) ;
741
+ let mut sw = self . stop_watch ( ) ;
742
+
743
+ for & file_id in & file_ids {
744
+ _ = analysis. diagnostics (
745
+ & DiagnosticsConfig {
746
+ enabled : true ,
747
+ proc_macros_enabled : true ,
748
+ proc_attr_macros_enabled : true ,
749
+ disable_experimental : false ,
750
+ disabled : Default :: default ( ) ,
751
+ expr_fill_default : Default :: default ( ) ,
752
+ insert_use : ide_db:: imports:: insert_use:: InsertUseConfig {
753
+ granularity : ide_db:: imports:: insert_use:: ImportGranularity :: Crate ,
754
+ enforce_granularity : true ,
755
+ prefix_kind : hir:: PrefixKind :: ByCrate ,
756
+ group : true ,
757
+ skip_glob_imports : true ,
758
+ } ,
759
+ prefer_no_std : Default :: default ( ) ,
760
+ } ,
761
+ ide:: AssistResolveStrategy :: All ,
762
+ file_id,
763
+ ) ;
764
+ }
765
+ for & file_id in & file_ids {
766
+ _ = analysis. inlay_hints (
767
+ & InlayHintsConfig {
768
+ render_colons : false ,
769
+ type_hints : true ,
770
+ discriminant_hints : ide:: DiscriminantHints :: Always ,
771
+ parameter_hints : true ,
772
+ chaining_hints : true ,
773
+ adjustment_hints : ide:: AdjustmentHints :: Always ,
774
+ adjustment_hints_mode : ide:: AdjustmentHintsMode :: Postfix ,
775
+ adjustment_hints_hide_outside_unsafe : false ,
776
+ closure_return_type_hints : ide:: ClosureReturnTypeHints :: Always ,
777
+ closure_capture_hints : true ,
778
+ binding_mode_hints : true ,
779
+ lifetime_elision_hints : ide:: LifetimeElisionHints :: Always ,
780
+ param_names_for_lifetime_elision_hints : true ,
781
+ hide_named_constructor_hints : false ,
782
+ hide_closure_initialization_hints : false ,
783
+ closure_style : hir:: ClosureStyle :: ImplFn ,
784
+ max_length : Some ( 25 ) ,
785
+ closing_brace_hints_min_lines : Some ( 20 ) ,
786
+ } ,
787
+ file_id,
788
+ None ,
789
+ ) ;
790
+ }
791
+ for & file_id in & file_ids {
792
+ analysis
793
+ . annotations (
794
+ & AnnotationConfig {
795
+ binary_target : true ,
796
+ annotate_runnables : true ,
797
+ annotate_impls : true ,
798
+ annotate_references : false ,
799
+ annotate_method_references : false ,
800
+ annotate_enum_variant_references : false ,
801
+ location : ide:: AnnotationLocation :: AboveName ,
802
+ } ,
803
+ file_id,
804
+ )
805
+ . unwrap ( )
806
+ . into_iter ( )
807
+ . for_each ( |annotation| {
808
+ _ = analysis. resolve_annotation ( annotation) ;
809
+ } ) ;
810
+ }
811
+ let ide_time = sw. elapsed ( ) ;
812
+ eprintln ! ( "{:<20} {} ({} files)" , "IDE:" , ide_time, file_ids. len( ) ) ;
813
+ }
814
+
732
815
fn stop_watch ( & self ) -> StopWatch {
733
816
StopWatch :: start ( ) . memory ( self . memory_usage )
734
817
}
0 commit comments