Skip to content

Commit 763824e

Browse files
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 <[email protected]>
2 parents 3f6077f + 9231821 commit 763824e

File tree

4 files changed

+13
-40
lines changed

4 files changed

+13
-40
lines changed

crates/hir/src/code_model.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,7 @@ impl Impl {
13251325
let item = src.file_id.is_builtin_derive(db.upcast())?;
13261326
let hygenic = hir_expand::hygiene::Hygiene::new(db.upcast(), item.file_id);
13271327

1328+
// FIXME: handle `cfg_attr`
13281329
let attr = item
13291330
.value
13301331
.attrs()

crates/hir_def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Attrs {
104104
}
105105
}
106106

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 {
108108
let hygiene = Hygiene::new(db.upcast(), owner.file_id);
109109
Attrs::new(owner.value, &hygiene)
110110
}

crates/ide/src/display/navigation_target.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//! FIXME: write short doc here
22
33
use either::Either;
4-
use hir::{
5-
AssocItem, Documentation, FieldSource, HasAttrs, HasSource, HirFileId, InFile, ModuleSource,
6-
};
4+
use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, ModuleSource};
75
use ide_db::base_db::{FileId, SourceDatabase};
86
use ide_db::{defs::Definition, RootDatabase};
97
use syntax::{
@@ -168,7 +166,7 @@ impl ToNav for FileSymbol {
168166
focus_range: self.name_range,
169167
container_name: self.container_name.clone(),
170168
description: description_from_symbol(db, self),
171-
docs: docs_from_symbol(db, self),
169+
docs: None,
172170
}
173171
}
174172
}
@@ -394,30 +392,6 @@ impl ToNav for hir::LifetimeParam {
394392
}
395393
}
396394

397-
pub(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-
421395
/// Get a description of a symbol.
422396
///
423397
/// e.g. `struct Name`, `enum Name`, `fn Name`

crates/ide/src/runnables.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22

33
use assists::utils::test_related_attribute;
44
use cfg::CfgExpr;
5-
use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics};
5+
use hir::{AsAssocItem, HasAttrs, InFile, Semantics};
66
use ide_db::RootDatabase;
77
use itertools::Itertools;
88
use syntax::{
@@ -105,7 +105,7 @@ pub(crate) fn runnable(
105105
match item {
106106
ast::Struct(it) => runnable_struct(sema, it, file_id),
107107
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),
109109
_ => None,
110110
}
111111
}
@@ -116,9 +116,10 @@ fn runnable_fn(
116116
fn_def: ast::Fn,
117117
file_id: FileId,
118118
) -> Option<Runnable> {
119+
let def = sema.to_def(&fn_def)?;
119120
let name_string = fn_def.name()?.text().to_string();
120121

121-
let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def));
122+
let attrs = def.attrs(sema.db);
122123
let kind = if name_string == "main" {
123124
RunnableKind::Bin
124125
} else {
@@ -189,10 +190,10 @@ fn runnable_struct(
189190
struct_def: ast::Struct,
190191
file_id: FileId,
191192
) -> Option<Runnable> {
193+
let def = sema.to_def(&struct_def)?;
192194
let name_string = struct_def.name()?.text().to_string();
193195

194-
let attrs =
195-
Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &struct_def));
196+
let attrs = def.attrs(sema.db);
196197
if !has_runnable_doc_test(&attrs) {
197198
return None;
198199
}
@@ -262,11 +263,7 @@ fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool {
262263
})
263264
}
264265

265-
fn runnable_mod(
266-
sema: &Semantics<RootDatabase>,
267-
module: ast::Module,
268-
file_id: FileId,
269-
) -> Option<Runnable> {
266+
fn runnable_mod(sema: &Semantics<RootDatabase>, module: ast::Module) -> Option<Runnable> {
270267
if !has_test_function_or_multiple_test_submodules(&module) {
271268
return None;
272269
}
@@ -279,7 +276,8 @@ fn runnable_mod(
279276
.filter_map(|it| it.name(sema.db))
280277
.join("::");
281278

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);
283281
let cfg = attrs.cfg();
284282
let nav = module_def.to_nav(sema.db);
285283
Some(Runnable { nav, kind: RunnableKind::TestMod { path }, cfg })

0 commit comments

Comments
 (0)