aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-12-17 14:45:26 +0000
committerJonas Schievink <[email protected]>2020-12-17 14:45:26 +0000
commit9231821c031ddada08d37547664b276d5e631f62 (patch)
tree7077e360ba55f13a1b210d43fcef31dd73ceae70 /crates
parent3f6077ffe75a31dd53e77719d3369605b6f8b7a5 (diff)
Make `Attrs::from_attrs_owner` private
Diffstat (limited to 'crates')
-rw-r--r--crates/hir/src/code_model.rs1
-rw-r--r--crates/hir_def/src/attr.rs2
-rw-r--r--crates/ide/src/display/navigation_target.rs30
-rw-r--r--crates/ide/src/runnables.rs20
4 files changed, 13 insertions, 40 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 84e8c8047..2c0e0eae0 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -1325,6 +1325,7 @@ impl Impl {
1325 let item = src.file_id.is_builtin_derive(db.upcast())?; 1325 let item = src.file_id.is_builtin_derive(db.upcast())?;
1326 let hygenic = hir_expand::hygiene::Hygiene::new(db.upcast(), item.file_id); 1326 let hygenic = hir_expand::hygiene::Hygiene::new(db.upcast(), item.file_id);
1327 1327
1328 // FIXME: handle `cfg_attr`
1328 let attr = item 1329 let attr = item
1329 .value 1330 .value
1330 .attrs() 1331 .attrs()
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs
index c64b78445..45313f335 100644
--- a/crates/hir_def/src/attr.rs
+++ b/crates/hir_def/src/attr.rs
@@ -104,7 +104,7 @@ impl Attrs {
104 } 104 }
105 } 105 }
106 106
107 pub fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs { 107 fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs {
108 let hygiene = Hygiene::new(db.upcast(), owner.file_id); 108 let hygiene = Hygiene::new(db.upcast(), owner.file_id);
109 Attrs::new(owner.value, &hygiene) 109 Attrs::new(owner.value, &hygiene)
110 } 110 }
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index 54b33a98e..8410bf5a2 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -1,9 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use either::Either; 3use either::Either;
4use hir::{ 4use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource};
5 AssocItem, Documentation, FieldSource, HasAttrs, HasSource, HirFileId, InFile, ModuleSource,
6};
7use ide_db::base_db::{FileId, SourceDatabase}; 5use ide_db::base_db::{FileId, SourceDatabase};
8use ide_db::{defs::Definition, RootDatabase}; 6use ide_db::{defs::Definition, RootDatabase};
9use syntax::{ 7use syntax::{
@@ -168,7 +166,7 @@ impl ToNav for FileSymbol {
168 focus_range: self.name_range, 166 focus_range: self.name_range,
169 container_name: self.container_name.clone(), 167 container_name: self.container_name.clone(),
170 description: description_from_symbol(db, self), 168 description: description_from_symbol(db, self),
171 docs: docs_from_symbol(db, self), 169 docs: None,
172 } 170 }
173 } 171 }
174} 172}
@@ -394,30 +392,6 @@ impl ToNav for hir::LifetimeParam {
394 } 392 }
395} 393}
396 394
397pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<Documentation> {
398 let parse = db.parse(symbol.file_id);
399 let node = symbol.ptr.to_node(parse.tree().syntax());
400 let file_id = HirFileId::from(symbol.file_id);
401
402 let it = match_ast! {
403 match node {
404 ast::Fn(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
405 ast::Struct(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
406 ast::Enum(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
407 ast::Trait(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
408 ast::Module(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
409 ast::TypeAlias(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
410 ast::Const(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
411 ast::Static(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
412 ast::RecordField(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
413 ast::Variant(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
414 ast::MacroCall(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
415 _ => return None,
416 }
417 };
418 it.docs()
419}
420
421/// Get a description of a symbol. 395/// Get a description of a symbol.
422/// 396///
423/// e.g. `struct Name`, `enum Name`, `fn Name` 397/// e.g. `struct Name`, `enum Name`, `fn Name`
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index 96462a7b0..a2a0ad43d 100644
--- a/crates/ide/src/runnables.rs
+++ b/crates/ide/src/runnables.rs
@@ -2,7 +2,7 @@ use std::fmt;
2 2
3use assists::utils::test_related_attribute; 3use assists::utils::test_related_attribute;
4use cfg::CfgExpr; 4use cfg::CfgExpr;
5use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics}; 5use hir::{AsAssocItem, HasAttrs, InFile, Semantics};
6use ide_db::RootDatabase; 6use ide_db::RootDatabase;
7use itertools::Itertools; 7use itertools::Itertools;
8use syntax::{ 8use syntax::{
@@ -105,7 +105,7 @@ pub(crate) fn runnable(
105 match item { 105 match item {
106 ast::Struct(it) => runnable_struct(sema, it, file_id), 106 ast::Struct(it) => runnable_struct(sema, it, file_id),
107 ast::Fn(it) => runnable_fn(sema, it, file_id), 107 ast::Fn(it) => runnable_fn(sema, it, file_id),
108 ast::Module(it) => runnable_mod(sema, it, file_id), 108 ast::Module(it) => runnable_mod(sema, it),
109 _ => None, 109 _ => None,
110 } 110 }
111 } 111 }
@@ -116,9 +116,10 @@ fn runnable_fn(
116 fn_def: ast::Fn, 116 fn_def: ast::Fn,
117 file_id: FileId, 117 file_id: FileId,
118) -> Option<Runnable> { 118) -> Option<Runnable> {
119 let def = sema.to_def(&fn_def)?;
119 let name_string = fn_def.name()?.text().to_string(); 120 let name_string = fn_def.name()?.text().to_string();
120 121
121 let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def)); 122 let attrs = def.attrs(sema.db);
122 let kind = if name_string == "main" { 123 let kind = if name_string == "main" {
123 RunnableKind::Bin 124 RunnableKind::Bin
124 } else { 125 } else {
@@ -189,10 +190,10 @@ fn runnable_struct(
189 struct_def: ast::Struct, 190 struct_def: ast::Struct,
190 file_id: FileId, 191 file_id: FileId,
191) -> Option<Runnable> { 192) -> Option<Runnable> {
193 let def = sema.to_def(&struct_def)?;
192 let name_string = struct_def.name()?.text().to_string(); 194 let name_string = struct_def.name()?.text().to_string();
193 195
194 let attrs = 196 let attrs = def.attrs(sema.db);
195 Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &struct_def));
196 if !has_runnable_doc_test(&attrs) { 197 if !has_runnable_doc_test(&attrs) {
197 return None; 198 return None;
198 } 199 }
@@ -262,11 +263,7 @@ fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool {
262 }) 263 })
263} 264}
264 265
265fn runnable_mod( 266fn runnable_mod(sema: &Semantics<RootDatabase>, module: ast::Module) -> Option<Runnable> {
266 sema: &Semantics<RootDatabase>,
267 module: ast::Module,
268 file_id: FileId,
269) -> Option<Runnable> {
270 if !has_test_function_or_multiple_test_submodules(&module) { 267 if !has_test_function_or_multiple_test_submodules(&module) {
271 return None; 268 return None;
272 } 269 }
@@ -279,7 +276,8 @@ fn runnable_mod(
279 .filter_map(|it| it.name(sema.db)) 276 .filter_map(|it| it.name(sema.db))
280 .join("::"); 277 .join("::");
281 278
282 let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &module)); 279 let def = sema.to_def(&module)?;
280 let attrs = def.attrs(sema.db);
283 let cfg = attrs.cfg(); 281 let cfg = attrs.cfg();
284 let nav = module_def.to_nav(sema.db); 282 let nav = module_def.to_nav(sema.db);
285 Some(Runnable { nav, kind: RunnableKind::TestMod { path }, cfg }) 283 Some(Runnable { nav, kind: RunnableKind::TestMod { path }, cfg })