Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/hir/src/code_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,7 @@ impl Impl {
let item = src.file_id.is_builtin_derive(db.upcast())?;
let hygenic = hir_expand::hygiene::Hygiene::new(db.upcast(), item.file_id);

// FIXME: handle `cfg_attr`
let attr = item
.value
.attrs()
Expand Down
2 changes: 1 addition & 1 deletion crates/hir_def/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Attrs {
}
}

pub fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs {
fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs {
let hygiene = Hygiene::new(db.upcast(), owner.file_id);
Attrs::new(owner.value, &hygiene)
}
Expand Down
30 changes: 2 additions & 28 deletions crates/ide/src/display/navigation_target.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! FIXME: write short doc here

use either::Either;
use hir::{
AssocItem, Documentation, FieldSource, HasAttrs, HasSource, HirFileId, InFile, ModuleSource,
};
use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource};
use ide_db::base_db::{FileId, SourceDatabase};
use ide_db::{defs::Definition, RootDatabase};
use syntax::{
Expand Down Expand Up @@ -168,7 +166,7 @@ impl ToNav for FileSymbol {
focus_range: self.name_range,
container_name: self.container_name.clone(),
description: description_from_symbol(db, self),
docs: docs_from_symbol(db, self),
docs: None,
}
}
}
Expand Down Expand Up @@ -394,30 +392,6 @@ impl ToNav for hir::LifetimeParam {
}
}

pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<Documentation> {
let parse = db.parse(symbol.file_id);
let node = symbol.ptr.to_node(parse.tree().syntax());
let file_id = HirFileId::from(symbol.file_id);

let it = match_ast! {
match node {
ast::Fn(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
ast::Struct(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
ast::Enum(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
ast::Trait(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
ast::Module(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
ast::TypeAlias(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
ast::Const(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
ast::Static(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
ast::RecordField(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
ast::Variant(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
ast::MacroCall(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
_ => return None,
}
};
it.docs()
}

/// Get a description of a symbol.
///
/// e.g. `struct Name`, `enum Name`, `fn Name`
Expand Down
20 changes: 9 additions & 11 deletions crates/ide/src/runnables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt;

use assists::utils::test_related_attribute;
use cfg::CfgExpr;
use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics};
use hir::{AsAssocItem, HasAttrs, InFile, Semantics};
use ide_db::RootDatabase;
use itertools::Itertools;
use syntax::{
Expand Down Expand Up @@ -105,7 +105,7 @@ pub(crate) fn runnable(
match item {
ast::Struct(it) => runnable_struct(sema, it, file_id),
ast::Fn(it) => runnable_fn(sema, it, file_id),
ast::Module(it) => runnable_mod(sema, it, file_id),
ast::Module(it) => runnable_mod(sema, it),
_ => None,
}
}
Expand All @@ -116,9 +116,10 @@ fn runnable_fn(
fn_def: ast::Fn,
file_id: FileId,
) -> Option<Runnable> {
let def = sema.to_def(&fn_def)?;
let name_string = fn_def.name()?.text().to_string();

let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def));
let attrs = def.attrs(sema.db);
let kind = if name_string == "main" {
RunnableKind::Bin
} else {
Expand Down Expand Up @@ -189,10 +190,10 @@ fn runnable_struct(
struct_def: ast::Struct,
file_id: FileId,
) -> Option<Runnable> {
let def = sema.to_def(&struct_def)?;
let name_string = struct_def.name()?.text().to_string();

let attrs =
Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &struct_def));
let attrs = def.attrs(sema.db);
if !has_runnable_doc_test(&attrs) {
return None;
}
Expand Down Expand Up @@ -262,11 +263,7 @@ fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool {
})
}

fn runnable_mod(
sema: &Semantics<RootDatabase>,
module: ast::Module,
file_id: FileId,
) -> Option<Runnable> {
fn runnable_mod(sema: &Semantics<RootDatabase>, module: ast::Module) -> Option<Runnable> {
if !has_test_function_or_multiple_test_submodules(&module) {
return None;
}
Expand All @@ -279,7 +276,8 @@ fn runnable_mod(
.filter_map(|it| it.name(sema.db))
.join("::");

let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &module));
let def = sema.to_def(&module)?;
let attrs = def.attrs(sema.db);
let cfg = attrs.cfg();
let nav = module_def.to_nav(sema.db);
Some(Runnable { nav, kind: RunnableKind::TestMod { path }, cfg })
Expand Down