mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Merge #6916
6916: Make `Attrs::from_attrs_owner` private r=matklad a=jonas-schievink It is only meant for use inside `hir` crates. Removes `docs_from_symbol`, which didn't seem to have any visible effect in VS Code. Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
763824e775
4 changed files with 13 additions and 40 deletions
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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::{
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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`
|
||||
|
|
|
@ -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::{
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 })
|
||||
|
|
Loading…
Reference in a new issue