aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/from_source.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/from_source.rs')
-rw-r--r--crates/ra_hir/src/from_source.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index 1c26756c9..f4dca25cb 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -87,7 +87,7 @@ impl FromSource for MacroDef {
87 let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; 87 let module = Module::from_definition(db, Source::new(src.file_id, module_src))?;
88 let krate = module.krate().crate_id(); 88 let krate = module.krate().crate_id();
89 89
90 let ast_id = AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.ast)); 90 let ast_id = AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.value));
91 91
92 let id: MacroDefId = MacroDefId { krate, ast_id, kind }; 92 let id: MacroDefId = MacroDefId { krate, ast_id, kind };
93 Some(MacroDef { id }) 93 Some(MacroDef { id })
@@ -105,8 +105,8 @@ impl FromSource for ImplBlock {
105impl FromSource for EnumVariant { 105impl FromSource for EnumVariant {
106 type Ast = ast::EnumVariant; 106 type Ast = ast::EnumVariant;
107 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 107 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
108 let parent_enum = src.ast.parent_enum(); 108 let parent_enum = src.value.parent_enum();
109 let src_enum = Source { file_id: src.file_id, ast: parent_enum }; 109 let src_enum = Source { file_id: src.file_id, value: parent_enum };
110 let variants = Enum::from_source(db, src_enum)?.variants(db); 110 let variants = Enum::from_source(db, src_enum)?.variants(db);
111 variants.into_iter().find(|v| v.source(db) == src) 111 variants.into_iter().find(|v| v.source(db) == src)
112 } 112 }
@@ -115,16 +115,16 @@ impl FromSource for EnumVariant {
115impl FromSource for StructField { 115impl FromSource for StructField {
116 type Ast = FieldSource; 116 type Ast = FieldSource;
117 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 117 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
118 let variant_def: VariantDef = match src.ast { 118 let variant_def: VariantDef = match src.value {
119 FieldSource::Named(ref field) => { 119 FieldSource::Named(ref field) => {
120 let ast = field.syntax().ancestors().find_map(ast::StructDef::cast)?; 120 let value = field.syntax().ancestors().find_map(ast::StructDef::cast)?;
121 let src = Source { file_id: src.file_id, ast }; 121 let src = Source { file_id: src.file_id, value };
122 let def = Struct::from_source(db, src)?; 122 let def = Struct::from_source(db, src)?;
123 VariantDef::from(def) 123 VariantDef::from(def)
124 } 124 }
125 FieldSource::Pos(ref field) => { 125 FieldSource::Pos(ref field) => {
126 let ast = field.syntax().ancestors().find_map(ast::EnumVariant::cast)?; 126 let value = field.syntax().ancestors().find_map(ast::EnumVariant::cast)?;
127 let src = Source { file_id: src.file_id, ast }; 127 let src = Source { file_id: src.file_id, value };
128 let def = EnumVariant::from_source(db, src)?; 128 let def = EnumVariant::from_source(db, src)?;
129 VariantDef::from(def) 129 VariantDef::from(def)
130 } 130 }
@@ -142,12 +142,12 @@ impl FromSource for StructField {
142impl Local { 142impl Local {
143 pub fn from_source(db: &impl HirDatabase, src: Source<ast::BindPat>) -> Option<Self> { 143 pub fn from_source(db: &impl HirDatabase, src: Source<ast::BindPat>) -> Option<Self> {
144 let file_id = src.file_id; 144 let file_id = src.file_id;
145 let parent: DefWithBody = src.ast.syntax().ancestors().find_map(|it| { 145 let parent: DefWithBody = src.value.syntax().ancestors().find_map(|it| {
146 let res = match_ast! { 146 let res = match_ast! {
147 match it { 147 match it {
148 ast::ConstDef(ast) => { Const::from_source(db, Source { ast, file_id})?.into() }, 148 ast::ConstDef(value) => { Const::from_source(db, Source { value, file_id})?.into() },
149 ast::StaticDef(ast) => { Static::from_source(db, Source { ast, file_id})?.into() }, 149 ast::StaticDef(value) => { Static::from_source(db, Source { value, file_id})?.into() },
150 ast::FnDef(ast) => { Function::from_source(db, Source { ast, file_id})?.into() }, 150 ast::FnDef(value) => { Function::from_source(db, Source { value, file_id})?.into() },
151 _ => return None, 151 _ => return None,
152 } 152 }
153 }; 153 };
@@ -162,33 +162,33 @@ impl Local {
162 162
163impl Module { 163impl Module {
164 pub fn from_declaration(db: &impl DefDatabase, src: Source<ast::Module>) -> Option<Self> { 164 pub fn from_declaration(db: &impl DefDatabase, src: Source<ast::Module>) -> Option<Self> {
165 let parent_declaration = src.ast.syntax().ancestors().skip(1).find_map(ast::Module::cast); 165 let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast);
166 166
167 let parent_module = match parent_declaration { 167 let parent_module = match parent_declaration {
168 Some(parent_declaration) => { 168 Some(parent_declaration) => {
169 let src_parent = Source { file_id: src.file_id, ast: parent_declaration }; 169 let src_parent = Source { file_id: src.file_id, value: parent_declaration };
170 Module::from_declaration(db, src_parent) 170 Module::from_declaration(db, src_parent)
171 } 171 }
172 _ => { 172 _ => {
173 let src_parent = Source { 173 let src_parent = Source {
174 file_id: src.file_id, 174 file_id: src.file_id,
175 ast: ModuleSource::new(db, Some(src.file_id.original_file(db)), None), 175 value: ModuleSource::new(db, Some(src.file_id.original_file(db)), None),
176 }; 176 };
177 Module::from_definition(db, src_parent) 177 Module::from_definition(db, src_parent)
178 } 178 }
179 }?; 179 }?;
180 180
181 let child_name = src.ast.name()?; 181 let child_name = src.value.name()?;
182 parent_module.child(db, &child_name.as_name()) 182 parent_module.child(db, &child_name.as_name())
183 } 183 }
184 184
185 pub fn from_definition(db: &impl DefDatabase, src: Source<ModuleSource>) -> Option<Self> { 185 pub fn from_definition(db: &impl DefDatabase, src: Source<ModuleSource>) -> Option<Self> {
186 match src.ast { 186 match src.value {
187 ModuleSource::Module(ref module) => { 187 ModuleSource::Module(ref module) => {
188 assert!(!module.has_semi()); 188 assert!(!module.has_semi());
189 return Module::from_declaration( 189 return Module::from_declaration(
190 db, 190 db,
191 Source { file_id: src.file_id, ast: module.clone() }, 191 Source { file_id: src.file_id, value: module.clone() },
192 ); 192 );
193 } 193 }
194 ModuleSource::SourceFile(_) => (), 194 ModuleSource::SourceFile(_) => (),
@@ -214,5 +214,5 @@ where
214 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); 214 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
215 let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; 215 let module = Module::from_definition(db, Source::new(src.file_id, module_src))?;
216 let ctx = LocationCtx::new(db, module.id, src.file_id); 216 let ctx = LocationCtx::new(db, module.id, src.file_id);
217 Some(DEF::from_ast(ctx, &src.ast)) 217 Some(DEF::from_ast(ctx, &src.value))
218} 218}