diff options
author | Aleksey Kladov <[email protected]> | 2019-11-20 06:40:36 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-20 06:42:30 +0000 |
commit | 36e3fc9d5413f7e6e17e82867aae1318645880a3 (patch) | |
tree | 166ee3c45f99611f7c20740c2a246f5b3bed41a3 /crates | |
parent | e975f6364cb3caf50467835afb0dafce887f51f0 (diff) |
Rename Source::ast -> Source::value
Diffstat (limited to 'crates')
43 files changed, 226 insertions, 214 deletions
diff --git a/crates/ra_assists/src/assists/add_missing_impl_members.rs b/crates/ra_assists/src/assists/add_missing_impl_members.rs index 91af161ee..cef669cb5 100644 --- a/crates/ra_assists/src/assists/add_missing_impl_members.rs +++ b/crates/ra_assists/src/assists/add_missing_impl_members.rs | |||
@@ -174,7 +174,7 @@ fn resolve_target_trait_def( | |||
174 | .path()?; | 174 | .path()?; |
175 | 175 | ||
176 | match analyzer.resolve_path(db, &ast_path) { | 176 | match analyzer.resolve_path(db, &ast_path) { |
177 | Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).ast), | 177 | Some(hir::PathResolution::Def(hir::ModuleDef::Trait(def))) => Some(def.source(db).value), |
178 | _ => None, | 178 | _ => None, |
179 | } | 179 | } |
180 | } | 180 | } |
diff --git a/crates/ra_assists/src/assists/add_new.rs b/crates/ra_assists/src/assists/add_new.rs index 2038afdc6..b5f8afb4e 100644 --- a/crates/ra_assists/src/assists/add_new.rs +++ b/crates/ra_assists/src/assists/add_new.rs | |||
@@ -141,7 +141,7 @@ fn find_struct_impl( | |||
141 | })?; | 141 | })?; |
142 | 142 | ||
143 | let struct_ty = { | 143 | let struct_ty = { |
144 | let src = hir::Source { file_id: ctx.frange.file_id.into(), ast: strukt.clone() }; | 144 | let src = hir::Source { file_id: ctx.frange.file_id.into(), value: strukt.clone() }; |
145 | hir::Struct::from_source(db, src).unwrap().ty(db) | 145 | hir::Struct::from_source(db, src).unwrap().ty(db) |
146 | }; | 146 | }; |
147 | 147 | ||
@@ -152,7 +152,7 @@ fn find_struct_impl( | |||
152 | return false; | 152 | return false; |
153 | } | 153 | } |
154 | 154 | ||
155 | let src = hir::Source { file_id: ctx.frange.file_id.into(), ast: impl_blk.clone() }; | 155 | let src = hir::Source { file_id: ctx.frange.file_id.into(), value: impl_blk.clone() }; |
156 | let blk = hir::ImplBlock::from_source(db, src).unwrap(); | 156 | let blk = hir::ImplBlock::from_source(db, src).unwrap(); |
157 | 157 | ||
158 | let same_ty = blk.target_ty(db) == struct_ty; | 158 | let same_ty = blk.target_ty(db) == struct_ty; |
diff --git a/crates/ra_assists/src/assists/fill_match_arms.rs b/crates/ra_assists/src/assists/fill_match_arms.rs index b851c2082..9354466d9 100644 --- a/crates/ra_assists/src/assists/fill_match_arms.rs +++ b/crates/ra_assists/src/assists/fill_match_arms.rs | |||
@@ -84,7 +84,7 @@ fn resolve_enum_def( | |||
84 | let expr_ty = analyzer.type_of(db, &expr)?; | 84 | let expr_ty = analyzer.type_of(db, &expr)?; |
85 | 85 | ||
86 | analyzer.autoderef(db, expr_ty).find_map(|ty| match ty.as_adt() { | 86 | analyzer.autoderef(db, expr_ty).find_map(|ty| match ty.as_adt() { |
87 | Some((Adt::Enum(e), _)) => Some(e.source(db).ast), | 87 | Some((Adt::Enum(e), _)) => Some(e.source(db).value), |
88 | _ => None, | 88 | _ => None, |
89 | }) | 89 | }) |
90 | } | 90 | } |
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index 3429a3c49..9cd21e4b6 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs | |||
@@ -98,7 +98,7 @@ pub fn run( | |||
98 | let src = f.source(db); | 98 | let src = f.source(db); |
99 | let original_file = src.file_id.original_file(db); | 99 | let original_file = src.file_id.original_file(db); |
100 | let path = db.file_relative_path(original_file); | 100 | let path = db.file_relative_path(original_file); |
101 | let syntax_range = src.ast.syntax().text_range(); | 101 | let syntax_range = src.value.syntax().text_range(); |
102 | write!(msg, " ({:?} {})", path, syntax_range).unwrap(); | 102 | write!(msg, " ({:?} {})", path, syntax_range).unwrap(); |
103 | } | 103 | } |
104 | bar.set_message(&msg); | 104 | bar.set_message(&msg); |
@@ -135,7 +135,7 @@ pub fn run( | |||
135 | let path = db.file_relative_path(original_file); | 135 | let path = db.file_relative_path(original_file); |
136 | let line_index = host.analysis().file_line_index(original_file).unwrap(); | 136 | let line_index = host.analysis().file_line_index(original_file).unwrap(); |
137 | let text_range = src | 137 | let text_range = src |
138 | .ast | 138 | .value |
139 | .either(|it| it.syntax().text_range(), |it| it.syntax().text_range()); | 139 | .either(|it| it.syntax().text_range(), |it| it.syntax().text_range()); |
140 | let (start, end) = ( | 140 | let (start, end) = ( |
141 | line_index.line_col(text_range.start()), | 141 | line_index.line_col(text_range.start()), |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 731cc1fff..cb990f4e2 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -139,7 +139,7 @@ impl Module { | |||
139 | ) -> Either<ast::UseTree, ast::ExternCrateItem> { | 139 | ) -> Either<ast::UseTree, ast::ExternCrateItem> { |
140 | let src = self.definition_source(db); | 140 | let src = self.definition_source(db); |
141 | let (_, source_map) = db.raw_items_with_source_map(src.file_id); | 141 | let (_, source_map) = db.raw_items_with_source_map(src.file_id); |
142 | source_map.get(&src.ast, import) | 142 | source_map.get(&src.value, import) |
143 | } | 143 | } |
144 | 144 | ||
145 | /// Returns the crate this module is part of. | 145 | /// Returns the crate this module is part of. |
@@ -206,7 +206,7 @@ impl Module { | |||
206 | crate::ModuleDef::Function(f) => f.diagnostics(db, sink), | 206 | crate::ModuleDef::Function(f) => f.diagnostics(db, sink), |
207 | crate::ModuleDef::Module(m) => { | 207 | crate::ModuleDef::Module(m) => { |
208 | // Only add diagnostics from inline modules | 208 | // Only add diagnostics from inline modules |
209 | if let ModuleSource::Module(_) = m.definition_source(db).ast { | 209 | if let ModuleSource::Module(_) = m.definition_source(db).value { |
210 | m.diagnostics(db, sink) | 210 | m.diagnostics(db, sink) |
211 | } | 211 | } |
212 | } | 212 | } |
@@ -598,10 +598,10 @@ impl FnData { | |||
598 | func: Function, | 598 | func: Function, |
599 | ) -> Arc<FnData> { | 599 | ) -> Arc<FnData> { |
600 | let src = func.source(db); | 600 | let src = func.source(db); |
601 | let name = src.ast.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); | 601 | let name = src.value.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); |
602 | let mut params = Vec::new(); | 602 | let mut params = Vec::new(); |
603 | let mut has_self_param = false; | 603 | let mut has_self_param = false; |
604 | if let Some(param_list) = src.ast.param_list() { | 604 | if let Some(param_list) = src.value.param_list() { |
605 | if let Some(self_param) = param_list.self_param() { | 605 | if let Some(self_param) = param_list.self_param() { |
606 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { | 606 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { |
607 | TypeRef::from_ast(type_ref) | 607 | TypeRef::from_ast(type_ref) |
@@ -625,7 +625,7 @@ impl FnData { | |||
625 | params.push(type_ref); | 625 | params.push(type_ref); |
626 | } | 626 | } |
627 | } | 627 | } |
628 | let ret_type = if let Some(type_ref) = src.ast.ret_type().and_then(|rt| rt.type_ref()) { | 628 | let ret_type = if let Some(type_ref) = src.value.ret_type().and_then(|rt| rt.type_ref()) { |
629 | TypeRef::from_ast(type_ref) | 629 | TypeRef::from_ast(type_ref) |
630 | } else { | 630 | } else { |
631 | TypeRef::unit() | 631 | TypeRef::unit() |
@@ -801,7 +801,7 @@ impl ConstData { | |||
801 | db: &(impl DefDatabase + AstDatabase), | 801 | db: &(impl DefDatabase + AstDatabase), |
802 | konst: Const, | 802 | konst: Const, |
803 | ) -> Arc<ConstData> { | 803 | ) -> Arc<ConstData> { |
804 | let node = konst.source(db).ast; | 804 | let node = konst.source(db).value; |
805 | const_data_for(&node) | 805 | const_data_for(&node) |
806 | } | 806 | } |
807 | 807 | ||
@@ -809,7 +809,7 @@ impl ConstData { | |||
809 | db: &(impl DefDatabase + AstDatabase), | 809 | db: &(impl DefDatabase + AstDatabase), |
810 | konst: Static, | 810 | konst: Static, |
811 | ) -> Arc<ConstData> { | 811 | ) -> Arc<ConstData> { |
812 | let node = konst.source(db).ast; | 812 | let node = konst.source(db).value; |
813 | const_data_for(&node) | 813 | const_data_for(&node) |
814 | } | 814 | } |
815 | } | 815 | } |
diff --git a/crates/ra_hir/src/code_model/attrs.rs b/crates/ra_hir/src/code_model/attrs.rs index f7db36b66..9e304217c 100644 --- a/crates/ra_hir/src/code_model/attrs.rs +++ b/crates/ra_hir/src/code_model/attrs.rs | |||
@@ -49,9 +49,9 @@ pub(crate) fn attributes_query( | |||
49 | AttrDef::Module(it) => { | 49 | AttrDef::Module(it) => { |
50 | let src = it.declaration_source(db)?; | 50 | let src = it.declaration_source(db)?; |
51 | let hygiene = Hygiene::new(db, src.file_id); | 51 | let hygiene = Hygiene::new(db, src.file_id); |
52 | Attr::from_attrs_owner(&src.ast, &hygiene) | 52 | Attr::from_attrs_owner(&src.value, &hygiene) |
53 | } | 53 | } |
54 | AttrDef::StructField(it) => match it.source(db).ast { | 54 | AttrDef::StructField(it) => match it.source(db).value { |
55 | FieldSource::Named(named) => { | 55 | FieldSource::Named(named) => { |
56 | let src = it.source(db); | 56 | let src = it.source(db); |
57 | let hygiene = Hygiene::new(db, src.file_id); | 57 | let hygiene = Hygiene::new(db, src.file_id); |
@@ -82,7 +82,7 @@ where | |||
82 | { | 82 | { |
83 | let src = node.source(db); | 83 | let src = node.source(db); |
84 | let hygiene = Hygiene::new(db, src.file_id); | 84 | let hygiene = Hygiene::new(db, src.file_id); |
85 | Attr::from_attrs_owner(&src.ast, &hygiene) | 85 | Attr::from_attrs_owner(&src.value, &hygiene) |
86 | } | 86 | } |
87 | 87 | ||
88 | impl<T: Into<AttrDef> + Copy> Attrs for T { | 88 | impl<T: Into<AttrDef> + Copy> Attrs for T { |
diff --git a/crates/ra_hir/src/code_model/docs.rs b/crates/ra_hir/src/code_model/docs.rs index 8533b4f5e..e40efef34 100644 --- a/crates/ra_hir/src/code_model/docs.rs +++ b/crates/ra_hir/src/code_model/docs.rs | |||
@@ -70,23 +70,23 @@ pub(crate) fn documentation_query( | |||
70 | def: DocDef, | 70 | def: DocDef, |
71 | ) -> Option<Documentation> { | 71 | ) -> Option<Documentation> { |
72 | match def { | 72 | match def { |
73 | DocDef::Module(it) => docs_from_ast(&it.declaration_source(db)?.ast), | 73 | DocDef::Module(it) => docs_from_ast(&it.declaration_source(db)?.value), |
74 | DocDef::StructField(it) => match it.source(db).ast { | 74 | DocDef::StructField(it) => match it.source(db).value { |
75 | FieldSource::Named(named) => docs_from_ast(&named), | 75 | FieldSource::Named(named) => docs_from_ast(&named), |
76 | FieldSource::Pos(..) => None, | 76 | FieldSource::Pos(..) => None, |
77 | }, | 77 | }, |
78 | DocDef::Adt(it) => match it { | 78 | DocDef::Adt(it) => match it { |
79 | Adt::Struct(it) => docs_from_ast(&it.source(db).ast), | 79 | Adt::Struct(it) => docs_from_ast(&it.source(db).value), |
80 | Adt::Enum(it) => docs_from_ast(&it.source(db).ast), | 80 | Adt::Enum(it) => docs_from_ast(&it.source(db).value), |
81 | Adt::Union(it) => docs_from_ast(&it.source(db).ast), | 81 | Adt::Union(it) => docs_from_ast(&it.source(db).value), |
82 | }, | 82 | }, |
83 | DocDef::EnumVariant(it) => docs_from_ast(&it.source(db).ast), | 83 | DocDef::EnumVariant(it) => docs_from_ast(&it.source(db).value), |
84 | DocDef::Static(it) => docs_from_ast(&it.source(db).ast), | 84 | DocDef::Static(it) => docs_from_ast(&it.source(db).value), |
85 | DocDef::Const(it) => docs_from_ast(&it.source(db).ast), | 85 | DocDef::Const(it) => docs_from_ast(&it.source(db).value), |
86 | DocDef::Function(it) => docs_from_ast(&it.source(db).ast), | 86 | DocDef::Function(it) => docs_from_ast(&it.source(db).value), |
87 | DocDef::Trait(it) => docs_from_ast(&it.source(db).ast), | 87 | DocDef::Trait(it) => docs_from_ast(&it.source(db).value), |
88 | DocDef::TypeAlias(it) => docs_from_ast(&it.source(db).ast), | 88 | DocDef::TypeAlias(it) => docs_from_ast(&it.source(db).value), |
89 | DocDef::MacroDef(it) => docs_from_ast(&it.source(db).ast), | 89 | DocDef::MacroDef(it) => docs_from_ast(&it.source(db).value), |
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 247ae3e55..556417b0f 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs | |||
@@ -25,9 +25,9 @@ impl Module { | |||
25 | let def_map = db.crate_def_map(self.id.krate); | 25 | let def_map = db.crate_def_map(self.id.krate); |
26 | let decl_id = def_map[self.id.module_id].declaration; | 26 | let decl_id = def_map[self.id.module_id].declaration; |
27 | let file_id = def_map[self.id.module_id].definition; | 27 | let file_id = def_map[self.id.module_id].definition; |
28 | let ast = ModuleSource::new(db, file_id, decl_id); | 28 | let value = ModuleSource::new(db, file_id, decl_id); |
29 | let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id()); | 29 | let file_id = file_id.map(HirFileId::from).unwrap_or_else(|| decl_id.unwrap().file_id()); |
30 | Source { file_id, ast } | 30 | Source { file_id, value } |
31 | } | 31 | } |
32 | 32 | ||
33 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. | 33 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. |
@@ -38,8 +38,8 @@ impl Module { | |||
38 | ) -> Option<Source<ast::Module>> { | 38 | ) -> Option<Source<ast::Module>> { |
39 | let def_map = db.crate_def_map(self.id.krate); | 39 | let def_map = db.crate_def_map(self.id.krate); |
40 | let decl = def_map[self.id.module_id].declaration?; | 40 | let decl = def_map[self.id.module_id].declaration?; |
41 | let ast = decl.to_node(db); | 41 | let value = decl.to_node(db); |
42 | Some(Source { file_id: decl.file_id(), ast }) | 42 | Some(Source { file_id: decl.file_id(), value }) |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
@@ -53,11 +53,11 @@ impl HasSource for StructField { | |||
53 | let (file_id, struct_kind) = match self.parent { | 53 | let (file_id, struct_kind) = match self.parent { |
54 | VariantDef::Struct(s) => { | 54 | VariantDef::Struct(s) => { |
55 | ss = s.source(db); | 55 | ss = s.source(db); |
56 | (ss.file_id, ss.ast.kind()) | 56 | (ss.file_id, ss.value.kind()) |
57 | } | 57 | } |
58 | VariantDef::EnumVariant(e) => { | 58 | VariantDef::EnumVariant(e) => { |
59 | es = e.source(db); | 59 | es = e.source(db); |
60 | (es.file_id, es.ast.kind()) | 60 | (es.file_id, es.value.kind()) |
61 | } | 61 | } |
62 | }; | 62 | }; |
63 | 63 | ||
@@ -66,13 +66,13 @@ impl HasSource for StructField { | |||
66 | ast::StructKind::Named(fl) => fl.fields().map(|it| FieldSource::Named(it)).collect(), | 66 | ast::StructKind::Named(fl) => fl.fields().map(|it| FieldSource::Named(it)).collect(), |
67 | ast::StructKind::Unit => Vec::new(), | 67 | ast::StructKind::Unit => Vec::new(), |
68 | }; | 68 | }; |
69 | let ast = field_sources | 69 | let value = field_sources |
70 | .into_iter() | 70 | .into_iter() |
71 | .zip(fields.iter()) | 71 | .zip(fields.iter()) |
72 | .find(|(_syntax, (id, _))| *id == self.id) | 72 | .find(|(_syntax, (id, _))| *id == self.id) |
73 | .unwrap() | 73 | .unwrap() |
74 | .0; | 74 | .0; |
75 | Source { file_id, ast } | 75 | Source { file_id, value } |
76 | } | 76 | } |
77 | } | 77 | } |
78 | impl HasSource for Struct { | 78 | impl HasSource for Struct { |
@@ -98,8 +98,8 @@ impl HasSource for EnumVariant { | |||
98 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::EnumVariant> { | 98 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::EnumVariant> { |
99 | let enum_data = db.enum_data(self.parent.id); | 99 | let enum_data = db.enum_data(self.parent.id); |
100 | let src = self.parent.id.source(db); | 100 | let src = self.parent.id.source(db); |
101 | let ast = src | 101 | let value = src |
102 | .ast | 102 | .value |
103 | .variant_list() | 103 | .variant_list() |
104 | .into_iter() | 104 | .into_iter() |
105 | .flat_map(|it| it.variants()) | 105 | .flat_map(|it| it.variants()) |
@@ -107,7 +107,7 @@ impl HasSource for EnumVariant { | |||
107 | .find(|(_syntax, (id, _))| *id == self.id) | 107 | .find(|(_syntax, (id, _))| *id == self.id) |
108 | .unwrap() | 108 | .unwrap() |
109 | .0; | 109 | .0; |
110 | Source { file_id: src.file_id, ast } | 110 | Source { file_id: src.file_id, value } |
111 | } | 111 | } |
112 | } | 112 | } |
113 | impl HasSource for Function { | 113 | impl HasSource for Function { |
@@ -143,7 +143,7 @@ impl HasSource for TypeAlias { | |||
143 | impl HasSource for MacroDef { | 143 | impl HasSource for MacroDef { |
144 | type Ast = ast::MacroCall; | 144 | type Ast = ast::MacroCall; |
145 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::MacroCall> { | 145 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::MacroCall> { |
146 | Source { file_id: self.id.ast_id.file_id(), ast: self.id.ast_id.to_node(db) } | 146 | Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) } |
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs index 1751e7be3..7d1b64858 100644 --- a/crates/ra_hir/src/diagnostics.rs +++ b/crates/ra_hir/src/diagnostics.rs | |||
@@ -21,7 +21,7 @@ impl Diagnostic for NoSuchField { | |||
21 | } | 21 | } |
22 | 22 | ||
23 | fn source(&self) -> Source<SyntaxNodePtr> { | 23 | fn source(&self) -> Source<SyntaxNodePtr> { |
24 | Source { file_id: self.file, ast: self.field.into() } | 24 | Source { file_id: self.file, value: self.field.into() } |
25 | } | 25 | } |
26 | 26 | ||
27 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 27 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
@@ -41,7 +41,7 @@ impl Diagnostic for MissingFields { | |||
41 | "fill structure fields".to_string() | 41 | "fill structure fields".to_string() |
42 | } | 42 | } |
43 | fn source(&self) -> Source<SyntaxNodePtr> { | 43 | fn source(&self) -> Source<SyntaxNodePtr> { |
44 | Source { file_id: self.file, ast: self.field_list.into() } | 44 | Source { file_id: self.file, value: self.field_list.into() } |
45 | } | 45 | } |
46 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 46 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
47 | self | 47 | self |
@@ -53,7 +53,7 @@ impl AstDiagnostic for MissingFields { | |||
53 | 53 | ||
54 | fn ast(&self, db: &impl AstDatabase) -> Self::AST { | 54 | fn ast(&self, db: &impl AstDatabase) -> Self::AST { |
55 | let root = db.parse_or_expand(self.source().file_id).unwrap(); | 55 | let root = db.parse_or_expand(self.source().file_id).unwrap(); |
56 | let node = self.source().ast.to_node(&root); | 56 | let node = self.source().value.to_node(&root); |
57 | ast::RecordFieldList::cast(node).unwrap() | 57 | ast::RecordFieldList::cast(node).unwrap() |
58 | } | 58 | } |
59 | } | 59 | } |
@@ -69,7 +69,7 @@ impl Diagnostic for MissingOkInTailExpr { | |||
69 | "wrap return expression in Ok".to_string() | 69 | "wrap return expression in Ok".to_string() |
70 | } | 70 | } |
71 | fn source(&self) -> Source<SyntaxNodePtr> { | 71 | fn source(&self) -> Source<SyntaxNodePtr> { |
72 | Source { file_id: self.file, ast: self.expr.into() } | 72 | Source { file_id: self.file, value: self.expr.into() } |
73 | } | 73 | } |
74 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 74 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
75 | self | 75 | self |
@@ -81,7 +81,7 @@ impl AstDiagnostic for MissingOkInTailExpr { | |||
81 | 81 | ||
82 | fn ast(&self, db: &impl AstDatabase) -> Self::AST { | 82 | fn ast(&self, db: &impl AstDatabase) -> Self::AST { |
83 | let root = db.parse_or_expand(self.file).unwrap(); | 83 | let root = db.parse_or_expand(self.file).unwrap(); |
84 | let node = self.source().ast.to_node(&root); | 84 | let node = self.source().value.to_node(&root); |
85 | ast::Expr::cast(node).unwrap() | 85 | ast::Expr::cast(node).unwrap() |
86 | } | 86 | } |
87 | } | 87 | } |
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index e3733779e..8bfdda45e 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -116,7 +116,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
116 | let source_map = self.func.body_source_map(db); | 116 | let source_map = self.func.body_source_map(db); |
117 | 117 | ||
118 | if let Some(source_ptr) = source_map.expr_syntax(id) { | 118 | if let Some(source_ptr) = source_map.expr_syntax(id) { |
119 | if let Some(expr) = source_ptr.ast.a() { | 119 | if let Some(expr) = source_ptr.value.a() { |
120 | let root = source_ptr.file_syntax(db); | 120 | let root = source_ptr.file_syntax(db); |
121 | if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { | 121 | if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { |
122 | if let Some(field_list) = record_lit.record_field_list() { | 122 | if let Some(field_list) = record_lit.record_field_list() { |
@@ -161,7 +161,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
161 | let source_map = self.func.body_source_map(db); | 161 | let source_map = self.func.body_source_map(db); |
162 | 162 | ||
163 | if let Some(source_ptr) = source_map.expr_syntax(id) { | 163 | if let Some(source_ptr) = source_map.expr_syntax(id) { |
164 | if let Some(expr) = source_ptr.ast.a() { | 164 | if let Some(expr) = source_ptr.value.a() { |
165 | self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr }); | 165 | self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr }); |
166 | } | 166 | } |
167 | } | 167 | } |
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 { | |||
105 | impl FromSource for EnumVariant { | 105 | impl 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 { | |||
115 | impl FromSource for StructField { | 115 | impl 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 { | |||
142 | impl Local { | 142 | impl 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 | ||
163 | impl Module { | 163 | impl 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 | } |
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index c35482ae8..8925ba3a9 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -91,10 +91,10 @@ impl GenericParams { | |||
91 | let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32; | 91 | let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32; |
92 | // FIXME: add `: Sized` bound for everything except for `Self` in traits | 92 | // FIXME: add `: Sized` bound for everything except for `Self` in traits |
93 | match def { | 93 | match def { |
94 | GenericDef::Function(it) => generics.fill(&it.source(db).ast, start), | 94 | GenericDef::Function(it) => generics.fill(&it.source(db).value, start), |
95 | GenericDef::Adt(Adt::Struct(it)) => generics.fill(&it.source(db).ast, start), | 95 | GenericDef::Adt(Adt::Struct(it)) => generics.fill(&it.source(db).value, start), |
96 | GenericDef::Adt(Adt::Union(it)) => generics.fill(&it.source(db).ast, start), | 96 | GenericDef::Adt(Adt::Union(it)) => generics.fill(&it.source(db).value, start), |
97 | GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start), | 97 | GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).value, start), |
98 | GenericDef::Trait(it) => { | 98 | GenericDef::Trait(it) => { |
99 | // traits get the Self type as an implicit first type parameter | 99 | // traits get the Self type as an implicit first type parameter |
100 | generics.params.push(GenericParam { | 100 | generics.params.push(GenericParam { |
@@ -102,17 +102,17 @@ impl GenericParams { | |||
102 | name: name::SELF_TYPE, | 102 | name: name::SELF_TYPE, |
103 | default: None, | 103 | default: None, |
104 | }); | 104 | }); |
105 | generics.fill(&it.source(db).ast, start + 1); | 105 | generics.fill(&it.source(db).value, start + 1); |
106 | // add super traits as bounds on Self | 106 | // add super traits as bounds on Self |
107 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar | 107 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar |
108 | let self_param = TypeRef::Path(name::SELF_TYPE.into()); | 108 | let self_param = TypeRef::Path(name::SELF_TYPE.into()); |
109 | generics.fill_bounds(&it.source(db).ast, self_param); | 109 | generics.fill_bounds(&it.source(db).value, self_param); |
110 | } | 110 | } |
111 | GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start), | 111 | GenericDef::TypeAlias(it) => generics.fill(&it.source(db).value, start), |
112 | // Note that we don't add `Self` here: in `impl`s, `Self` is not a | 112 | // Note that we don't add `Self` here: in `impl`s, `Self` is not a |
113 | // type-parameter, but rather is a type-alias for impl's target | 113 | // type-parameter, but rather is a type-alias for impl's target |
114 | // type, so this is handled by the resolver. | 114 | // type, so this is handled by the resolver. |
115 | GenericDef::ImplBlock(it) => generics.fill(&it.source(db).ast, start), | 115 | GenericDef::ImplBlock(it) => generics.fill(&it.source(db).value, start), |
116 | GenericDef::EnumVariant(_) | GenericDef::Const(_) => {} | 116 | GenericDef::EnumVariant(_) | GenericDef::Const(_) => {} |
117 | } | 117 | } |
118 | 118 | ||
diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs index fa2ef8a17..89fd85f59 100644 --- a/crates/ra_hir/src/lang_item.rs +++ b/crates/ra_hir/src/lang_item.rs | |||
@@ -97,7 +97,7 @@ impl LangItems { | |||
97 | // Look for impl targets | 97 | // Look for impl targets |
98 | for impl_block in module.impl_blocks(db) { | 98 | for impl_block in module.impl_blocks(db) { |
99 | let src = impl_block.source(db); | 99 | let src = impl_block.source(db); |
100 | if let Some(lang_item_name) = lang_item_name(&src.ast) { | 100 | if let Some(lang_item_name) = lang_item_name(&src.value) { |
101 | self.items | 101 | self.items |
102 | .entry(lang_item_name) | 102 | .entry(lang_item_name) |
103 | .or_insert_with(|| LangItemTarget::ImplBlock(impl_block)); | 103 | .or_insert_with(|| LangItemTarget::ImplBlock(impl_block)); |
@@ -144,7 +144,7 @@ impl LangItems { | |||
144 | T: Copy + HasSource<Ast = N>, | 144 | T: Copy + HasSource<Ast = N>, |
145 | N: AttrsOwner, | 145 | N: AttrsOwner, |
146 | { | 146 | { |
147 | let node = item.source(db).ast; | 147 | let node = item.source(db).value; |
148 | if let Some(lang_item_name) = lang_item_name(&node) { | 148 | if let Some(lang_item_name) = lang_item_name(&node) { |
149 | self.items.entry(lang_item_name).or_insert_with(|| constructor(item)); | 149 | self.items.entry(lang_item_name).or_insert_with(|| constructor(item)); |
150 | } | 150 | } |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 5d3196c2a..471b0b089 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -31,7 +31,7 @@ use crate::{ | |||
31 | 31 | ||
32 | fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { | 32 | fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { |
33 | match_ast! { | 33 | match_ast! { |
34 | match (node.ast) { | 34 | match (node.value) { |
35 | ast::Module(it) => { | 35 | ast::Module(it) => { |
36 | let src = node.with_ast(it); | 36 | let src = node.with_ast(it); |
37 | Some(crate::Module::from_declaration(db, src)?.resolver(db)) | 37 | Some(crate::Module::from_declaration(db, src)?.resolver(db)) |
@@ -48,7 +48,7 @@ fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) - | |||
48 | let src = node.with_ast(it); | 48 | let src = node.with_ast(it); |
49 | Some(Enum::from_source(db, src)?.resolver(db)) | 49 | Some(Enum::from_source(db, src)?.resolver(db)) |
50 | }, | 50 | }, |
51 | _ => match node.ast.kind() { | 51 | _ => match node.value.kind() { |
52 | FN_DEF | CONST_DEF | STATIC_DEF => { | 52 | FN_DEF | CONST_DEF | STATIC_DEF => { |
53 | Some(def_with_body_from_child_node(db, node)?.resolver(db)) | 53 | Some(def_with_body_from_child_node(db, node)?.resolver(db)) |
54 | } | 54 | } |
@@ -67,7 +67,7 @@ fn def_with_body_from_child_node( | |||
67 | let module = Module::from_definition(db, Source::new(child.file_id, module_source))?; | 67 | let module = Module::from_definition(db, Source::new(child.file_id, module_source))?; |
68 | let ctx = LocationCtx::new(db, module.id, child.file_id); | 68 | let ctx = LocationCtx::new(db, module.id, child.file_id); |
69 | 69 | ||
70 | child.ast.ancestors().find_map(|node| { | 70 | child.value.ancestors().find_map(|node| { |
71 | match_ast! { | 71 | match_ast! { |
72 | match node { | 72 | match node { |
73 | ast::FnDef(def) => { Some(Function {id: ctx.to_def(&def) }.into()) }, | 73 | ast::FnDef(def) => { Some(Function {id: ctx.to_def(&def) }.into()) }, |
@@ -171,7 +171,7 @@ impl SourceAnalyzer { | |||
171 | } else { | 171 | } else { |
172 | SourceAnalyzer { | 172 | SourceAnalyzer { |
173 | resolver: node | 173 | resolver: node |
174 | .ast | 174 | .value |
175 | .ancestors() | 175 | .ancestors() |
176 | .find_map(|it| try_get_resolver_for_node(db, node.with_ast(&it))) | 176 | .find_map(|it| try_get_resolver_for_node(db, node.with_ast(&it))) |
177 | .unwrap_or_default(), | 177 | .unwrap_or_default(), |
@@ -185,12 +185,12 @@ impl SourceAnalyzer { | |||
185 | } | 185 | } |
186 | 186 | ||
187 | fn expr_id(&self, expr: &ast::Expr) -> Option<ExprId> { | 187 | fn expr_id(&self, expr: &ast::Expr) -> Option<ExprId> { |
188 | let src = Source { file_id: self.file_id, ast: expr }; | 188 | let src = Source { file_id: self.file_id, value: expr }; |
189 | self.body_source_map.as_ref()?.node_expr(src) | 189 | self.body_source_map.as_ref()?.node_expr(src) |
190 | } | 190 | } |
191 | 191 | ||
192 | fn pat_id(&self, pat: &ast::Pat) -> Option<PatId> { | 192 | fn pat_id(&self, pat: &ast::Pat) -> Option<PatId> { |
193 | let src = Source { file_id: self.file_id, ast: pat }; | 193 | let src = Source { file_id: self.file_id, value: pat }; |
194 | self.body_source_map.as_ref()?.node_pat(src) | 194 | self.body_source_map.as_ref()?.node_pat(src) |
195 | } | 195 | } |
196 | 196 | ||
@@ -302,7 +302,7 @@ impl SourceAnalyzer { | |||
302 | let entry = scopes.resolve_name_in_scope(scope, &name)?; | 302 | let entry = scopes.resolve_name_in_scope(scope, &name)?; |
303 | Some(ScopeEntryWithSyntax { | 303 | Some(ScopeEntryWithSyntax { |
304 | name: entry.name().clone(), | 304 | name: entry.name().clone(), |
305 | ptr: source_map.pat_syntax(entry.pat())?.ast, | 305 | ptr: source_map.pat_syntax(entry.pat())?.value, |
306 | }) | 306 | }) |
307 | } | 307 | } |
308 | 308 | ||
@@ -428,7 +428,7 @@ fn scope_for( | |||
428 | source_map: &BodySourceMap, | 428 | source_map: &BodySourceMap, |
429 | node: Source<&SyntaxNode>, | 429 | node: Source<&SyntaxNode>, |
430 | ) -> Option<ScopeId> { | 430 | ) -> Option<ScopeId> { |
431 | node.ast | 431 | node.value |
432 | .ancestors() | 432 | .ancestors() |
433 | .filter_map(ast::Expr::cast) | 433 | .filter_map(ast::Expr::cast) |
434 | .filter_map(|it| source_map.node_expr(Source::new(node.file_id, &it))) | 434 | .filter_map(|it| source_map.node_expr(Source::new(node.file_id, &it))) |
@@ -450,18 +450,18 @@ fn scope_for_offset( | |||
450 | return None; | 450 | return None; |
451 | } | 451 | } |
452 | let syntax_node_ptr = | 452 | let syntax_node_ptr = |
453 | source.ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()); | 453 | source.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()); |
454 | Some((syntax_node_ptr, scope)) | 454 | Some((syntax_node_ptr, scope)) |
455 | }) | 455 | }) |
456 | // find containing scope | 456 | // find containing scope |
457 | .min_by_key(|(ptr, _scope)| { | 457 | .min_by_key(|(ptr, _scope)| { |
458 | ( | 458 | ( |
459 | !(ptr.range().start() <= offset.ast && offset.ast <= ptr.range().end()), | 459 | !(ptr.range().start() <= offset.value && offset.value <= ptr.range().end()), |
460 | ptr.range().len(), | 460 | ptr.range().len(), |
461 | ) | 461 | ) |
462 | }) | 462 | }) |
463 | .map(|(ptr, scope)| { | 463 | .map(|(ptr, scope)| { |
464 | adjust(scopes, source_map, ptr, offset.file_id, offset.ast).unwrap_or(*scope) | 464 | adjust(scopes, source_map, ptr, offset.file_id, offset.value).unwrap_or(*scope) |
465 | }) | 465 | }) |
466 | } | 466 | } |
467 | 467 | ||
@@ -485,7 +485,7 @@ fn adjust( | |||
485 | return None; | 485 | return None; |
486 | } | 486 | } |
487 | let syntax_node_ptr = | 487 | let syntax_node_ptr = |
488 | source.ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()); | 488 | source.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()); |
489 | Some((syntax_node_ptr, scope)) | 489 | Some((syntax_node_ptr, scope)) |
490 | }) | 490 | }) |
491 | .map(|(ptr, scope)| (ptr.range(), scope)) | 491 | .map(|(ptr, scope)| (ptr.range(), scope)) |
diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs index 1a45dacba..858972c6f 100644 --- a/crates/ra_hir/src/traits.rs +++ b/crates/ra_hir/src/traits.rs | |||
@@ -26,11 +26,11 @@ impl TraitData { | |||
26 | tr: Trait, | 26 | tr: Trait, |
27 | ) -> Arc<TraitData> { | 27 | ) -> Arc<TraitData> { |
28 | let src = tr.source(db); | 28 | let src = tr.source(db); |
29 | let name = src.ast.name().map(|n| n.as_name()); | 29 | let name = src.value.name().map(|n| n.as_name()); |
30 | let module = tr.module(db); | 30 | let module = tr.module(db); |
31 | let ctx = LocationCtx::new(db, module.id, src.file_id); | 31 | let ctx = LocationCtx::new(db, module.id, src.file_id); |
32 | let auto = src.ast.is_auto(); | 32 | let auto = src.value.is_auto(); |
33 | let items = if let Some(item_list) = src.ast.item_list() { | 33 | let items = if let Some(item_list) = src.value.item_list() { |
34 | item_list | 34 | item_list |
35 | .impl_items() | 35 | .impl_items() |
36 | .map(|item_node| match item_node { | 36 | .map(|item_node| match item_node { |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index ca1693679..c1024d03c 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -4694,14 +4694,16 @@ fn infer(content: &str) -> String { | |||
4694 | } | 4694 | } |
4695 | 4695 | ||
4696 | // sort ranges for consistency | 4696 | // sort ranges for consistency |
4697 | types.sort_by_key(|(src_ptr, _)| (src_ptr.ast.range().start(), src_ptr.ast.range().end())); | 4697 | types.sort_by_key(|(src_ptr, _)| { |
4698 | (src_ptr.value.range().start(), src_ptr.value.range().end()) | ||
4699 | }); | ||
4698 | for (src_ptr, ty) in &types { | 4700 | for (src_ptr, ty) in &types { |
4699 | let node = src_ptr.ast.to_node(&src_ptr.file_syntax(&db)); | 4701 | let node = src_ptr.value.to_node(&src_ptr.file_syntax(&db)); |
4700 | 4702 | ||
4701 | let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node.clone()) { | 4703 | let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node.clone()) { |
4702 | (self_param.self_kw_token().text_range(), "self".to_string()) | 4704 | (self_param.self_kw_token().text_range(), "self".to_string()) |
4703 | } else { | 4705 | } else { |
4704 | (src_ptr.ast.range(), node.text().to_string().replace("\n", " ")) | 4706 | (src_ptr.value.range(), node.text().to_string().replace("\n", " ")) |
4705 | }; | 4707 | }; |
4706 | let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; | 4708 | let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; |
4707 | write!( | 4709 | write!( |
diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs index 078e6295e..392f244cf 100644 --- a/crates/ra_hir/src/type_alias.rs +++ b/crates/ra_hir/src/type_alias.rs | |||
@@ -23,7 +23,7 @@ impl TypeAliasData { | |||
23 | db: &(impl DefDatabase + AstDatabase), | 23 | db: &(impl DefDatabase + AstDatabase), |
24 | typ: TypeAlias, | 24 | typ: TypeAlias, |
25 | ) -> Arc<TypeAliasData> { | 25 | ) -> Arc<TypeAliasData> { |
26 | let node = typ.source(db).ast; | 26 | let node = typ.source(db).value; |
27 | let name = node.name().map_or_else(Name::missing, |n| n.as_name()); | 27 | let name = node.name().map_or_else(Name::missing, |n| n.as_name()); |
28 | let type_ref = node.type_ref().map(TypeRef::from_ast); | 28 | let type_ref = node.type_ref().map(TypeRef::from_ast); |
29 | Arc::new(TypeAliasData { name, type_ref }) | 29 | Arc::new(TypeAliasData { name, type_ref }) |
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index a29c4d41e..d04f54e15 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -54,8 +54,8 @@ impl StructData { | |||
54 | id: StructOrUnionId, | 54 | id: StructOrUnionId, |
55 | ) -> Arc<StructData> { | 55 | ) -> Arc<StructData> { |
56 | let src = id.source(db); | 56 | let src = id.source(db); |
57 | let name = src.ast.name().map(|n| n.as_name()); | 57 | let name = src.value.name().map(|n| n.as_name()); |
58 | let variant_data = VariantData::new(src.ast.kind()); | 58 | let variant_data = VariantData::new(src.value.kind()); |
59 | let variant_data = Arc::new(variant_data); | 59 | let variant_data = Arc::new(variant_data); |
60 | Arc::new(StructData { name, variant_data }) | 60 | Arc::new(StructData { name, variant_data }) |
61 | } | 61 | } |
@@ -64,9 +64,9 @@ impl StructData { | |||
64 | impl EnumData { | 64 | impl EnumData { |
65 | pub(crate) fn enum_data_query(db: &impl DefDatabase2, e: EnumId) -> Arc<EnumData> { | 65 | pub(crate) fn enum_data_query(db: &impl DefDatabase2, e: EnumId) -> Arc<EnumData> { |
66 | let src = e.source(db); | 66 | let src = e.source(db); |
67 | let name = src.ast.name().map(|n| n.as_name()); | 67 | let name = src.value.name().map(|n| n.as_name()); |
68 | let variants = src | 68 | let variants = src |
69 | .ast | 69 | .value |
70 | .variant_list() | 70 | .variant_list() |
71 | .into_iter() | 71 | .into_iter() |
72 | .flat_map(|it| it.variants()) | 72 | .flat_map(|it| it.variants()) |
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 85dc4feb0..3804b65c7 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -73,8 +73,8 @@ impl Expander { | |||
73 | std::mem::forget(mark); | 73 | std::mem::forget(mark); |
74 | } | 74 | } |
75 | 75 | ||
76 | fn to_source<T>(&self, ast: T) -> Source<T> { | 76 | fn to_source<T>(&self, value: T) -> Source<T> { |
77 | Source { file_id: self.current_file_id, ast } | 77 | Source { file_id: self.current_file_id, value } |
78 | } | 78 | } |
79 | 79 | ||
80 | fn parse_path(&mut self, path: ast::Path) -> Option<Path> { | 80 | fn parse_path(&mut self, path: ast::Path) -> Option<Path> { |
@@ -150,16 +150,16 @@ impl Body { | |||
150 | let (file_id, module, body) = match def { | 150 | let (file_id, module, body) = match def { |
151 | DefWithBodyId::FunctionId(f) => { | 151 | DefWithBodyId::FunctionId(f) => { |
152 | let src = f.source(db); | 152 | let src = f.source(db); |
153 | params = src.ast.param_list(); | 153 | params = src.value.param_list(); |
154 | (src.file_id, f.module(db), src.ast.body().map(ast::Expr::from)) | 154 | (src.file_id, f.module(db), src.value.body().map(ast::Expr::from)) |
155 | } | 155 | } |
156 | DefWithBodyId::ConstId(c) => { | 156 | DefWithBodyId::ConstId(c) => { |
157 | let src = c.source(db); | 157 | let src = c.source(db); |
158 | (src.file_id, c.module(db), src.ast.body()) | 158 | (src.file_id, c.module(db), src.value.body()) |
159 | } | 159 | } |
160 | DefWithBodyId::StaticId(s) => { | 160 | DefWithBodyId::StaticId(s) => { |
161 | let src = s.source(db); | 161 | let src = s.source(db); |
162 | (src.file_id, s.module(db), src.ast.body()) | 162 | (src.file_id, s.module(db), src.value.body()) |
163 | } | 163 | } |
164 | }; | 164 | }; |
165 | let expander = Expander::new(db, file_id, module); | 165 | let expander = Expander::new(db, file_id, module); |
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 10cb87d37..aeb71ff22 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs | |||
@@ -210,8 +210,9 @@ mod tests { | |||
210 | let scopes = db.expr_scopes(function.into()); | 210 | let scopes = db.expr_scopes(function.into()); |
211 | let (_body, source_map) = db.body_with_source_map(function.into()); | 211 | let (_body, source_map) = db.body_with_source_map(function.into()); |
212 | 212 | ||
213 | let expr_id = | 213 | let expr_id = source_map |
214 | source_map.node_expr(Source { file_id: file_id.into(), ast: &marker.into() }).unwrap(); | 214 | .node_expr(Source { file_id: file_id.into(), value: &marker.into() }) |
215 | .unwrap(); | ||
215 | let scope = scopes.scope_for(expr_id); | 216 | let scope = scopes.scope_for(expr_id); |
216 | 217 | ||
217 | let actual = scopes | 218 | let actual = scopes |
@@ -317,14 +318,14 @@ mod tests { | |||
317 | let expr_scope = { | 318 | let expr_scope = { |
318 | let expr_ast = name_ref.syntax().ancestors().find_map(ast::Expr::cast).unwrap(); | 319 | let expr_ast = name_ref.syntax().ancestors().find_map(ast::Expr::cast).unwrap(); |
319 | let expr_id = | 320 | let expr_id = |
320 | source_map.node_expr(Source { file_id: file_id.into(), ast: &expr_ast }).unwrap(); | 321 | source_map.node_expr(Source { file_id: file_id.into(), value: &expr_ast }).unwrap(); |
321 | scopes.scope_for(expr_id).unwrap() | 322 | scopes.scope_for(expr_id).unwrap() |
322 | }; | 323 | }; |
323 | 324 | ||
324 | let resolved = scopes.resolve_name_in_scope(expr_scope, &name_ref.as_name()).unwrap(); | 325 | let resolved = scopes.resolve_name_in_scope(expr_scope, &name_ref.as_name()).unwrap(); |
325 | let pat_src = source_map.pat_syntax(resolved.pat()).unwrap(); | 326 | let pat_src = source_map.pat_syntax(resolved.pat()).unwrap(); |
326 | 327 | ||
327 | let local_name = pat_src.ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()); | 328 | let local_name = pat_src.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()); |
328 | assert_eq!(local_name.range(), expected_name.syntax().text_range()); | 329 | assert_eq!(local_name.range(), expected_name.syntax().text_range()); |
329 | } | 330 | } |
330 | 331 | ||
diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs index 9843009a5..eda9b2269 100644 --- a/crates/ra_hir_def/src/diagnostics.rs +++ b/crates/ra_hir_def/src/diagnostics.rs | |||
@@ -20,7 +20,7 @@ impl Diagnostic for UnresolvedModule { | |||
20 | "unresolved module".to_string() | 20 | "unresolved module".to_string() |
21 | } | 21 | } |
22 | fn source(&self) -> Source<SyntaxNodePtr> { | 22 | fn source(&self) -> Source<SyntaxNodePtr> { |
23 | Source { file_id: self.file, ast: self.decl.into() } | 23 | Source { file_id: self.file, value: self.decl.into() } |
24 | } | 24 | } |
25 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 25 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
26 | self | 26 | self |
diff --git a/crates/ra_hir_def/src/imp.rs b/crates/ra_hir_def/src/imp.rs index 717991c40..4323dfcb6 100644 --- a/crates/ra_hir_def/src/imp.rs +++ b/crates/ra_hir_def/src/imp.rs | |||
@@ -25,11 +25,11 @@ impl ImplData { | |||
25 | let src = id.source(db); | 25 | let src = id.source(db); |
26 | let items = db.ast_id_map(src.file_id); | 26 | let items = db.ast_id_map(src.file_id); |
27 | 27 | ||
28 | let target_trait = src.ast.target_trait().map(TypeRef::from_ast); | 28 | let target_trait = src.value.target_trait().map(TypeRef::from_ast); |
29 | let target_type = TypeRef::from_ast_opt(src.ast.target_type()); | 29 | let target_type = TypeRef::from_ast_opt(src.value.target_type()); |
30 | let negative = src.ast.is_negative(); | 30 | let negative = src.value.is_negative(); |
31 | 31 | ||
32 | let items = if let Some(item_list) = src.ast.item_list() { | 32 | let items = if let Some(item_list) = src.value.item_list() { |
33 | let ctx = LocationCtx::new(db, id.module(db), src.file_id); | 33 | let ctx = LocationCtx::new(db, id.module(db), src.file_id); |
34 | item_list | 34 | item_list |
35 | .impl_items() | 35 | .impl_items() |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index a240a10b8..50caf4f83 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -80,7 +80,7 @@ impl ModuleSource { | |||
80 | 80 | ||
81 | pub fn from_child_node(db: &impl db::DefDatabase2, child: Source<&SyntaxNode>) -> ModuleSource { | 81 | pub fn from_child_node(db: &impl db::DefDatabase2, child: Source<&SyntaxNode>) -> ModuleSource { |
82 | if let Some(m) = | 82 | if let Some(m) = |
83 | child.ast.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) | 83 | child.value.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) |
84 | { | 84 | { |
85 | ModuleSource::Module(m) | 85 | ModuleSource::Module(m) |
86 | } else { | 86 | } else { |
@@ -184,8 +184,8 @@ pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone { | |||
184 | } | 184 | } |
185 | fn source(self, db: &(impl AstDatabase + InternDatabase)) -> Source<N> { | 185 | fn source(self, db: &(impl AstDatabase + InternDatabase)) -> Source<N> { |
186 | let loc = self.lookup_intern(db); | 186 | let loc = self.lookup_intern(db); |
187 | let ast = loc.ast_id.to_node(db); | 187 | let value = loc.ast_id.to_node(db); |
188 | Source { file_id: loc.ast_id.file_id(), ast } | 188 | Source { file_id: loc.ast_id.file_id(), value } |
189 | } | 189 | } |
190 | fn module(self, db: &impl InternDatabase) -> ModuleId { | 190 | fn module(self, db: &impl InternDatabase) -> ModuleId { |
191 | let loc = self.lookup_intern(db); | 191 | let loc = self.lookup_intern(db); |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index a0a2c7273..7c68fd638 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -327,7 +327,7 @@ impl RawItemsCollector { | |||
327 | 327 | ||
328 | let mut buf = Vec::new(); | 328 | let mut buf = Vec::new(); |
329 | Path::expand_use_item( | 329 | Path::expand_use_item( |
330 | Source { ast: use_item, file_id: self.file_id }, | 330 | Source { value: use_item, file_id: self.file_id }, |
331 | &self.hygiene, | 331 | &self.hygiene, |
332 | |path, use_tree, is_glob, alias| { | 332 | |path, use_tree, is_glob, alias| { |
333 | let import_data = ImportData { | 333 | let import_data = ImportData { |
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index 04039376f..626ebffdc 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -71,7 +71,7 @@ impl Path { | |||
71 | hygiene: &Hygiene, | 71 | hygiene: &Hygiene, |
72 | mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>), | 72 | mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>), |
73 | ) { | 73 | ) { |
74 | if let Some(tree) = item_src.ast.use_tree() { | 74 | if let Some(tree) = item_src.value.use_tree() { |
75 | expand_use_tree(None, tree, hygiene, &mut cb); | 75 | expand_use_tree(None, tree, hygiene, &mut cb); |
76 | } | 76 | } |
77 | } | 77 | } |
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs index 201884b95..3d37e9335 100644 --- a/crates/ra_hir_expand/src/diagnostics.rs +++ b/crates/ra_hir_expand/src/diagnostics.rs | |||
@@ -24,7 +24,7 @@ pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { | |||
24 | fn message(&self) -> String; | 24 | fn message(&self) -> String; |
25 | fn source(&self) -> Source<SyntaxNodePtr>; | 25 | fn source(&self) -> Source<SyntaxNodePtr>; |
26 | fn highlight_range(&self) -> TextRange { | 26 | fn highlight_range(&self) -> TextRange { |
27 | self.source().ast.range() | 27 | self.source().value.range() |
28 | } | 28 | } |
29 | fn as_any(&self) -> &(dyn Any + Send + 'static); | 29 | fn as_any(&self) -> &(dyn Any + Send + 'static); |
30 | } | 30 | } |
@@ -37,7 +37,7 @@ pub trait AstDiagnostic { | |||
37 | impl dyn Diagnostic { | 37 | impl dyn Diagnostic { |
38 | pub fn syntax_node(&self, db: &impl AstDatabase) -> SyntaxNode { | 38 | pub fn syntax_node(&self, db: &impl AstDatabase) -> SyntaxNode { |
39 | let node = db.parse_or_expand(self.source().file_id).unwrap(); | 39 | let node = db.parse_or_expand(self.source().file_id).unwrap(); |
40 | self.source().ast.to_node(&node) | 40 | self.source().value.to_node(&node) |
41 | } | 41 | } |
42 | 42 | ||
43 | pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { | 43 | pub fn downcast_ref<D: Diagnostic>(&self) -> Option<&D> { |
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index cfe7e6d15..6ca4bc7a3 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -166,19 +166,19 @@ impl ExpansionInfo { | |||
166 | pub fn map_token_down(&self, token: Source<&SyntaxToken>) -> Option<Source<SyntaxToken>> { | 166 | pub fn map_token_down(&self, token: Source<&SyntaxToken>) -> Option<Source<SyntaxToken>> { |
167 | assert_eq!(token.file_id, self.arg.file_id); | 167 | assert_eq!(token.file_id, self.arg.file_id); |
168 | let range = | 168 | let range = |
169 | token.ast.text_range().checked_sub(self.arg.ast.syntax().text_range().start())?; | 169 | token.value.text_range().checked_sub(self.arg.value.syntax().text_range().start())?; |
170 | let token_id = self.macro_arg.1.token_by_range(range)?; | 170 | let token_id = self.macro_arg.1.token_by_range(range)?; |
171 | let token_id = self.macro_def.0.map_id_down(token_id); | 171 | let token_id = self.macro_def.0.map_id_down(token_id); |
172 | 172 | ||
173 | let range = self.exp_map.range_by_token(token_id)?; | 173 | let range = self.exp_map.range_by_token(token_id)?; |
174 | 174 | ||
175 | let token = algo::find_covering_element(&self.expanded.ast, range).into_token()?; | 175 | let token = algo::find_covering_element(&self.expanded.value, range).into_token()?; |
176 | 176 | ||
177 | Some(self.expanded.with_ast(token)) | 177 | Some(self.expanded.with_ast(token)) |
178 | } | 178 | } |
179 | 179 | ||
180 | pub fn map_token_up(&self, token: Source<&SyntaxToken>) -> Option<Source<SyntaxToken>> { | 180 | pub fn map_token_up(&self, token: Source<&SyntaxToken>) -> Option<Source<SyntaxToken>> { |
181 | let token_id = self.exp_map.token_by_range(token.ast.text_range())?; | 181 | let token_id = self.exp_map.token_by_range(token.value.text_range())?; |
182 | 182 | ||
183 | let (token_id, origin) = self.macro_def.0.map_id_up(token_id); | 183 | let (token_id, origin) = self.macro_def.0.map_id_up(token_id); |
184 | let (token_map, tt) = match origin { | 184 | let (token_map, tt) = match origin { |
@@ -188,8 +188,8 @@ impl ExpansionInfo { | |||
188 | 188 | ||
189 | let range = token_map.range_by_token(token_id)?; | 189 | let range = token_map.range_by_token(token_id)?; |
190 | let token = algo::find_covering_element( | 190 | let token = algo::find_covering_element( |
191 | tt.ast.syntax(), | 191 | tt.value.syntax(), |
192 | range + tt.ast.syntax().text_range().start(), | 192 | range + tt.value.syntax().text_range().start(), |
193 | ) | 193 | ) |
194 | .into_token()?; | 194 | .into_token()?; |
195 | Some(tt.with_ast(token)) | 195 | Some(tt.with_ast(token)) |
@@ -240,30 +240,34 @@ impl<N: AstNode> AstId<N> { | |||
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
243 | /// FIXME: https://github.com/matklad/with ? | 243 | /// `Source<T>` stores a value of `T` inside a particular file/syntax tree. |
244 | /// | ||
245 | /// Typical usages are: | ||
246 | /// | ||
247 | /// * `Source<SyntaxNode>` -- syntax node in a file | ||
248 | /// * `Source<ast::FnDef>` -- ast node in a file | ||
249 | /// * `Source<TextUnit>` -- offset in a file | ||
244 | #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] | 250 | #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] |
245 | pub struct Source<T> { | 251 | pub struct Source<T> { |
246 | pub file_id: HirFileId, | 252 | pub file_id: HirFileId, |
247 | // FIXME: this stores all kind of things, not only `ast`. | 253 | pub value: T, |
248 | // There should be a better name... | ||
249 | pub ast: T, | ||
250 | } | 254 | } |
251 | 255 | ||
252 | impl<T> Source<T> { | 256 | impl<T> Source<T> { |
253 | pub fn new(file_id: HirFileId, ast: T) -> Source<T> { | 257 | pub fn new(file_id: HirFileId, value: T) -> Source<T> { |
254 | Source { file_id, ast } | 258 | Source { file_id, value } |
255 | } | 259 | } |
256 | 260 | ||
257 | // Similarly, naming here is stupid... | 261 | // Similarly, naming here is stupid... |
258 | pub fn with_ast<U>(&self, ast: U) -> Source<U> { | 262 | pub fn with_ast<U>(&self, value: U) -> Source<U> { |
259 | Source::new(self.file_id, ast) | 263 | Source::new(self.file_id, value) |
260 | } | 264 | } |
261 | 265 | ||
262 | pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { | 266 | pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { |
263 | Source::new(self.file_id, f(self.ast)) | 267 | Source::new(self.file_id, f(self.value)) |
264 | } | 268 | } |
265 | pub fn as_ref(&self) -> Source<&T> { | 269 | pub fn as_ref(&self) -> Source<&T> { |
266 | self.with_ast(&self.ast) | 270 | self.with_ast(&self.value) |
267 | } | 271 | } |
268 | pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { | 272 | pub fn file_syntax(&self, db: &impl db::AstDatabase) -> SyntaxNode { |
269 | db.parse_or_expand(self.file_id).expect("source created from invalid file") | 273 | db.parse_or_expand(self.file_id).expect("source created from invalid file") |
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index 0906a4e1b..b8345c91d 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs | |||
@@ -54,7 +54,7 @@ impl<'a> CompletionContext<'a> { | |||
54 | let src = hir::ModuleSource::from_position(db, position); | 54 | let src = hir::ModuleSource::from_position(db, position); |
55 | let module = hir::Module::from_definition( | 55 | let module = hir::Module::from_definition( |
56 | db, | 56 | db, |
57 | hir::Source { file_id: position.file_id.into(), ast: src }, | 57 | hir::Source { file_id: position.file_id.into(), value: src }, |
58 | ); | 58 | ); |
59 | let token = | 59 | let token = |
60 | original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?; | 60 | original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?; |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 501b7da4e..b20329459 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -169,7 +169,7 @@ impl Completions { | |||
169 | None => return, | 169 | None => return, |
170 | }; | 170 | }; |
171 | 171 | ||
172 | let ast_node = macro_.source(ctx.db).ast; | 172 | let ast_node = macro_.source(ctx.db).value; |
173 | let detail = macro_label(&ast_node); | 173 | let detail = macro_label(&ast_node); |
174 | 174 | ||
175 | let docs = macro_.docs(ctx.db); | 175 | let docs = macro_.docs(ctx.db); |
@@ -201,7 +201,7 @@ impl Completions { | |||
201 | ) { | 201 | ) { |
202 | let data = func.data(ctx.db); | 202 | let data = func.data(ctx.db); |
203 | let name = name.unwrap_or_else(|| data.name().to_string()); | 203 | let name = name.unwrap_or_else(|| data.name().to_string()); |
204 | let ast_node = func.source(ctx.db).ast; | 204 | let ast_node = func.source(ctx.db).value; |
205 | let detail = function_label(&ast_node); | 205 | let detail = function_label(&ast_node); |
206 | 206 | ||
207 | let mut builder = | 207 | let mut builder = |
@@ -234,7 +234,7 @@ impl Completions { | |||
234 | } | 234 | } |
235 | 235 | ||
236 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { | 236 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { |
237 | let ast_node = constant.source(ctx.db).ast; | 237 | let ast_node = constant.source(ctx.db).value; |
238 | let name = match ast_node.name() { | 238 | let name = match ast_node.name() { |
239 | Some(name) => name, | 239 | Some(name) => name, |
240 | _ => return, | 240 | _ => return, |
@@ -250,7 +250,7 @@ impl Completions { | |||
250 | } | 250 | } |
251 | 251 | ||
252 | pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { | 252 | pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { |
253 | let type_def = type_alias.source(ctx.db).ast; | 253 | let type_def = type_alias.source(ctx.db).value; |
254 | let name = match type_def.name() { | 254 | let name = match type_def.name() { |
255 | Some(name) => name, | 255 | Some(name) => name, |
256 | _ => return, | 256 | _ => return, |
diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index e52ffefb3..cc1ccab4b 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs | |||
@@ -96,7 +96,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> | |||
96 | }); | 96 | }); |
97 | let source_file = db.parse(file_id).tree(); | 97 | let source_file = db.parse(file_id).tree(); |
98 | let src = | 98 | let src = |
99 | hir::Source { file_id: file_id.into(), ast: hir::ModuleSource::SourceFile(source_file) }; | 99 | hir::Source { file_id: file_id.into(), value: hir::ModuleSource::SourceFile(source_file) }; |
100 | if let Some(m) = hir::Module::from_definition(db, src) { | 100 | if let Some(m) = hir::Module::from_definition(db, src) { |
101 | m.diagnostics(db, &mut sink); | 101 | m.diagnostics(db, &mut sink); |
102 | }; | 102 | }; |
diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs index 9075ca443..f42dffc87 100644 --- a/crates/ra_ide_api/src/display/function_signature.rs +++ b/crates/ra_ide_api/src/display/function_signature.rs | |||
@@ -48,12 +48,12 @@ impl FunctionSignature { | |||
48 | 48 | ||
49 | pub(crate) fn from_hir(db: &db::RootDatabase, function: hir::Function) -> Self { | 49 | pub(crate) fn from_hir(db: &db::RootDatabase, function: hir::Function) -> Self { |
50 | let doc = function.docs(db); | 50 | let doc = function.docs(db); |
51 | let ast_node = function.source(db).ast; | 51 | let ast_node = function.source(db).value; |
52 | FunctionSignature::from(&ast_node).with_doc_opt(doc) | 52 | FunctionSignature::from(&ast_node).with_doc_opt(doc) |
53 | } | 53 | } |
54 | 54 | ||
55 | pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option<Self> { | 55 | pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option<Self> { |
56 | let node: ast::StructDef = st.source(db).ast; | 56 | let node: ast::StructDef = st.source(db).value; |
57 | match node.kind() { | 57 | match node.kind() { |
58 | ast::StructKind::Named(_) => return None, | 58 | ast::StructKind::Named(_) => return None, |
59 | _ => (), | 59 | _ => (), |
@@ -87,7 +87,7 @@ impl FunctionSignature { | |||
87 | db: &db::RootDatabase, | 87 | db: &db::RootDatabase, |
88 | variant: hir::EnumVariant, | 88 | variant: hir::EnumVariant, |
89 | ) -> Option<Self> { | 89 | ) -> Option<Self> { |
90 | let node: ast::EnumVariant = variant.source(db).ast; | 90 | let node: ast::EnumVariant = variant.source(db).value; |
91 | match node.kind() { | 91 | match node.kind() { |
92 | ast::StructKind::Named(_) | ast::StructKind::Unit => return None, | 92 | ast::StructKind::Named(_) | ast::StructKind::Unit => return None, |
93 | _ => (), | 93 | _ => (), |
@@ -126,7 +126,7 @@ impl FunctionSignature { | |||
126 | } | 126 | } |
127 | 127 | ||
128 | pub(crate) fn from_macro(db: &db::RootDatabase, macro_def: hir::MacroDef) -> Option<Self> { | 128 | pub(crate) fn from_macro(db: &db::RootDatabase, macro_def: hir::MacroDef) -> Option<Self> { |
129 | let node: ast::MacroCall = macro_def.source(db).ast; | 129 | let node: ast::MacroCall = macro_def.source(db).value; |
130 | 130 | ||
131 | let params = vec![]; | 131 | let params = vec![]; |
132 | 132 | ||
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index b30ef8e05..50accafd0 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -86,9 +86,9 @@ impl NavigationTarget { | |||
86 | name, | 86 | name, |
87 | None, | 87 | None, |
88 | frange.range, | 88 | frange.range, |
89 | src.ast.syntax().kind(), | 89 | src.value.syntax().kind(), |
90 | src.ast.doc_comment_text(), | 90 | src.value.doc_comment_text(), |
91 | src.ast.short_label(), | 91 | src.value.short_label(), |
92 | ); | 92 | ); |
93 | } | 93 | } |
94 | module.to_nav(db) | 94 | module.to_nav(db) |
@@ -146,9 +146,9 @@ impl NavigationTarget { | |||
146 | description: Option<String>, | 146 | description: Option<String>, |
147 | ) -> NavigationTarget { | 147 | ) -> NavigationTarget { |
148 | //FIXME: use `_` instead of empty string | 148 | //FIXME: use `_` instead of empty string |
149 | let name = node.ast.name().map(|it| it.text().clone()).unwrap_or_default(); | 149 | let name = node.value.name().map(|it| it.text().clone()).unwrap_or_default(); |
150 | let focus_range = | 150 | let focus_range = |
151 | node.ast.name().map(|it| original_range(db, node.with_ast(it.syntax())).range); | 151 | node.value.name().map(|it| original_range(db, node.with_ast(it.syntax())).range); |
152 | let frange = original_range(db, node.map(|it| it.syntax())); | 152 | let frange = original_range(db, node.map(|it| it.syntax())); |
153 | 153 | ||
154 | NavigationTarget::from_syntax( | 154 | NavigationTarget::from_syntax( |
@@ -156,7 +156,7 @@ impl NavigationTarget { | |||
156 | name, | 156 | name, |
157 | focus_range, | 157 | focus_range, |
158 | frange.range, | 158 | frange.range, |
159 | node.ast.syntax().kind(), | 159 | node.value.syntax().kind(), |
160 | docs, | 160 | docs, |
161 | description, | 161 | description, |
162 | ) | 162 | ) |
@@ -220,8 +220,8 @@ where | |||
220 | NavigationTarget::from_named( | 220 | NavigationTarget::from_named( |
221 | db, | 221 | db, |
222 | src.as_ref().map(|it| it as &dyn ast::NameOwner), | 222 | src.as_ref().map(|it| it as &dyn ast::NameOwner), |
223 | src.ast.doc_comment_text(), | 223 | src.value.doc_comment_text(), |
224 | src.ast.short_label(), | 224 | src.value.short_label(), |
225 | ) | 225 | ) |
226 | } | 226 | } |
227 | } | 227 | } |
@@ -230,7 +230,7 @@ impl ToNav for hir::Module { | |||
230 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 230 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
231 | let src = self.definition_source(db); | 231 | let src = self.definition_source(db); |
232 | let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default(); | 232 | let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default(); |
233 | match &src.ast { | 233 | match &src.value { |
234 | ModuleSource::SourceFile(node) => { | 234 | ModuleSource::SourceFile(node) => { |
235 | let frange = original_range(db, src.with_ast(node.syntax())); | 235 | let frange = original_range(db, src.with_ast(node.syntax())); |
236 | 236 | ||
@@ -271,7 +271,7 @@ impl ToNav for hir::ImplBlock { | |||
271 | "impl".into(), | 271 | "impl".into(), |
272 | None, | 272 | None, |
273 | frange.range, | 273 | frange.range, |
274 | src.ast.syntax().kind(), | 274 | src.value.syntax().kind(), |
275 | None, | 275 | None, |
276 | None, | 276 | None, |
277 | ) | 277 | ) |
@@ -282,7 +282,7 @@ impl ToNav for hir::StructField { | |||
282 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 282 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
283 | let src = self.source(db); | 283 | let src = self.source(db); |
284 | 284 | ||
285 | match &src.ast { | 285 | match &src.value { |
286 | FieldSource::Named(it) => NavigationTarget::from_named( | 286 | FieldSource::Named(it) => NavigationTarget::from_named( |
287 | db, | 287 | db, |
288 | src.with_ast(it), | 288 | src.with_ast(it), |
@@ -308,11 +308,11 @@ impl ToNav for hir::StructField { | |||
308 | impl ToNav for hir::MacroDef { | 308 | impl ToNav for hir::MacroDef { |
309 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 309 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
310 | let src = self.source(db); | 310 | let src = self.source(db); |
311 | log::debug!("nav target {:#?}", src.ast.syntax()); | 311 | log::debug!("nav target {:#?}", src.value.syntax()); |
312 | NavigationTarget::from_named( | 312 | NavigationTarget::from_named( |
313 | db, | 313 | db, |
314 | src.as_ref().map(|it| it as &dyn ast::NameOwner), | 314 | src.as_ref().map(|it| it as &dyn ast::NameOwner), |
315 | src.ast.doc_comment_text(), | 315 | src.value.doc_comment_text(), |
316 | None, | 316 | None, |
317 | ) | 317 | ) |
318 | } | 318 | } |
@@ -341,7 +341,7 @@ impl ToNav for hir::AssocItem { | |||
341 | impl ToNav for hir::Local { | 341 | impl ToNav for hir::Local { |
342 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 342 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
343 | let src = self.source(db); | 343 | let src = self.source(db); |
344 | let (full_range, focus_range) = match src.ast { | 344 | let (full_range, focus_range) = match src.value { |
345 | Either::A(it) => { | 345 | Either::A(it) => { |
346 | (it.syntax().text_range(), it.name().map(|it| it.syntax().text_range())) | 346 | (it.syntax().text_range(), it.name().map(|it| it.syntax().text_range())) |
347 | } | 347 | } |
diff --git a/crates/ra_ide_api/src/expand.rs b/crates/ra_ide_api/src/expand.rs index 7f59e46d2..0228bced9 100644 --- a/crates/ra_ide_api/src/expand.rs +++ b/crates/ra_ide_api/src/expand.rs | |||
@@ -12,7 +12,7 @@ pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> Fi | |||
12 | None => { | 12 | None => { |
13 | return FileRange { | 13 | return FileRange { |
14 | file_id: node.file_id.original_file(db), | 14 | file_id: node.file_id.original_file(db), |
15 | range: node.ast.text_range(), | 15 | range: node.value.text_range(), |
16 | } | 16 | } |
17 | } | 17 | } |
18 | Some(it) => it, | 18 | Some(it) => it, |
@@ -25,14 +25,18 @@ pub(crate) fn original_range(db: &RootDatabase, node: Source<&SyntaxNode>) -> Fi | |||
25 | // *Second*, we should handle recurside macro expansions | 25 | // *Second*, we should handle recurside macro expansions |
26 | 26 | ||
27 | let token = node | 27 | let token = node |
28 | .ast | 28 | .value |
29 | .descendants_with_tokens() | 29 | .descendants_with_tokens() |
30 | .filter_map(|it| it.into_token()) | 30 | .filter_map(|it| it.into_token()) |
31 | .find_map(|it| expansion.map_token_up(node.with_ast(&it))); | 31 | .find_map(|it| expansion.map_token_up(node.with_ast(&it))); |
32 | 32 | ||
33 | match token { | 33 | match token { |
34 | Some(it) => FileRange { file_id: it.file_id.original_file(db), range: it.ast.text_range() }, | 34 | Some(it) => { |
35 | None => FileRange { file_id: node.file_id.original_file(db), range: node.ast.text_range() }, | 35 | FileRange { file_id: it.file_id.original_file(db), range: it.value.text_range() } |
36 | } | ||
37 | None => { | ||
38 | FileRange { file_id: node.file_id.original_file(db), range: node.value.text_range() } | ||
39 | } | ||
36 | } | 40 | } |
37 | } | 41 | } |
38 | 42 | ||
@@ -44,13 +48,13 @@ pub(crate) fn descend_into_macros( | |||
44 | let src = Source::new(file_id.into(), token); | 48 | let src = Source::new(file_id.into(), token); |
45 | 49 | ||
46 | successors(Some(src), |token| { | 50 | successors(Some(src), |token| { |
47 | let macro_call = token.ast.ancestors().find_map(ast::MacroCall::cast)?; | 51 | let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?; |
48 | let tt = macro_call.token_tree()?; | 52 | let tt = macro_call.token_tree()?; |
49 | if !token.ast.text_range().is_subrange(&tt.syntax().text_range()) { | 53 | if !token.value.text_range().is_subrange(&tt.syntax().text_range()) { |
50 | return None; | 54 | return None; |
51 | } | 55 | } |
52 | let source_analyzer = | 56 | let source_analyzer = |
53 | hir::SourceAnalyzer::new(db, token.with_ast(token.ast.parent()).as_ref(), None); | 57 | hir::SourceAnalyzer::new(db, token.with_ast(token.value.parent()).as_ref(), None); |
54 | let exp = source_analyzer.expand(db, ¯o_call)?; | 58 | let exp = source_analyzer.expand(db, ¯o_call)?; |
55 | exp.map_token_down(db, token.as_ref()) | 59 | exp.map_token_down(db, token.as_ref()) |
56 | }) | 60 | }) |
diff --git a/crates/ra_ide_api/src/expand_macro.rs b/crates/ra_ide_api/src/expand_macro.rs index e9eb2a7fb..2d478ec09 100644 --- a/crates/ra_ide_api/src/expand_macro.rs +++ b/crates/ra_ide_api/src/expand_macro.rs | |||
@@ -46,7 +46,7 @@ fn expand_macro_recur( | |||
46 | let mut replaces = FxHashMap::default(); | 46 | let mut replaces = FxHashMap::default(); |
47 | 47 | ||
48 | for child in children.into_iter() { | 48 | for child in children.into_iter() { |
49 | let source = hir::Source::new(macro_file_id, source.ast); | 49 | let source = hir::Source::new(macro_file_id, source.value); |
50 | let new_node = expand_macro_recur(db, source, &child)?; | 50 | let new_node = expand_macro_recur(db, source, &child)?; |
51 | 51 | ||
52 | replaces.insert(child.syntax().clone().into(), new_node.into()); | 52 | replaces.insert(child.syntax().clone().into(), new_node.into()); |
@@ -139,7 +139,7 @@ mod tests { | |||
139 | } | 139 | } |
140 | macro_rules! baz { | 140 | macro_rules! baz { |
141 | () => { foo!(); } | 141 | () => { foo!(); } |
142 | } | 142 | } |
143 | f<|>oo!(); | 143 | f<|>oo!(); |
144 | "#, | 144 | "#, |
145 | ); | 145 | ); |
@@ -156,7 +156,7 @@ fn b(){} | |||
156 | r#" | 156 | r#" |
157 | //- /lib.rs | 157 | //- /lib.rs |
158 | macro_rules! foo { | 158 | macro_rules! foo { |
159 | () => { | 159 | () => { |
160 | fn some_thing() -> u32 { | 160 | fn some_thing() -> u32 { |
161 | let a = 0; | 161 | let a = 0; |
162 | a + 10 | 162 | a + 10 |
@@ -172,7 +172,7 @@ fn b(){} | |||
172 | fn some_thing() -> u32 { | 172 | fn some_thing() -> u32 { |
173 | let a = 0; | 173 | let a = 0; |
174 | a+10 | 174 | a+10 |
175 | } | 175 | } |
176 | "###); | 176 | "###); |
177 | } | 177 | } |
178 | } | 178 | } |
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 3f16e9566..ed9d99a7f 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -23,7 +23,7 @@ pub(crate) fn goto_definition( | |||
23 | let token = descend_into_macros(db, position.file_id, token); | 23 | let token = descend_into_macros(db, position.file_id, token); |
24 | 24 | ||
25 | let res = match_ast! { | 25 | let res = match_ast! { |
26 | match (token.ast.parent()) { | 26 | match (token.value.parent()) { |
27 | ast::NameRef(name_ref) => { | 27 | ast::NameRef(name_ref) => { |
28 | let navs = reference_definition(db, token.with_ast(&name_ref)).to_vec(); | 28 | let navs = reference_definition(db, token.with_ast(&name_ref)).to_vec(); |
29 | RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec()) | 29 | RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec()) |
@@ -84,7 +84,7 @@ pub(crate) fn reference_definition( | |||
84 | }; | 84 | }; |
85 | 85 | ||
86 | // Fallback index based approach: | 86 | // Fallback index based approach: |
87 | let navs = crate::symbol_index::index_resolve(db, name_ref.ast) | 87 | let navs = crate::symbol_index::index_resolve(db, name_ref.value) |
88 | .into_iter() | 88 | .into_iter() |
89 | .map(|s| s.to_nav(db)) | 89 | .map(|s| s.to_nav(db)) |
90 | .collect(); | 90 | .collect(); |
@@ -95,7 +95,7 @@ pub(crate) fn name_definition( | |||
95 | db: &RootDatabase, | 95 | db: &RootDatabase, |
96 | name: Source<&ast::Name>, | 96 | name: Source<&ast::Name>, |
97 | ) -> Option<Vec<NavigationTarget>> { | 97 | ) -> Option<Vec<NavigationTarget>> { |
98 | let parent = name.ast.syntax().parent()?; | 98 | let parent = name.value.syntax().parent()?; |
99 | 99 | ||
100 | if let Some(module) = ast::Module::cast(parent.clone()) { | 100 | if let Some(module) = ast::Module::cast(parent.clone()) { |
101 | if module.has_semi() { | 101 | if module.has_semi() { |
@@ -116,7 +116,7 @@ pub(crate) fn name_definition( | |||
116 | 116 | ||
117 | fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<NavigationTarget> { | 117 | fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<NavigationTarget> { |
118 | match_ast! { | 118 | match_ast! { |
119 | match (node.ast) { | 119 | match (node.value) { |
120 | ast::StructDef(it) => { | 120 | ast::StructDef(it) => { |
121 | Some(NavigationTarget::from_named( | 121 | Some(NavigationTarget::from_named( |
122 | db, | 122 | db, |
diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs index 7d694e1f6..6aeeefa1f 100644 --- a/crates/ra_ide_api/src/goto_type_definition.rs +++ b/crates/ra_ide_api/src/goto_type_definition.rs | |||
@@ -16,7 +16,7 @@ pub(crate) fn goto_type_definition( | |||
16 | let token = file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; | 16 | let token = file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; |
17 | let token = descend_into_macros(db, position.file_id, token); | 17 | let token = descend_into_macros(db, position.file_id, token); |
18 | 18 | ||
19 | let node = token.ast.ancestors().find_map(|token| { | 19 | let node = token.value.ancestors().find_map(|token| { |
20 | token | 20 | token |
21 | .ancestors() | 21 | .ancestors() |
22 | .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some()) | 22 | .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some()) |
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 787b714b3..e8a340ba4 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -101,11 +101,11 @@ fn hover_text_from_name_kind( | |||
101 | return match name_kind { | 101 | return match name_kind { |
102 | Macro(it) => { | 102 | Macro(it) => { |
103 | let src = it.source(db); | 103 | let src = it.source(db); |
104 | hover_text(src.ast.doc_comment_text(), Some(macro_label(&src.ast))) | 104 | hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value))) |
105 | } | 105 | } |
106 | Field(it) => { | 106 | Field(it) => { |
107 | let src = it.source(db); | 107 | let src = it.source(db); |
108 | match src.ast { | 108 | match src.value { |
109 | hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()), | 109 | hir::FieldSource::Named(it) => hover_text(it.doc_comment_text(), it.short_label()), |
110 | _ => None, | 110 | _ => None, |
111 | } | 111 | } |
@@ -116,7 +116,7 @@ fn hover_text_from_name_kind( | |||
116 | hir::AssocItem::TypeAlias(it) => from_def_source(db, it), | 116 | hir::AssocItem::TypeAlias(it) => from_def_source(db, it), |
117 | }, | 117 | }, |
118 | Def(it) => match it { | 118 | Def(it) => match it { |
119 | hir::ModuleDef::Module(it) => match it.definition_source(db).ast { | 119 | hir::ModuleDef::Module(it) => match it.definition_source(db).value { |
120 | hir::ModuleSource::Module(it) => { | 120 | hir::ModuleSource::Module(it) => { |
121 | hover_text(it.doc_comment_text(), it.short_label()) | 121 | hover_text(it.doc_comment_text(), it.short_label()) |
122 | } | 122 | } |
@@ -158,7 +158,7 @@ fn hover_text_from_name_kind( | |||
158 | A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel, | 158 | A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel, |
159 | { | 159 | { |
160 | let src = def.source(db); | 160 | let src = def.source(db); |
161 | hover_text(src.ast.doc_comment_text(), src.ast.short_label()) | 161 | hover_text(src.value.doc_comment_text(), src.value.short_label()) |
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
@@ -170,7 +170,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
170 | let mut res = HoverResult::new(); | 170 | let mut res = HoverResult::new(); |
171 | 171 | ||
172 | let mut range = match_ast! { | 172 | let mut range = match_ast! { |
173 | match (token.ast.parent()) { | 173 | match (token.value.parent()) { |
174 | ast::NameRef(name_ref) => { | 174 | ast::NameRef(name_ref) => { |
175 | let mut no_fallback = false; | 175 | let mut no_fallback = false; |
176 | if let Some(name_kind) = | 176 | if let Some(name_kind) = |
@@ -211,7 +211,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
211 | }; | 211 | }; |
212 | 212 | ||
213 | if range.is_none() { | 213 | if range.is_none() { |
214 | let node = token.ast.ancestors().find(|n| { | 214 | let node = token.value.ancestors().find(|n| { |
215 | ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some() | 215 | ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some() |
216 | })?; | 216 | })?; |
217 | let frange = FileRange { file_id: position.file_id, range: node.text_range() }; | 217 | let frange = FileRange { file_id: position.file_id, range: node.text_range() }; |
diff --git a/crates/ra_ide_api/src/impls.rs b/crates/ra_ide_api/src/impls.rs index bc9b66550..3e3012559 100644 --- a/crates/ra_ide_api/src/impls.rs +++ b/crates/ra_ide_api/src/impls.rs | |||
@@ -16,7 +16,7 @@ pub(crate) fn goto_implementation( | |||
16 | let src = hir::ModuleSource::from_position(db, position); | 16 | let src = hir::ModuleSource::from_position(db, position); |
17 | let module = hir::Module::from_definition( | 17 | let module = hir::Module::from_definition( |
18 | db, | 18 | db, |
19 | hir::Source { file_id: position.file_id.into(), ast: src }, | 19 | hir::Source { file_id: position.file_id.into(), value: src }, |
20 | )?; | 20 | )?; |
21 | 21 | ||
22 | if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) { | 22 | if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) { |
@@ -42,11 +42,11 @@ fn impls_for_def( | |||
42 | ) -> Option<Vec<NavigationTarget>> { | 42 | ) -> Option<Vec<NavigationTarget>> { |
43 | let ty = match node { | 43 | let ty = match node { |
44 | ast::NominalDef::StructDef(def) => { | 44 | ast::NominalDef::StructDef(def) => { |
45 | let src = hir::Source { file_id: position.file_id.into(), ast: def.clone() }; | 45 | let src = hir::Source { file_id: position.file_id.into(), value: def.clone() }; |
46 | hir::Struct::from_source(db, src)?.ty(db) | 46 | hir::Struct::from_source(db, src)?.ty(db) |
47 | } | 47 | } |
48 | ast::NominalDef::EnumDef(def) => { | 48 | ast::NominalDef::EnumDef(def) => { |
49 | let src = hir::Source { file_id: position.file_id.into(), ast: def.clone() }; | 49 | let src = hir::Source { file_id: position.file_id.into(), value: def.clone() }; |
50 | hir::Enum::from_source(db, src)?.ty(db) | 50 | hir::Enum::from_source(db, src)?.ty(db) |
51 | } | 51 | } |
52 | }; | 52 | }; |
@@ -69,7 +69,7 @@ fn impls_for_trait( | |||
69 | node: &ast::TraitDef, | 69 | node: &ast::TraitDef, |
70 | module: hir::Module, | 70 | module: hir::Module, |
71 | ) -> Option<Vec<NavigationTarget>> { | 71 | ) -> Option<Vec<NavigationTarget>> { |
72 | let src = hir::Source { file_id: position.file_id.into(), ast: node.clone() }; | 72 | let src = hir::Source { file_id: position.file_id.into(), value: node.clone() }; |
73 | let tr = hir::Trait::from_source(db, src)?; | 73 | let tr = hir::Trait::from_source(db, src)?; |
74 | 74 | ||
75 | let krate = module.krate(); | 75 | let krate = module.krate(); |
diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs index 4c57566e2..fa232a379 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs | |||
@@ -10,7 +10,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na | |||
10 | let src = hir::ModuleSource::from_position(db, position); | 10 | let src = hir::ModuleSource::from_position(db, position); |
11 | let module = match hir::Module::from_definition( | 11 | let module = match hir::Module::from_definition( |
12 | db, | 12 | db, |
13 | hir::Source { file_id: position.file_id.into(), ast: src }, | 13 | hir::Source { file_id: position.file_id.into(), value: src }, |
14 | ) { | 14 | ) { |
15 | None => return Vec::new(), | 15 | None => return Vec::new(), |
16 | Some(it) => it, | 16 | Some(it) => it, |
@@ -23,7 +23,8 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na | |||
23 | pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { | 23 | pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> { |
24 | let src = hir::ModuleSource::from_file_id(db, file_id); | 24 | let src = hir::ModuleSource::from_file_id(db, file_id); |
25 | let module = | 25 | let module = |
26 | match hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), ast: src }) { | 26 | match hir::Module::from_definition(db, hir::Source { file_id: file_id.into(), value: src }) |
27 | { | ||
27 | Some(it) => it, | 28 | Some(it) => it, |
28 | None => return Vec::new(), | 29 | None => return Vec::new(), |
29 | }; | 30 | }; |
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs index ea9d20e71..333264540 100644 --- a/crates/ra_ide_api/src/references/classify.rs +++ b/crates/ra_ide_api/src/references/classify.rs | |||
@@ -13,7 +13,7 @@ use crate::db::RootDatabase; | |||
13 | 13 | ||
14 | pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Option<NameDefinition> { | 14 | pub(crate) fn classify_name(db: &RootDatabase, name: Source<&ast::Name>) -> Option<NameDefinition> { |
15 | let _p = profile("classify_name"); | 15 | let _p = profile("classify_name"); |
16 | let parent = name.ast.syntax().parent()?; | 16 | let parent = name.value.syntax().parent()?; |
17 | 17 | ||
18 | match_ast! { | 18 | match_ast! { |
19 | match parent { | 19 | match parent { |
@@ -121,7 +121,7 @@ pub(crate) fn classify_name_ref( | |||
121 | ) -> Option<NameDefinition> { | 121 | ) -> Option<NameDefinition> { |
122 | let _p = profile("classify_name_ref"); | 122 | let _p = profile("classify_name_ref"); |
123 | 123 | ||
124 | let parent = name_ref.ast.syntax().parent()?; | 124 | let parent = name_ref.value.syntax().parent()?; |
125 | let analyzer = SourceAnalyzer::new(db, name_ref.map(|it| it.syntax()), None); | 125 | let analyzer = SourceAnalyzer::new(db, name_ref.map(|it| it.syntax()), None); |
126 | 126 | ||
127 | if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { | 127 | if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { |
@@ -142,7 +142,7 @@ pub(crate) fn classify_name_ref( | |||
142 | tested_by!(goto_definition_works_for_record_fields); | 142 | tested_by!(goto_definition_works_for_record_fields); |
143 | if let Some(record_lit) = record_field.syntax().ancestors().find_map(ast::RecordLit::cast) { | 143 | if let Some(record_lit) = record_field.syntax().ancestors().find_map(ast::RecordLit::cast) { |
144 | let variant_def = analyzer.resolve_record_literal(&record_lit)?; | 144 | let variant_def = analyzer.resolve_record_literal(&record_lit)?; |
145 | let hir_path = Path::from_name_ref(name_ref.ast); | 145 | let hir_path = Path::from_name_ref(name_ref.value); |
146 | let hir_name = hir_path.as_ident()?; | 146 | let hir_name = hir_path.as_ident()?; |
147 | let field = variant_def.field(db, hir_name)?; | 147 | let field = variant_def.field(db, hir_name)?; |
148 | return Some(from_struct_field(db, field)); | 148 | return Some(from_struct_field(db, field)); |
@@ -162,7 +162,7 @@ pub(crate) fn classify_name_ref( | |||
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
165 | let path = name_ref.ast.syntax().ancestors().find_map(ast::Path::cast)?; | 165 | let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?; |
166 | let resolved = analyzer.resolve_path(db, &path)?; | 166 | let resolved = analyzer.resolve_path(db, &path)?; |
167 | match resolved { | 167 | match resolved { |
168 | PathResolution::Def(def) => Some(from_module_def(db, def, Some(container))), | 168 | PathResolution::Def(def) => Some(from_module_def(db, def, Some(container))), |
diff --git a/crates/ra_ide_api/src/references/name_definition.rs b/crates/ra_ide_api/src/references/name_definition.rs index ccd75278a..aca23f79e 100644 --- a/crates/ra_ide_api/src/references/name_definition.rs +++ b/crates/ra_ide_api/src/references/name_definition.rs | |||
@@ -32,9 +32,9 @@ pub(crate) struct NameDefinition { | |||
32 | pub(super) fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { | 32 | pub(super) fn from_assoc_item(db: &RootDatabase, item: AssocItem) -> NameDefinition { |
33 | let container = item.module(db); | 33 | let container = item.module(db); |
34 | let visibility = match item { | 34 | let visibility = match item { |
35 | AssocItem::Function(f) => f.source(db).ast.visibility(), | 35 | AssocItem::Function(f) => f.source(db).value.visibility(), |
36 | AssocItem::Const(c) => c.source(db).ast.visibility(), | 36 | AssocItem::Const(c) => c.source(db).value.visibility(), |
37 | AssocItem::TypeAlias(a) => a.source(db).ast.visibility(), | 37 | AssocItem::TypeAlias(a) => a.source(db).value.visibility(), |
38 | }; | 38 | }; |
39 | let kind = NameKind::AssocItem(item); | 39 | let kind = NameKind::AssocItem(item); |
40 | NameDefinition { kind, container, visibility } | 40 | NameDefinition { kind, container, visibility } |
@@ -45,8 +45,8 @@ pub(super) fn from_struct_field(db: &RootDatabase, field: StructField) -> NameDe | |||
45 | let parent = field.parent_def(db); | 45 | let parent = field.parent_def(db); |
46 | let container = parent.module(db); | 46 | let container = parent.module(db); |
47 | let visibility = match parent { | 47 | let visibility = match parent { |
48 | VariantDef::Struct(s) => s.source(db).ast.visibility(), | 48 | VariantDef::Struct(s) => s.source(db).value.visibility(), |
49 | VariantDef::EnumVariant(e) => e.source(db).ast.parent_enum().visibility(), | 49 | VariantDef::EnumVariant(e) => e.source(db).value.parent_enum().visibility(), |
50 | }; | 50 | }; |
51 | NameDefinition { kind, container, visibility } | 51 | NameDefinition { kind, container, visibility } |
52 | } | 52 | } |
@@ -60,22 +60,22 @@ pub(super) fn from_module_def( | |||
60 | let (container, visibility) = match def { | 60 | let (container, visibility) = match def { |
61 | ModuleDef::Module(it) => { | 61 | ModuleDef::Module(it) => { |
62 | let container = it.parent(db).or_else(|| Some(it)).unwrap(); | 62 | let container = it.parent(db).or_else(|| Some(it)).unwrap(); |
63 | let visibility = it.declaration_source(db).and_then(|s| s.ast.visibility()); | 63 | let visibility = it.declaration_source(db).and_then(|s| s.value.visibility()); |
64 | (container, visibility) | 64 | (container, visibility) |
65 | } | 65 | } |
66 | ModuleDef::EnumVariant(it) => { | 66 | ModuleDef::EnumVariant(it) => { |
67 | let container = it.module(db); | 67 | let container = it.module(db); |
68 | let visibility = it.source(db).ast.parent_enum().visibility(); | 68 | let visibility = it.source(db).value.parent_enum().visibility(); |
69 | (container, visibility) | 69 | (container, visibility) |
70 | } | 70 | } |
71 | ModuleDef::Function(it) => (it.module(db), it.source(db).ast.visibility()), | 71 | ModuleDef::Function(it) => (it.module(db), it.source(db).value.visibility()), |
72 | ModuleDef::Const(it) => (it.module(db), it.source(db).ast.visibility()), | 72 | ModuleDef::Const(it) => (it.module(db), it.source(db).value.visibility()), |
73 | ModuleDef::Static(it) => (it.module(db), it.source(db).ast.visibility()), | 73 | ModuleDef::Static(it) => (it.module(db), it.source(db).value.visibility()), |
74 | ModuleDef::Trait(it) => (it.module(db), it.source(db).ast.visibility()), | 74 | ModuleDef::Trait(it) => (it.module(db), it.source(db).value.visibility()), |
75 | ModuleDef::TypeAlias(it) => (it.module(db), it.source(db).ast.visibility()), | 75 | ModuleDef::TypeAlias(it) => (it.module(db), it.source(db).value.visibility()), |
76 | ModuleDef::Adt(Adt::Struct(it)) => (it.module(db), it.source(db).ast.visibility()), | 76 | ModuleDef::Adt(Adt::Struct(it)) => (it.module(db), it.source(db).value.visibility()), |
77 | ModuleDef::Adt(Adt::Union(it)) => (it.module(db), it.source(db).ast.visibility()), | 77 | ModuleDef::Adt(Adt::Union(it)) => (it.module(db), it.source(db).value.visibility()), |
78 | ModuleDef::Adt(Adt::Enum(it)) => (it.module(db), it.source(db).ast.visibility()), | 78 | ModuleDef::Adt(Adt::Enum(it)) => (it.module(db), it.source(db).value.visibility()), |
79 | ModuleDef::BuiltinType(..) => (module.unwrap(), None), | 79 | ModuleDef::BuiltinType(..) => (module.unwrap(), None), |
80 | }; | 80 | }; |
81 | NameDefinition { kind, container, visibility } | 81 | NameDefinition { kind, container, visibility } |
diff --git a/crates/ra_ide_api/src/references/rename.rs b/crates/ra_ide_api/src/references/rename.rs index 11f81cbb3..4ea372e6f 100644 --- a/crates/ra_ide_api/src/references/rename.rs +++ b/crates/ra_ide_api/src/references/rename.rs | |||
@@ -55,11 +55,11 @@ fn rename_mod( | |||
55 | ) -> Option<SourceChange> { | 55 | ) -> Option<SourceChange> { |
56 | let mut source_file_edits = Vec::new(); | 56 | let mut source_file_edits = Vec::new(); |
57 | let mut file_system_edits = Vec::new(); | 57 | let mut file_system_edits = Vec::new(); |
58 | let module_src = hir::Source { file_id: position.file_id.into(), ast: ast_module.clone() }; | 58 | let module_src = hir::Source { file_id: position.file_id.into(), value: ast_module.clone() }; |
59 | if let Some(module) = hir::Module::from_declaration(db, module_src) { | 59 | if let Some(module) = hir::Module::from_declaration(db, module_src) { |
60 | let src = module.definition_source(db); | 60 | let src = module.definition_source(db); |
61 | let file_id = src.file_id.original_file(db); | 61 | let file_id = src.file_id.original_file(db); |
62 | match src.ast { | 62 | match src.value { |
63 | ModuleSource::SourceFile(..) => { | 63 | ModuleSource::SourceFile(..) => { |
64 | let mod_path: RelativePathBuf = db.file_relative_path(file_id); | 64 | let mod_path: RelativePathBuf = db.file_relative_path(file_id); |
65 | // mod is defined in path/to/dir/mod.rs | 65 | // mod is defined in path/to/dir/mod.rs |
diff --git a/crates/ra_ide_api/src/references/search_scope.rs b/crates/ra_ide_api/src/references/search_scope.rs index 2907787c2..f5c9589f4 100644 --- a/crates/ra_ide_api/src/references/search_scope.rs +++ b/crates/ra_ide_api/src/references/search_scope.rs | |||
@@ -73,9 +73,9 @@ impl NameDefinition { | |||
73 | 73 | ||
74 | if let NameKind::Local(var) = self.kind { | 74 | if let NameKind::Local(var) = self.kind { |
75 | let range = match var.parent(db) { | 75 | let range = match var.parent(db) { |
76 | DefWithBody::Function(f) => f.source(db).ast.syntax().text_range(), | 76 | DefWithBody::Function(f) => f.source(db).value.syntax().text_range(), |
77 | DefWithBody::Const(c) => c.source(db).ast.syntax().text_range(), | 77 | DefWithBody::Const(c) => c.source(db).value.syntax().text_range(), |
78 | DefWithBody::Static(s) => s.source(db).ast.syntax().text_range(), | 78 | DefWithBody::Static(s) => s.source(db).value.syntax().text_range(), |
79 | }; | 79 | }; |
80 | let mut res = FxHashMap::default(); | 80 | let mut res = FxHashMap::default(); |
81 | res.insert(file_id, Some(range)); | 81 | res.insert(file_id, Some(range)); |
@@ -91,7 +91,7 @@ impl NameDefinition { | |||
91 | let parent_src = parent_module.definition_source(db); | 91 | let parent_src = parent_module.definition_source(db); |
92 | let file_id = parent_src.file_id.original_file(db); | 92 | let file_id = parent_src.file_id.original_file(db); |
93 | 93 | ||
94 | match parent_src.ast { | 94 | match parent_src.value { |
95 | ModuleSource::Module(m) => { | 95 | ModuleSource::Module(m) => { |
96 | let range = Some(m.syntax().text_range()); | 96 | let range = Some(m.syntax().text_range()); |
97 | res.insert(file_id, range); | 97 | res.insert(file_id, range); |
@@ -135,7 +135,7 @@ impl NameDefinition { | |||
135 | } | 135 | } |
136 | 136 | ||
137 | let mut res = FxHashMap::default(); | 137 | let mut res = FxHashMap::default(); |
138 | let range = match module_src.ast { | 138 | let range = match module_src.value { |
139 | ModuleSource::Module(m) => Some(m.syntax().text_range()), | 139 | ModuleSource::Module(m) => Some(m.syntax().text_range()), |
140 | ModuleSource::SourceFile(_) => None, | 140 | ModuleSource::SourceFile(_) => None, |
141 | }; | 141 | }; |