@@ -9,18 +9,18 @@ use crate::{
9
9
Module , ModuleSource , Static , Struct , StructField , Trait , TypeAlias , Union ,
10
10
} ;
11
11
12
- pub use hir_expand:: Source ;
12
+ pub use hir_expand:: InFile ;
13
13
14
14
pub trait HasSource {
15
15
type Ast ;
16
- fn source ( self , db : & impl DefDatabase ) -> Source < Self :: Ast > ;
16
+ fn source ( self , db : & impl DefDatabase ) -> InFile < Self :: Ast > ;
17
17
}
18
18
19
19
/// NB: Module is !HasSource, because it has two source nodes at the same time:
20
20
/// definition and declaration.
21
21
impl Module {
22
22
/// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
23
- pub fn definition_source ( self , db : & impl DefDatabase ) -> Source < ModuleSource > {
23
+ pub fn definition_source ( self , db : & impl DefDatabase ) -> InFile < ModuleSource > {
24
24
let def_map = db. crate_def_map ( self . id . krate ) ;
25
25
let src = def_map[ self . id . local_id ] . definition_source ( db) ;
26
26
src. map ( |it| match it {
@@ -31,15 +31,15 @@ impl Module {
31
31
32
32
/// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
33
33
/// `None` for the crate root.
34
- pub fn declaration_source ( self , db : & impl DefDatabase ) -> Option < Source < ast:: Module > > {
34
+ pub fn declaration_source ( self , db : & impl DefDatabase ) -> Option < InFile < ast:: Module > > {
35
35
let def_map = db. crate_def_map ( self . id . krate ) ;
36
36
def_map[ self . id . local_id ] . declaration_source ( db)
37
37
}
38
38
}
39
39
40
40
impl HasSource for StructField {
41
41
type Ast = FieldSource ;
42
- fn source ( self , db : & impl DefDatabase ) -> Source < FieldSource > {
42
+ fn source ( self , db : & impl DefDatabase ) -> InFile < FieldSource > {
43
43
let var = VariantId :: from ( self . parent ) ;
44
44
let src = var. child_source ( db) ;
45
45
src. map ( |it| match it[ self . id ] . clone ( ) {
@@ -50,75 +50,75 @@ impl HasSource for StructField {
50
50
}
51
51
impl HasSource for Struct {
52
52
type Ast = ast:: StructDef ;
53
- fn source ( self , db : & impl DefDatabase ) -> Source < ast:: StructDef > {
53
+ fn source ( self , db : & impl DefDatabase ) -> InFile < ast:: StructDef > {
54
54
self . id . source ( db)
55
55
}
56
56
}
57
57
impl HasSource for Union {
58
58
type Ast = ast:: UnionDef ;
59
- fn source ( self , db : & impl DefDatabase ) -> Source < ast:: UnionDef > {
59
+ fn source ( self , db : & impl DefDatabase ) -> InFile < ast:: UnionDef > {
60
60
self . id . source ( db)
61
61
}
62
62
}
63
63
impl HasSource for Enum {
64
64
type Ast = ast:: EnumDef ;
65
- fn source ( self , db : & impl DefDatabase ) -> Source < ast:: EnumDef > {
65
+ fn source ( self , db : & impl DefDatabase ) -> InFile < ast:: EnumDef > {
66
66
self . id . source ( db)
67
67
}
68
68
}
69
69
impl HasSource for EnumVariant {
70
70
type Ast = ast:: EnumVariant ;
71
- fn source ( self , db : & impl DefDatabase ) -> Source < ast:: EnumVariant > {
71
+ fn source ( self , db : & impl DefDatabase ) -> InFile < ast:: EnumVariant > {
72
72
self . parent . id . child_source ( db) . map ( |map| map[ self . id ] . clone ( ) )
73
73
}
74
74
}
75
75
impl HasSource for Function {
76
76
type Ast = ast:: FnDef ;
77
- fn source ( self , db : & impl DefDatabase ) -> Source < ast:: FnDef > {
77
+ fn source ( self , db : & impl DefDatabase ) -> InFile < ast:: FnDef > {
78
78
self . id . lookup ( db) . source ( db)
79
79
}
80
80
}
81
81
impl HasSource for Const {
82
82
type Ast = ast:: ConstDef ;
83
- fn source ( self , db : & impl DefDatabase ) -> Source < ast:: ConstDef > {
83
+ fn source ( self , db : & impl DefDatabase ) -> InFile < ast:: ConstDef > {
84
84
self . id . lookup ( db) . source ( db)
85
85
}
86
86
}
87
87
impl HasSource for Static {
88
88
type Ast = ast:: StaticDef ;
89
- fn source ( self , db : & impl DefDatabase ) -> Source < ast:: StaticDef > {
89
+ fn source ( self , db : & impl DefDatabase ) -> InFile < ast:: StaticDef > {
90
90
self . id . lookup ( db) . source ( db)
91
91
}
92
92
}
93
93
impl HasSource for Trait {
94
94
type Ast = ast:: TraitDef ;
95
- fn source ( self , db : & impl DefDatabase ) -> Source < ast:: TraitDef > {
95
+ fn source ( self , db : & impl DefDatabase ) -> InFile < ast:: TraitDef > {
96
96
self . id . source ( db)
97
97
}
98
98
}
99
99
impl HasSource for TypeAlias {
100
100
type Ast = ast:: TypeAliasDef ;
101
- fn source ( self , db : & impl DefDatabase ) -> Source < ast:: TypeAliasDef > {
101
+ fn source ( self , db : & impl DefDatabase ) -> InFile < ast:: TypeAliasDef > {
102
102
self . id . lookup ( db) . source ( db)
103
103
}
104
104
}
105
105
impl HasSource for MacroDef {
106
106
type Ast = ast:: MacroCall ;
107
- fn source ( self , db : & impl DefDatabase ) -> Source < ast:: MacroCall > {
108
- Source { file_id : self . id . ast_id . file_id ( ) , value : self . id . ast_id . to_node ( db) }
107
+ fn source ( self , db : & impl DefDatabase ) -> InFile < ast:: MacroCall > {
108
+ InFile { file_id : self . id . ast_id . file_id ( ) , value : self . id . ast_id . to_node ( db) }
109
109
}
110
110
}
111
111
impl HasSource for ImplBlock {
112
112
type Ast = ast:: ImplBlock ;
113
- fn source ( self , db : & impl DefDatabase ) -> Source < ast:: ImplBlock > {
113
+ fn source ( self , db : & impl DefDatabase ) -> InFile < ast:: ImplBlock > {
114
114
self . id . source ( db)
115
115
}
116
116
}
117
117
impl HasSource for Import {
118
118
type Ast = Either < ast:: UseTree , ast:: ExternCrateItem > ;
119
119
120
120
/// Returns the syntax of the last path segment corresponding to this import
121
- fn source ( self , db : & impl DefDatabase ) -> Source < Self :: Ast > {
121
+ fn source ( self , db : & impl DefDatabase ) -> InFile < Self :: Ast > {
122
122
let src = self . parent . definition_source ( db) ;
123
123
let ( _, source_map) = db. raw_items_with_source_map ( src. file_id ) ;
124
124
let root = db. parse_or_expand ( src. file_id ) . unwrap ( ) ;
0 commit comments