aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
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/ide
parent3f6077ffe75a31dd53e77719d3369605b6f8b7a5 (diff)
Make `Attrs::from_attrs_owner` private
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/display/navigation_target.rs30
-rw-r--r--crates/ide/src/runnables.rs20
2 files changed, 11 insertions, 39 deletions
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 })