@@ -21,12 +21,11 @@ use std::borrow::Cow;
21
21
use std:: path:: { Path , PathBuf } ;
22
22
use triomphe:: Arc ;
23
23
pub enum RustAnalyzer < ' a > {
24
- WithDatabase {
25
- db : & ' a RootDatabase ,
24
+ WithSemantics {
26
25
vfs : & ' a Vfs ,
27
26
semantics : Semantics < ' a , RootDatabase > ,
28
27
} ,
29
- WithoutDatabase ( ) ,
28
+ WithoutSemantics ,
30
29
}
31
30
pub struct ParseResult {
32
31
pub ast : SourceFile ,
@@ -62,31 +61,28 @@ impl<'a> RustAnalyzer<'a> {
62
61
}
63
62
}
64
63
}
65
- pub fn new ( db : & ' a RootDatabase , vfs : & ' a Vfs , semantics : Semantics < ' a , RootDatabase > ) -> Self {
66
- RustAnalyzer :: WithDatabase { db , vfs, semantics }
64
+ pub fn new ( vfs : & ' a Vfs , semantics : Semantics < ' a , RootDatabase > ) -> Self {
65
+ RustAnalyzer :: WithSemantics { vfs, semantics }
67
66
}
68
67
pub fn semantics ( & ' a self ) -> Option < & ' a Semantics < ' a , RootDatabase > > {
69
68
match self {
70
- RustAnalyzer :: WithDatabase {
71
- db : _,
72
- vfs : _,
73
- semantics,
74
- } => Some ( semantics) ,
75
- RustAnalyzer :: WithoutDatabase ( ) => None ,
69
+ RustAnalyzer :: WithSemantics { vfs : _, semantics } => Some ( semantics) ,
70
+ RustAnalyzer :: WithoutSemantics => None ,
76
71
}
77
72
}
78
73
pub fn parse ( & self , path : & Path ) -> ParseResult {
79
- if let RustAnalyzer :: WithDatabase { vfs, db , semantics } = self {
74
+ if let RustAnalyzer :: WithSemantics { vfs, semantics } = self {
80
75
if let Some ( file_id) = Utf8PathBuf :: from_path_buf ( path. to_path_buf ( ) )
81
76
. ok ( )
82
77
. and_then ( |x| AbsPathBuf :: try_from ( x) . ok ( ) )
83
78
. map ( VfsPath :: from)
84
79
. and_then ( |x| vfs. file_id ( & x) )
85
80
{
86
- let input: Arc < str > = db. file_text ( file_id) ;
81
+ let input: Arc < str > = semantics . db . file_text ( file_id) ;
87
82
let file_id = EditionedFileId :: current_edition ( file_id) ;
88
83
let source_file = semantics. parse ( file_id) ;
89
- let errors = db
84
+ let errors = semantics
85
+ . db
90
86
. parse_errors ( file_id)
91
87
. into_iter ( )
92
88
. flat_map ( |x| x. to_vec ( ) )
0 commit comments