aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock50
-rw-r--r--crates/hir_ty/Cargo.toml2
-rw-r--r--crates/ide/src/goto_type_definition.rs62
3 files changed, 61 insertions, 53 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 847277118..5066d5f0f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -216,20 +216,6 @@ dependencies = [
216 "petgraph", 216 "petgraph",
217 "rustc-hash", 217 "rustc-hash",
218 "tracing", 218 "tracing",
219 "tracing-subscriber",
220 "tracing-tree",
221]
222
223[[package]]
224name = "chrono"
225version = "0.4.19"
226source = "registry+https://github.com/rust-lang/crates.io-index"
227checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
228dependencies = [
229 "libc",
230 "num-integer",
231 "num-traits",
232 "winapi",
233] 219]
234 220
235[[package]] 221[[package]]
@@ -975,25 +961,6 @@ dependencies = [
975] 961]
976 962
977[[package]] 963[[package]]
978name = "num-integer"
979version = "0.1.44"
980source = "registry+https://github.com/rust-lang/crates.io-index"
981checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
982dependencies = [
983 "autocfg",
984 "num-traits",
985]
986
987[[package]]
988name = "num-traits"
989version = "0.2.14"
990source = "registry+https://github.com/rust-lang/crates.io-index"
991checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
992dependencies = [
993 "autocfg",
994]
995
996[[package]]
997name = "num_cpus" 964name = "num_cpus"
998version = "1.13.0" 965version = "1.13.0"
999source = "registry+https://github.com/rust-lang/crates.io-index" 966source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1762,35 +1729,18 @@ dependencies = [
1762] 1729]
1763 1730
1764[[package]] 1731[[package]]
1765name = "tracing-serde"
1766version = "0.1.2"
1767source = "registry+https://github.com/rust-lang/crates.io-index"
1768checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
1769dependencies = [
1770 "serde",
1771 "tracing-core",
1772]
1773
1774[[package]]
1775name = "tracing-subscriber" 1732name = "tracing-subscriber"
1776version = "0.2.18" 1733version = "0.2.18"
1777source = "registry+https://github.com/rust-lang/crates.io-index" 1734source = "registry+https://github.com/rust-lang/crates.io-index"
1778checksum = "aa5553bf0883ba7c9cbe493b085c29926bd41b66afc31ff72cf17ff4fb60dcd5" 1735checksum = "aa5553bf0883ba7c9cbe493b085c29926bd41b66afc31ff72cf17ff4fb60dcd5"
1779dependencies = [ 1736dependencies = [
1780 "ansi_term",
1781 "chrono",
1782 "lazy_static", 1737 "lazy_static",
1783 "matchers", 1738 "matchers",
1784 "regex", 1739 "regex",
1785 "serde",
1786 "serde_json",
1787 "sharded-slab", 1740 "sharded-slab",
1788 "smallvec",
1789 "thread_local", 1741 "thread_local",
1790 "tracing", 1742 "tracing",
1791 "tracing-core", 1743 "tracing-core",
1792 "tracing-log",
1793 "tracing-serde",
1794] 1744]
1795 1745
1796[[package]] 1746[[package]]
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml
index a1894e8d8..74129eb21 100644
--- a/crates/hir_ty/Cargo.toml
+++ b/crates/hir_ty/Cargo.toml
@@ -20,7 +20,7 @@ rustc-hash = "1.1.0"
20scoped-tls = "1" 20scoped-tls = "1"
21chalk-solve = { version = "0.68", default-features = false } 21chalk-solve = { version = "0.68", default-features = false }
22chalk-ir = "0.68" 22chalk-ir = "0.68"
23chalk-recursive = "0.68" 23chalk-recursive = { version = "0.68", default-features = false }
24la-arena = { version = "0.2.0", path = "../../lib/arena" } 24la-arena = { version = "0.2.0", path = "../../lib/arena" }
25once_cell = { version = "1.5.0" } 25once_cell = { version = "1.5.0" }
26 26
diff --git a/crates/ide/src/goto_type_definition.rs b/crates/ide/src/goto_type_definition.rs
index 004d9cb68..ca3c02bf6 100644
--- a/crates/ide/src/goto_type_definition.rs
+++ b/crates/ide/src/goto_type_definition.rs
@@ -25,7 +25,7 @@ pub(crate) fn goto_type_definition(
25 let token: SyntaxToken = pick_best(file.syntax().token_at_offset(position.offset))?; 25 let token: SyntaxToken = pick_best(file.syntax().token_at_offset(position.offset))?;
26 let token: SyntaxToken = sema.descend_into_macros(token); 26 let token: SyntaxToken = sema.descend_into_macros(token);
27 27
28 let (ty, node) = sema.token_ancestors_with_macros(token).find_map(|node| { 28 let (ty, node) = sema.token_ancestors_with_macros(token.clone()).find_map(|node| {
29 let ty = match_ast! { 29 let ty = match_ast! {
30 match node { 30 match node {
31 ast::Expr(it) => sema.type_of_expr(&it)?, 31 ast::Expr(it) => sema.type_of_expr(&it)?,
@@ -33,13 +33,23 @@ pub(crate) fn goto_type_definition(
33 ast::SelfParam(it) => sema.type_of_self(&it)?, 33 ast::SelfParam(it) => sema.type_of_self(&it)?,
34 ast::Type(it) => sema.resolve_type(&it)?, 34 ast::Type(it) => sema.resolve_type(&it)?,
35 ast::RecordField(it) => sema.to_def(&it).map(|d| d.ty(db.upcast()))?, 35 ast::RecordField(it) => sema.to_def(&it).map(|d| d.ty(db.upcast()))?,
36 ast::RecordField(it) => sema.to_def(&it).map(|d| d.ty(db.upcast()))?,
37 // can't match on RecordExprField directly as `ast::Expr` will match an iteration too early otherwise
38 ast::NameRef(it) => {
39 if let Some(record_field) = ast::RecordExprField::for_name_ref(&it) {
40 let (_, _, ty) = sema.resolve_record_field(&record_field)?;
41 ty
42 } else {
43 let record_field = ast::RecordPatField::for_field_name_ref(&it)?;
44 sema.resolve_record_pat_field(&record_field)?.ty(db)
45 }
46 },
36 _ => return None, 47 _ => return None,
37 } 48 }
38 }; 49 };
39 50
40 Some((ty, node)) 51 Some((ty, node))
41 })?; 52 })?;
42
43 let adt_def = ty.autoderef(db).filter_map(|ty| ty.as_adt()).last()?; 53 let adt_def = ty.autoderef(db).filter_map(|ty| ty.as_adt()).last()?;
44 54
45 let nav = adt_def.try_to_nav(db)?; 55 let nav = adt_def.try_to_nav(db)?;
@@ -88,6 +98,54 @@ fn foo() {
88 } 98 }
89 99
90 #[test] 100 #[test]
101 fn goto_type_definition_record_expr_field() {
102 check(
103 r#"
104struct Bar;
105 // ^^^
106struct Foo { foo: Bar }
107fn foo() {
108 Foo { foo$0 }
109}
110"#,
111 );
112 check(
113 r#"
114struct Bar;
115 // ^^^
116struct Foo { foo: Bar }
117fn foo() {
118 Foo { foo$0: Bar }
119}
120"#,
121 );
122 }
123
124 #[test]
125 fn goto_type_definition_record_pat_field() {
126 check(
127 r#"
128struct Bar;
129 // ^^^
130struct Foo { foo: Bar }
131fn foo() {
132 let Foo { foo$0 };
133}
134"#,
135 );
136 check(
137 r#"
138struct Bar;
139 // ^^^
140struct Foo { foo: Bar }
141fn foo() {
142 let Foo { foo$0: bar };
143}
144"#,
145 );
146 }
147
148 #[test]
91 fn goto_type_definition_works_simple_ref() { 149 fn goto_type_definition_works_simple_ref() {
92 check( 150 check(
93 r#" 151 r#"