mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
use Source for module, part 2
This commit is contained in:
parent
0145d06515
commit
dd63f17027
3 changed files with 8 additions and 8 deletions
|
@ -210,11 +210,11 @@ impl Module {
|
||||||
pub fn declaration_source(
|
pub fn declaration_source(
|
||||||
self,
|
self,
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
db: &(impl DefDatabase + AstDatabase),
|
||||||
) -> Option<(HirFileId, TreeArc<ast::Module>)> {
|
) -> Option<Source<TreeArc<ast::Module>>> {
|
||||||
let def_map = db.crate_def_map(self.krate);
|
let def_map = db.crate_def_map(self.krate);
|
||||||
let decl = def_map[self.module_id].declaration?;
|
let decl = def_map[self.module_id].declaration?;
|
||||||
let ast = decl.to_node(db);
|
let ast = decl.to_node(db);
|
||||||
Some((decl.file_id(), ast))
|
Some((decl.file_id(), ast).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the syntax of the last path segment corresponding to this import
|
/// Returns the syntax of the last path segment corresponding to this import
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub(crate) fn documentation_query(
|
||||||
def: DocDef,
|
def: DocDef,
|
||||||
) -> Option<Documentation> {
|
) -> Option<Documentation> {
|
||||||
match def {
|
match def {
|
||||||
DocDef::Module(it) => docs_from_ast(&*it.declaration_source(db)?.1),
|
DocDef::Module(it) => docs_from_ast(&*it.declaration_source(db)?.ast),
|
||||||
DocDef::StructField(it) => match it.source(db).ast {
|
DocDef::StructField(it) => match it.source(db).ast {
|
||||||
FieldSource::Named(named) => docs_from_ast(&*named),
|
FieldSource::Named(named) => docs_from_ast(&*named),
|
||||||
FieldSource::Pos(..) => return None,
|
FieldSource::Pos(..) => return None,
|
||||||
|
|
|
@ -149,15 +149,15 @@ impl NavigationTarget {
|
||||||
|
|
||||||
pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
|
pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
|
||||||
let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
|
let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
|
||||||
if let Some((file_id, source)) = module.declaration_source(db) {
|
if let Some(src) = module.declaration_source(db) {
|
||||||
let file_id = file_id.as_original_file();
|
let file_id = src.file_id.as_original_file();
|
||||||
return NavigationTarget::from_syntax(
|
return NavigationTarget::from_syntax(
|
||||||
file_id,
|
file_id,
|
||||||
name,
|
name,
|
||||||
None,
|
None,
|
||||||
source.syntax(),
|
src.ast.syntax(),
|
||||||
source.doc_comment_text(),
|
src.ast.doc_comment_text(),
|
||||||
source.short_label(),
|
src.ast.short_label(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
NavigationTarget::from_module(db, module)
|
NavigationTarget::from_module(db, module)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue