return None;
}
- let node = token.ancestors().find(|n| {
- ast::Expr::can_cast(n.kind())
- || ast::Pat::can_cast(n.kind())
- || ast::SelfParam::can_cast(n.kind())
- })?;
+ let node = token
+ .ancestors()
+ .find(|n| ast::Expr::can_cast(n.kind()) || ast::Pat::can_cast(n.kind()))?;
let ty = match_ast! {
match node {
ast::Expr(it) => sema.type_of_expr(&it)?,
ast::Pat(it) => sema.type_of_pat(&it)?,
- ast::SelfParam(self_param) => sema.type_of_self(&self_param)?,
// If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
// (e.g expanding a builtin macro). So we give up here.
ast::MacroCall(_it) => return None,
Definition::SelfType(it) => it.target_ty(db).as_adt(),
_ => None,
}?;
- match adt {
- Adt::Struct(it) => it.try_to_nav(db),
- Adt::Union(it) => it.try_to_nav(db),
- Adt::Enum(it) => it.try_to_nav(db),
- }
- .map(to_action)
+ adt.try_to_nav(db).map(to_action)
}
fn runnable_action(
return tokens.max_by_key(priority);
fn priority(n: &SyntaxToken) -> usize {
match n.kind() {
- IDENT | INT_NUMBER | LIFETIME_IDENT => 3,
+ IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] => 3,
T!['('] | T![')'] => 2,
kind if kind.is_trivia() => 0,
_ => 1,
/// Test cases:
/// case 1. bare URL: https://www.example.com/
/// case 2. inline URL with title: [example](https://www.example.com/)
-/// case 3. code refrence: [`Result`]
-/// case 4. code refrence but miss footnote: [`String`]
+/// case 3. code reference: [`Result`]
+/// case 4. code reference but miss footnote: [`String`]
/// case 5. autolink: <http://www.example.com/>
/// case 6. email address: <test@example.com>
-/// case 7. refrence: [example][example]
+/// case 7. reference: [example][example]
/// case 8. collapsed link: [example][]
/// case 9. shortcut link: [example]
/// case 10. inline without URL: [example]()
-/// case 11. refrence: [foo][foo]
-/// case 12. refrence: [foo][bar]
+/// case 11. reference: [foo][foo]
+/// case 12. reference: [foo][bar]
/// case 13. collapsed link: [foo][]
/// case 14. shortcut link: [foo]
/// case 15. inline without URL: [foo]()
Test cases:
case 1. bare URL: https://www.example.com/
case 2. inline URL with title: [example](https://www.example.com/)
- case 3. code refrence: `Result`
- case 4. code refrence but miss footnote: `String`
+ case 3. code reference: `Result`
+ case 4. code reference but miss footnote: `String`
case 5. autolink: http://www.example.com/
case 6. email address: test@example.com
- case 7. refrence: example
+ case 7. reference: example
case 8. collapsed link: example
case 9. shortcut link: example
case 10. inline without URL: example
- case 11. refrence: foo
- case 12. refrence: foo
+ case 11. reference: foo
+ case 12. reference: foo
case 13. collapsed link: foo
case 14. shortcut link: foo
case 15. inline without URL: foo
);
}
+ #[test]
+ fn test_hover_self_has_go_to_type() {
+ check_actions(
+ r#"
+struct Foo;
+impl Foo {
+ fn foo(&self$0) {}
+}
+"#,
+ expect![[r#"
+ [
+ GoToType(
+ [
+ HoverGotoTypeData {
+ mod_path: "test::Foo",
+ nav: NavigationTarget {
+ file_id: FileId(
+ 0,
+ ),
+ full_range: 0..11,
+ focus_range: 7..10,
+ name: "Foo",
+ kind: Struct,
+ description: "struct Foo",
+ },
+ },
+ ],
+ ),
+ ]
+ "#]],
+ );
+ }
+
#[test]
fn hover_displays_normalized_crate_names() {
check(
}
"#,
expect![[r#"
- *&self*
+ *self*
+
```rust
&Foo
```
}
"#,
expect![[r#"
- *self: Arc<Foo>*
+ *self*
+
```rust
Arc<Foo>
```