mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 13:33:31 +00:00
More sources
This commit is contained in:
parent
9fcd98e956
commit
5e8c22dbf3
2 changed files with 32 additions and 41 deletions
|
@ -6,7 +6,7 @@ use ra_syntax::{
|
||||||
ast::{self, DocCommentsOwner, NameOwner},
|
ast::{self, DocCommentsOwner, NameOwner},
|
||||||
match_ast, AstNode, SmolStr,
|
match_ast, AstNode, SmolStr,
|
||||||
SyntaxKind::{self, BIND_PAT},
|
SyntaxKind::{self, BIND_PAT},
|
||||||
SyntaxNode, TextRange,
|
TextRange,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{db::RootDatabase, expand::original_range, FileSymbol};
|
use crate::{db::RootDatabase, expand::original_range, FileSymbol};
|
||||||
|
@ -86,7 +86,7 @@ impl NavigationTarget {
|
||||||
name,
|
name,
|
||||||
None,
|
None,
|
||||||
frange.range,
|
frange.range,
|
||||||
src.ast.syntax(),
|
src.ast.syntax().kind(),
|
||||||
src.ast.doc_comment_text(),
|
src.ast.doc_comment_text(),
|
||||||
src.ast.short_label(),
|
src.ast.short_label(),
|
||||||
);
|
);
|
||||||
|
@ -141,23 +141,22 @@ impl NavigationTarget {
|
||||||
/// Allows `NavigationTarget` to be created from a `NameOwner`
|
/// Allows `NavigationTarget` to be created from a `NameOwner`
|
||||||
pub(crate) fn from_named(
|
pub(crate) fn from_named(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
file_id: hir::HirFileId,
|
node: Source<&dyn ast::NameOwner>,
|
||||||
node: &impl ast::NameOwner,
|
|
||||||
docs: Option<String>,
|
docs: Option<String>,
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
) -> NavigationTarget {
|
) -> NavigationTarget {
|
||||||
//FIXME: use `_` instead of empty string
|
//FIXME: use `_` instead of empty string
|
||||||
let name = node.name().map(|it| it.text().clone()).unwrap_or_default();
|
let name = node.ast.name().map(|it| it.text().clone()).unwrap_or_default();
|
||||||
let focus_range =
|
let focus_range =
|
||||||
node.name().map(|it| original_range(db, Source::new(file_id, it.syntax())).range);
|
node.ast.name().map(|it| original_range(db, node.with_ast(it.syntax())).range);
|
||||||
let frange = original_range(db, Source::new(file_id, node.syntax()));
|
let frange = original_range(db, node.map(|it| it.syntax()));
|
||||||
|
|
||||||
NavigationTarget::from_syntax(
|
NavigationTarget::from_syntax(
|
||||||
frange.file_id,
|
frange.file_id,
|
||||||
name,
|
name,
|
||||||
focus_range,
|
focus_range,
|
||||||
frange.range,
|
frange.range,
|
||||||
node.syntax(),
|
node.ast.syntax().kind(),
|
||||||
docs,
|
docs,
|
||||||
description,
|
description,
|
||||||
)
|
)
|
||||||
|
@ -168,14 +167,14 @@ impl NavigationTarget {
|
||||||
name: SmolStr,
|
name: SmolStr,
|
||||||
focus_range: Option<TextRange>,
|
focus_range: Option<TextRange>,
|
||||||
full_range: TextRange,
|
full_range: TextRange,
|
||||||
node: &SyntaxNode,
|
kind: SyntaxKind,
|
||||||
docs: Option<String>,
|
docs: Option<String>,
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
) -> NavigationTarget {
|
) -> NavigationTarget {
|
||||||
NavigationTarget {
|
NavigationTarget {
|
||||||
file_id,
|
file_id,
|
||||||
name,
|
name,
|
||||||
kind: node.kind(),
|
kind,
|
||||||
full_range,
|
full_range,
|
||||||
focus_range,
|
focus_range,
|
||||||
container_name: None,
|
container_name: None,
|
||||||
|
@ -220,8 +219,7 @@ where
|
||||||
let src = self.source(db);
|
let src = self.source(db);
|
||||||
NavigationTarget::from_named(
|
NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
src.file_id,
|
src.as_ref().map(|it| it as &dyn ast::NameOwner),
|
||||||
&src.ast,
|
|
||||||
src.ast.doc_comment_text(),
|
src.ast.doc_comment_text(),
|
||||||
src.ast.short_label(),
|
src.ast.short_label(),
|
||||||
)
|
)
|
||||||
|
@ -241,7 +239,7 @@ impl ToNav for hir::Module {
|
||||||
name,
|
name,
|
||||||
None,
|
None,
|
||||||
frange.range,
|
frange.range,
|
||||||
node.syntax(),
|
node.syntax().kind(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
@ -254,7 +252,7 @@ impl ToNav for hir::Module {
|
||||||
name,
|
name,
|
||||||
None,
|
None,
|
||||||
frange.range,
|
frange.range,
|
||||||
node.syntax(),
|
node.syntax().kind(),
|
||||||
node.doc_comment_text(),
|
node.doc_comment_text(),
|
||||||
node.short_label(),
|
node.short_label(),
|
||||||
)
|
)
|
||||||
|
@ -273,7 +271,7 @@ impl ToNav for hir::ImplBlock {
|
||||||
"impl".into(),
|
"impl".into(),
|
||||||
None,
|
None,
|
||||||
frange.range,
|
frange.range,
|
||||||
src.ast.syntax(),
|
src.ast.syntax().kind(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
@ -287,8 +285,7 @@ impl ToNav for hir::StructField {
|
||||||
match &src.ast {
|
match &src.ast {
|
||||||
FieldSource::Named(it) => NavigationTarget::from_named(
|
FieldSource::Named(it) => NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
src.file_id,
|
src.with_ast(it),
|
||||||
it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
it.short_label(),
|
it.short_label(),
|
||||||
),
|
),
|
||||||
|
@ -299,7 +296,7 @@ impl ToNav for hir::StructField {
|
||||||
"".into(),
|
"".into(),
|
||||||
None,
|
None,
|
||||||
frange.range,
|
frange.range,
|
||||||
it.syntax(),
|
it.syntax().kind(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
@ -312,7 +309,12 @@ impl ToNav for hir::MacroDef {
|
||||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
||||||
let src = self.source(db);
|
let src = self.source(db);
|
||||||
log::debug!("nav target {:#?}", src.ast.syntax());
|
log::debug!("nav target {:#?}", src.ast.syntax());
|
||||||
NavigationTarget::from_named(db, src.file_id, &src.ast, src.ast.doc_comment_text(), None)
|
NavigationTarget::from_named(
|
||||||
|
db,
|
||||||
|
src.as_ref().map(|it| it as &dyn ast::NameOwner),
|
||||||
|
src.ast.doc_comment_text(),
|
||||||
|
None,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,8 +120,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||||
ast::StructDef(it) => {
|
ast::StructDef(it) => {
|
||||||
Some(NavigationTarget::from_named(
|
Some(NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
node.file_id,
|
node.with_ast(&it),
|
||||||
&it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
it.short_label(),
|
it.short_label(),
|
||||||
))
|
))
|
||||||
|
@ -129,8 +128,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||||
ast::EnumDef(it) => {
|
ast::EnumDef(it) => {
|
||||||
Some(NavigationTarget::from_named(
|
Some(NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
node.file_id,
|
node.with_ast(&it),
|
||||||
&it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
it.short_label(),
|
it.short_label(),
|
||||||
))
|
))
|
||||||
|
@ -138,8 +136,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||||
ast::EnumVariant(it) => {
|
ast::EnumVariant(it) => {
|
||||||
Some(NavigationTarget::from_named(
|
Some(NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
node.file_id,
|
node.with_ast(&it),
|
||||||
&it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
it.short_label(),
|
it.short_label(),
|
||||||
))
|
))
|
||||||
|
@ -147,8 +144,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||||
ast::FnDef(it) => {
|
ast::FnDef(it) => {
|
||||||
Some(NavigationTarget::from_named(
|
Some(NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
node.file_id,
|
node.with_ast(&it),
|
||||||
&it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
it.short_label(),
|
it.short_label(),
|
||||||
))
|
))
|
||||||
|
@ -156,8 +152,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||||
ast::TypeAliasDef(it) => {
|
ast::TypeAliasDef(it) => {
|
||||||
Some(NavigationTarget::from_named(
|
Some(NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
node.file_id,
|
node.with_ast(&it),
|
||||||
&it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
it.short_label(),
|
it.short_label(),
|
||||||
))
|
))
|
||||||
|
@ -165,8 +160,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||||
ast::ConstDef(it) => {
|
ast::ConstDef(it) => {
|
||||||
Some(NavigationTarget::from_named(
|
Some(NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
node.file_id,
|
node.with_ast(&it),
|
||||||
&it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
it.short_label(),
|
it.short_label(),
|
||||||
))
|
))
|
||||||
|
@ -174,8 +168,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||||
ast::StaticDef(it) => {
|
ast::StaticDef(it) => {
|
||||||
Some(NavigationTarget::from_named(
|
Some(NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
node.file_id,
|
node.with_ast(&it),
|
||||||
&it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
it.short_label(),
|
it.short_label(),
|
||||||
))
|
))
|
||||||
|
@ -183,8 +176,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||||
ast::TraitDef(it) => {
|
ast::TraitDef(it) => {
|
||||||
Some(NavigationTarget::from_named(
|
Some(NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
node.file_id,
|
node.with_ast(&it),
|
||||||
&it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
it.short_label(),
|
it.short_label(),
|
||||||
))
|
))
|
||||||
|
@ -192,8 +184,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||||
ast::RecordFieldDef(it) => {
|
ast::RecordFieldDef(it) => {
|
||||||
Some(NavigationTarget::from_named(
|
Some(NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
node.file_id,
|
node.with_ast(&it),
|
||||||
&it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
it.short_label(),
|
it.short_label(),
|
||||||
))
|
))
|
||||||
|
@ -201,8 +192,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||||
ast::Module(it) => {
|
ast::Module(it) => {
|
||||||
Some(NavigationTarget::from_named(
|
Some(NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
node.file_id,
|
node.with_ast(&it),
|
||||||
&it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
it.short_label(),
|
it.short_label(),
|
||||||
))
|
))
|
||||||
|
@ -210,8 +200,7 @@ fn named_target(db: &RootDatabase, node: Source<&SyntaxNode>) -> Option<Navigati
|
||||||
ast::MacroCall(it) => {
|
ast::MacroCall(it) => {
|
||||||
Some(NavigationTarget::from_named(
|
Some(NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
node.file_id,
|
node.with_ast(&it),
|
||||||
&it,
|
|
||||||
it.doc_comment_text(),
|
it.doc_comment_text(),
|
||||||
None,
|
None,
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in a new issue