@@ -2,70 +2,68 @@ use hir::{Problem, source_binder};
2
2
use ra_ide_api_light:: Severity ;
3
3
use ra_db:: SourceDatabase ;
4
4
5
- use crate :: { db , Diagnostic , FileId , FileSystemEdit , SourceChange } ;
5
+ use crate :: { Diagnostic , FileId , FileSystemEdit , SourceChange , db :: RootDatabase } ;
6
6
7
- impl db:: RootDatabase {
8
- pub ( crate ) fn diagnostics ( & self , file_id : FileId ) -> Vec < Diagnostic > {
9
- let syntax = self . parse ( file_id) ;
7
+ pub ( crate ) fn diagnostics ( db : & RootDatabase , file_id : FileId ) -> Vec < Diagnostic > {
8
+ let syntax = db. parse ( file_id) ;
10
9
11
- let mut res = ra_ide_api_light:: diagnostics ( & syntax)
12
- . into_iter ( )
13
- . map ( |d| Diagnostic {
14
- range : d. range ,
15
- message : d. msg ,
16
- severity : d. severity ,
17
- fix : d. fix . map ( |fix| SourceChange :: from_local_edit ( file_id, fix) ) ,
18
- } )
19
- . collect :: < Vec < _ > > ( ) ;
20
- if let Some ( m) = source_binder:: module_from_file_id ( self , file_id) {
21
- for ( name_node, problem) in m. problems ( self ) {
22
- let source_root = self . file_source_root ( file_id) ;
23
- let diag = match problem {
24
- Problem :: UnresolvedModule { candidate } => {
25
- let create_file = FileSystemEdit :: CreateFile {
26
- source_root,
27
- path : candidate. clone ( ) ,
28
- } ;
29
- let fix = SourceChange {
30
- label : "create module" . to_string ( ) ,
31
- source_file_edits : Vec :: new ( ) ,
32
- file_system_edits : vec ! [ create_file] ,
33
- cursor_position : None ,
34
- } ;
35
- Diagnostic {
36
- range : name_node. range ( ) ,
37
- message : "unresolved module" . to_string ( ) ,
38
- severity : Severity :: Error ,
39
- fix : Some ( fix) ,
40
- }
10
+ let mut res = ra_ide_api_light:: diagnostics ( & syntax)
11
+ . into_iter ( )
12
+ . map ( |d| Diagnostic {
13
+ range : d. range ,
14
+ message : d. msg ,
15
+ severity : d. severity ,
16
+ fix : d. fix . map ( |fix| SourceChange :: from_local_edit ( file_id, fix) ) ,
17
+ } )
18
+ . collect :: < Vec < _ > > ( ) ;
19
+ if let Some ( m) = source_binder:: module_from_file_id ( db, file_id) {
20
+ for ( name_node, problem) in m. problems ( db) {
21
+ let source_root = db. file_source_root ( file_id) ;
22
+ let diag = match problem {
23
+ Problem :: UnresolvedModule { candidate } => {
24
+ let create_file = FileSystemEdit :: CreateFile {
25
+ source_root,
26
+ path : candidate. clone ( ) ,
27
+ } ;
28
+ let fix = SourceChange {
29
+ label : "create module" . to_string ( ) ,
30
+ source_file_edits : Vec :: new ( ) ,
31
+ file_system_edits : vec ! [ create_file] ,
32
+ cursor_position : None ,
33
+ } ;
34
+ Diagnostic {
35
+ range : name_node. range ( ) ,
36
+ message : "unresolved module" . to_string ( ) ,
37
+ severity : Severity :: Error ,
38
+ fix : Some ( fix) ,
41
39
}
42
- Problem :: NotDirOwner { move_to , candidate } => {
43
- let move_file = FileSystemEdit :: MoveFile {
44
- src : file_id ,
45
- dst_source_root : source_root ,
46
- dst_path : move_to . clone ( ) ,
47
- } ;
48
- let create_file = FileSystemEdit :: CreateFile {
49
- source_root ,
50
- path : move_to . join ( candidate ) ,
51
- } ;
52
- let fix = SourceChange {
53
- label : "move file and create module" . to_string ( ) ,
54
- source_file_edits : Vec :: new ( ) ,
55
- file_system_edits : vec ! [ move_file , create_file ] ,
56
- cursor_position : None ,
57
- } ;
58
- Diagnostic {
59
- range : name_node . range ( ) ,
60
- message : "can't declare module at this location" . to_string ( ) ,
61
- severity : Severity :: Error ,
62
- fix : Some ( fix ) ,
63
- }
40
+ }
41
+ Problem :: NotDirOwner { move_to , candidate } => {
42
+ let move_file = FileSystemEdit :: MoveFile {
43
+ src : file_id ,
44
+ dst_source_root : source_root ,
45
+ dst_path : move_to . clone ( ) ,
46
+ } ;
47
+ let create_file = FileSystemEdit :: CreateFile {
48
+ source_root ,
49
+ path : move_to . join ( candidate ) ,
50
+ } ;
51
+ let fix = SourceChange {
52
+ label : "move file and create module" . to_string ( ) ,
53
+ source_file_edits : Vec :: new ( ) ,
54
+ file_system_edits : vec ! [ move_file , create_file ] ,
55
+ cursor_position : None ,
56
+ } ;
57
+ Diagnostic {
58
+ range : name_node . range ( ) ,
59
+ message : "can't declare module at this location" . to_string ( ) ,
60
+ severity : Severity :: Error ,
61
+ fix : Some ( fix ) ,
64
62
}
65
- } ;
66
- res . push ( diag )
67
- }
68
- } ;
69
- res
70
- }
63
+ }
64
+ } ;
65
+ res . push ( diag )
66
+ }
67
+ } ;
68
+ res
71
69
}
0 commit comments