aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-06-11 01:17:29 +0100
committerAleksey Kladov <[email protected]>2019-06-11 16:28:51 +0100
commit2a1fe26b6d354dbbd1b3843d288d56e74fa00557 (patch)
tree6784274854b9808eb997eb868d5a4f2bc889f9a3
parent91c120ccea4f0cfef20fd4d918154c8152f83816 (diff)
use Source more
-rw-r--r--crates/ra_hir/src/adt.rs21
-rw-r--r--crates/ra_hir/src/code_model.rs9
-rw-r--r--crates/ra_hir/src/docs.rs4
-rw-r--r--crates/ra_hir/src/generics.rs2
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs50
-rw-r--r--crates/ra_ide_api/src/hover.rs15
7 files changed, 39 insertions, 64 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 36679e99b..2b372333f 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -11,7 +11,7 @@ use ra_syntax::{
11 11
12use crate::{ 12use crate::{
13 Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase, 13 Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase,
14 HirDatabase, HirFileId, StructField, FieldSource, 14 HirDatabase, HirFileId, StructField, FieldSource, Source,
15 type_ref::TypeRef, DefDatabase, 15 type_ref::TypeRef, DefDatabase,
16}; 16};
17 17
@@ -72,15 +72,15 @@ impl EnumVariant {
72 pub(crate) fn source_impl( 72 pub(crate) fn source_impl(
73 &self, 73 &self,
74 db: &(impl DefDatabase + AstDatabase), 74 db: &(impl DefDatabase + AstDatabase),
75 ) -> (HirFileId, TreeArc<ast::EnumVariant>) { 75 ) -> Source<TreeArc<ast::EnumVariant>> {
76 let (file_id, enum_def) = self.parent.source(db); 76 let src = self.parent.source(db);
77 let var = variants(&*enum_def) 77 let ast = variants(&*src.ast)
78 .zip(db.enum_data(self.parent).variants.iter()) 78 .zip(db.enum_data(self.parent).variants.iter())
79 .find(|(_syntax, (id, _))| *id == self.id) 79 .find(|(_syntax, (id, _))| *id == self.id)
80 .unwrap() 80 .unwrap()
81 .0 81 .0
82 .to_owned(); 82 .to_owned();
83 (file_id, var) 83 Source { file_id: src.file_id, ast }
84 } 84 }
85 pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> { 85 pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> {
86 db.enum_data(self.parent).variants[self.id].variant_data.clone() 86 db.enum_data(self.parent).variants[self.id].variant_data.clone()
@@ -95,9 +95,9 @@ pub struct EnumData {
95 95
96impl EnumData { 96impl EnumData {
97 pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> { 97 pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> {
98 let (_file_id, enum_def) = e.source(db); 98 let src = e.source(db);
99 let name = enum_def.name().map(|n| n.as_name()); 99 let name = src.ast.name().map(|n| n.as_name());
100 let variants = variants(&*enum_def) 100 let variants = variants(&*src.ast)
101 .map(|var| EnumVariantData { 101 .map(|var| EnumVariantData {
102 name: var.name().map(|it| it.as_name()), 102 name: var.name().map(|it| it.as_name()),
103 variant_data: Arc::new(VariantData::new(var.kind())), 103 variant_data: Arc::new(VariantData::new(var.kind())),
@@ -215,9 +215,8 @@ impl StructField {
215 (ss.file_id, ss.ast.kind()) 215 (ss.file_id, ss.ast.kind())
216 } 216 }
217 VariantDef::EnumVariant(e) => { 217 VariantDef::EnumVariant(e) => {
218 let (file_id, source) = e.source(db); 218 es = e.source(db);
219 es = source; 219 (es.file_id, es.ast.kind())
220 (file_id, es.kind())
221 } 220 }
222 }; 221 };
223 222
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 3469da18a..63fdca55e 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -456,11 +456,8 @@ pub struct Enum {
456} 456}
457 457
458impl Enum { 458impl Enum {
459 pub fn source( 459 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::EnumDef>> {
460 self, 460 self.id.source(db).into()
461 db: &(impl DefDatabase + AstDatabase),
462 ) -> (HirFileId, TreeArc<ast::EnumDef>) {
463 self.id.source(db)
464 } 461 }
465 462
466 pub fn module(self, db: &impl HirDatabase) -> Module { 463 pub fn module(self, db: &impl HirDatabase) -> Module {
@@ -509,7 +506,7 @@ impl EnumVariant {
509 pub fn source( 506 pub fn source(
510 &self, 507 &self,
511 db: &(impl DefDatabase + AstDatabase), 508 db: &(impl DefDatabase + AstDatabase),
512 ) -> (HirFileId, TreeArc<ast::EnumVariant>) { 509 ) -> Source<TreeArc<ast::EnumVariant>> {
513 self.source_impl(db) 510 self.source_impl(db)
514 } 511 }
515 pub fn module(&self, db: &impl HirDatabase) -> Module { 512 pub fn module(&self, db: &impl HirDatabase) -> Module {
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs
index edd937901..70b9d13b2 100644
--- a/crates/ra_hir/src/docs.rs
+++ b/crates/ra_hir/src/docs.rs
@@ -77,8 +77,8 @@ pub(crate) fn documentation_query(
77 FieldSource::Pos(..) => return None, 77 FieldSource::Pos(..) => return None,
78 }, 78 },
79 DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast), 79 DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast),
80 DocDef::Enum(it) => docs_from_ast(&*it.source(db).1), 80 DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast),
81 DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).1), 81 DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast),
82 DocDef::Static(it) => docs_from_ast(&*it.source(db).1), 82 DocDef::Static(it) => docs_from_ast(&*it.source(db).1),
83 DocDef::Const(it) => docs_from_ast(&*it.source(db).1), 83 DocDef::Const(it) => docs_from_ast(&*it.source(db).1),
84 DocDef::Function(it) => docs_from_ast(&*it.source(db).1), 84 DocDef::Function(it) => docs_from_ast(&*it.source(db).1),
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 294a00721..2a92d5945 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -71,7 +71,7 @@ impl GenericParams {
71 GenericDef::Function(it) => generics.fill(&*it.source(db).1, start), 71 GenericDef::Function(it) => generics.fill(&*it.source(db).1, start),
72 GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start), 72 GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start),
73 GenericDef::Union(it) => generics.fill(&*it.source(db).1, start), 73 GenericDef::Union(it) => generics.fill(&*it.source(db).1, start),
74 GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start), 74 GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start),
75 GenericDef::Trait(it) => { 75 GenericDef::Trait(it) => {
76 // traits get the Self type as an implicit first type parameter 76 // traits get the Self type as an implicit first type parameter
77 generics.params.push(GenericParam { 77 generics.params.push(GenericParam {
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 0e4aaf678..90e3f1275 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -81,5 +81,5 @@ pub use self::code_model::{
81 StructField, FieldSource, 81 StructField, FieldSource,
82 Static, Const, ConstSignature, 82 Static, Const, ConstSignature,
83 Trait, TypeAlias, MacroDef, Container, 83 Trait, TypeAlias, MacroDef, Container,
84 BuiltinType, 84 BuiltinType, Source,
85}; 85};
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index c02bc005b..7c68bb41c 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -207,12 +207,12 @@ impl NavigationTarget {
207 ) 207 )
208 } 208 }
209 hir::AdtDef::Enum(s) => { 209 hir::AdtDef::Enum(s) => {
210 let (file_id, node) = s.source(db); 210 let src = s.source(db);
211 NavigationTarget::from_named( 211 NavigationTarget::from_named(
212 file_id.original_file(db), 212 src.file_id.original_file(db),
213 &*node, 213 &*src.ast,
214 node.doc_comment_text(), 214 src.ast.doc_comment_text(),
215 node.short_label(), 215 src.ast.short_label(),
216 ) 216 )
217 } 217 }
218 } 218 }
@@ -225,24 +225,9 @@ impl NavigationTarget {
225 let nav = match module_def { 225 let nav = match module_def {
226 hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), 226 hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module),
227 hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func), 227 hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func),
228 hir::ModuleDef::Struct(s) => { 228 hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()),
229 let src = s.source(db); 229 hir::ModuleDef::Enum(it) => NavigationTarget::from_adt_def(db, it.into()),
230 NavigationTarget::from_named( 230 hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()),
231 src.file_id.original_file(db),
232 &*src.ast,
233 src.ast.doc_comment_text(),
234 src.ast.short_label(),
235 )
236 }
237 hir::ModuleDef::Union(s) => {
238 let (file_id, node) = s.source(db);
239 NavigationTarget::from_named(
240 file_id.original_file(db),
241 &*node,
242 node.doc_comment_text(),
243 node.short_label(),
244 )
245 }
246 hir::ModuleDef::Const(s) => { 231 hir::ModuleDef::Const(s) => {
247 let (file_id, node) = s.source(db); 232 let (file_id, node) = s.source(db);
248 NavigationTarget::from_named( 233 NavigationTarget::from_named(
@@ -261,22 +246,13 @@ impl NavigationTarget {
261 node.short_label(), 246 node.short_label(),
262 ) 247 )
263 } 248 }
264 hir::ModuleDef::Enum(e) => {
265 let (file_id, node) = e.source(db);
266 NavigationTarget::from_named(
267 file_id.original_file(db),
268 &*node,
269 node.doc_comment_text(),
270 node.short_label(),
271 )
272 }
273 hir::ModuleDef::EnumVariant(var) => { 249 hir::ModuleDef::EnumVariant(var) => {
274 let (file_id, node) = var.source(db); 250 let src = var.source(db);
275 NavigationTarget::from_named( 251 NavigationTarget::from_named(
276 file_id.original_file(db), 252 src.file_id.original_file(db),
277 &*node, 253 &*src.ast,
278 node.doc_comment_text(), 254 src.ast.doc_comment_text(),
279 node.short_label(), 255 src.ast.short_label(),
280 ) 256 )
281 } 257 }
282 hir::ModuleDef::Trait(e) => { 258 hir::ModuleDef::Trait(e) => {
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 80445761c..ee0f2dde8 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -144,12 +144,12 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
144 res.extend(hover_text(it.doc_comment_text(), it.short_label())) 144 res.extend(hover_text(it.doc_comment_text(), it.short_label()))
145 } 145 }
146 hir::ModuleDef::Enum(it) => { 146 hir::ModuleDef::Enum(it) => {
147 let it = it.source(db).1; 147 let src = it.source(db);
148 res.extend(hover_text(it.doc_comment_text(), it.short_label())) 148 res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
149 } 149 }
150 hir::ModuleDef::EnumVariant(it) => { 150 hir::ModuleDef::EnumVariant(it) => {
151 let it = it.source(db).1; 151 let src = it.source(db);
152 res.extend(hover_text(it.doc_comment_text(), it.short_label())) 152 res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
153 } 153 }
154 hir::ModuleDef::Const(it) => { 154 hir::ModuleDef::Const(it) => {
155 let it = it.source(db).1; 155 let it = it.source(db).1;
@@ -187,8 +187,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
187 res.extend(hover_text(it.doc_comment_text(), it.short_label())) 187 res.extend(hover_text(it.doc_comment_text(), it.short_label()))
188 } 188 }
189 hir::AdtDef::Enum(it) => { 189 hir::AdtDef::Enum(it) => {
190 let it = it.source(db).1; 190 let src = it.source(db);
191 res.extend(hover_text(it.doc_comment_text(), it.short_label())) 191 res.extend(hover_text(
192 src.ast.doc_comment_text(),
193 src.ast.short_label(),
194 ))
192 } 195 }
193 } 196 }
194 } 197 }