1- use std:: collections:: HashMap ;
2- use std:: fs;
3- use std:: path:: { PathBuf } ;
4- use crate :: trap:: { TrapFile , TrapId , AsTrapKeyPart } ;
1+ use crate :: archive:: Archiver ;
2+ use crate :: trap:: { AsTrapKeyPart , TrapFile , TrapId } ;
53use crate :: { generated, trap_key} ;
6- use ra_ap_hir:: { Crate , Module , ModuleDef } ;
74use anyhow;
8- use ra_ap_hir:: { HasSource } ;
9- use ra_ap_vfs:: { AbsPath , FileId , Vfs } ;
5+ use codeql_extractor:: trap;
6+ use ra_ap_hir:: HasSource ;
7+ use ra_ap_hir:: { Crate , Module , ModuleDef } ;
8+ use ra_ap_ide_db:: line_index:: LineIndex ;
9+ use ra_ap_ide_db:: { LineIndexDatabase , RootDatabase } ;
1010use ra_ap_syntax:: ast:: HasName ;
11- use crate :: archive:: Archiver ;
11+ use ra_ap_syntax:: AstNode ;
12+ use ra_ap_vfs:: { AbsPath , FileId , Vfs } ;
13+ use std:: collections:: HashMap ;
14+ use std:: fs;
1215use std:: io:: Result ;
16+ use std:: path:: PathBuf ;
1317use triomphe:: Arc ;
14- use ra_ap_ide_db:: { LineIndexDatabase , RootDatabase } ;
15- use ra_ap_ide_db:: line_index:: LineIndex ;
16- use ra_ap_syntax:: AstNode ;
17- use codeql_extractor:: trap;
1818
1919#[ derive( Clone ) ]
2020struct FileData {
@@ -30,7 +30,6 @@ pub struct CrateTranslator<'a> {
3030 file_labels : HashMap < PathBuf , FileData > ,
3131}
3232
33-
3433impl CrateTranslator < ' _ > {
3534 pub fn new < ' a > (
3635 db : & ' a RootDatabase ,
@@ -56,9 +55,13 @@ impl CrateTranslator<'_> {
5655 self . archiver . archive ( & canonical) ;
5756 canonical = fs:: canonicalize ( & canonical) . unwrap_or ( canonical) ;
5857 let name = canonical. to_string_lossy ( ) ;
59- let label = self . trap . emit ( generated:: DbFile { id : trap_key ! [ "file;" , name. as_ref( ) ] , name : String :: from ( name) } ) ;
58+ let label = self . trap . emit ( generated:: DbFile {
59+ id : trap_key ! [ "file;" , name. as_ref( ) ] ,
60+ name : String :: from ( name) ,
61+ } ) ;
6062 let line_index = <dyn LineIndexDatabase >:: line_index ( self . db , file_id) ;
61- self . file_labels . insert ( canonical. clone ( ) , FileData { label, line_index } ) ;
63+ self . file_labels
64+ . insert ( canonical. clone ( ) , FileData { label, line_index } ) ;
6265 }
6366 self . file_labels . get ( & canonical) . cloned ( )
6467 } )
@@ -68,7 +71,8 @@ impl CrateTranslator<'_> {
6871 where
6972 T :: Ast : AstNode ,
7073 {
71- entity. source ( self . db )
74+ entity
75+ . source ( self . db )
7276 . and_then ( |source| source. file_id . file_id ( ) . map ( |f| ( f. file_id ( ) , source) ) )
7377 . and_then ( |( file_id, source) | self . emit_file ( file_id) . map ( |data| ( data, source) ) )
7478 . and_then ( |( data, source) | {
@@ -79,7 +83,12 @@ impl CrateTranslator<'_> {
7983 } )
8084 }
8185
82- fn emit_definition ( & mut self , module_label : trap:: Label , id : ModuleDef , labels : & mut Vec < trap:: Label > ) {
86+ fn emit_definition (
87+ & mut self ,
88+ module_label : trap:: Label ,
89+ id : ModuleDef ,
90+ labels : & mut Vec < trap:: Label > ,
91+ ) {
8392 match id {
8493 ModuleDef :: Module ( _) => { }
8594 ModuleDef :: Function ( function) => {
@@ -115,7 +124,7 @@ impl CrateTranslator<'_> {
115124 } ) ;
116125 }
117126
118- pub fn emit_crate ( & mut self ) -> std:: io:: Result < ( ) > {
127+ pub fn emit_crate ( & mut self ) -> std:: io:: Result < ( ) > {
119128 self . emit_file ( self . krate . root_file ( self . db ) ) ;
120129 let mut map = HashMap :: < Module , trap:: Label > :: new ( ) ;
121130 for module in self . krate . modules ( self . db ) {
0 commit comments