mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Simplify
This commit is contained in:
parent
b641a66078
commit
0c0142f61a
4 changed files with 16 additions and 22 deletions
|
@ -92,7 +92,7 @@ impl 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();
|
||||
if let Some(src) = module.declaration_source(db) {
|
||||
let node = src.as_ref().map(|it| it.syntax());
|
||||
let node = src.syntax();
|
||||
let full_range = node.original_file_range(db);
|
||||
let focus_range = src
|
||||
.value
|
||||
|
@ -298,7 +298,7 @@ impl TryToNav for hir::Impl {
|
|||
let frange = if let Some(item) = &derive_attr {
|
||||
item.syntax().original_file_range(db)
|
||||
} else {
|
||||
src.as_ref().map(|it| it.syntax()).original_file_range(db)
|
||||
src.syntax().original_file_range(db)
|
||||
};
|
||||
let focus_range = if derive_attr.is_some() {
|
||||
None
|
||||
|
|
|
@ -117,8 +117,6 @@ pub(crate) fn hover(
|
|||
let node = token.parent()?;
|
||||
let definition = match_ast! {
|
||||
match node {
|
||||
// We don't use NameClass::referenced_or_defined here as we do not want to resolve
|
||||
// field pattern shorthands to their definition.
|
||||
ast::Name(name) => NameClass::classify(&sema, &name).map(|class| match class {
|
||||
NameClass::Definition(it) | NameClass::ConstReference(it) => it,
|
||||
NameClass::PatFieldShorthand { local_def, field_ref: _ } => Definition::Local(local_def),
|
||||
|
@ -139,6 +137,7 @@ pub(crate) fn hover(
|
|||
NameClass::defined,
|
||||
),
|
||||
_ => {
|
||||
// intra-doc links
|
||||
if ast::Comment::cast(token.clone()).is_some() {
|
||||
cov_mark::hit!(no_highlight_on_comment_hover);
|
||||
let (attributes, def) = doc_attributes(&sema, &node)?;
|
||||
|
@ -153,9 +152,12 @@ pub(crate) fn hover(
|
|||
Either::Left(it) => Definition::ModuleDef(it),
|
||||
Either::Right(it) => Definition::Macro(it),
|
||||
})
|
||||
// attributes, require special machinery as they are mere ident tokens
|
||||
} else if let Some(attr) = token.ancestors().find_map(ast::Attr::cast) {
|
||||
// lints
|
||||
if let res@Some(_) = try_hover_for_lint(&attr, &token) {
|
||||
return res;
|
||||
// derives
|
||||
} else {
|
||||
range_override = Some(token.text_range());
|
||||
try_resolve_derive_input_at(&sema, &attr, &token).map(Definition::Macro)
|
||||
|
@ -276,7 +278,7 @@ fn hover_type_info(
|
|||
"```text\nType: {:>apad$}\nCoerced to: {:>opad$}\n```\n",
|
||||
uncoerced = original,
|
||||
coerced = adjusted,
|
||||
// 6 base padding for static text prefix of each line
|
||||
// 6 base padding for difference of length of the two text prefixes
|
||||
apad = 6 + adjusted.len().max(original.len()),
|
||||
opad = original.len(),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue