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
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--editors/code/package.json4
-rw-r--r--editors/code/src/net.ts12
-rw-r--r--xtask/src/dist.rs4
7 files changed, 74 insertions, 64 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#"
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 3b20d741a..5588c15da 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -1062,8 +1062,8 @@ mod tests {
1062 let package_json_path = project_root().join("editors/code/package.json"); 1062 let package_json_path = project_root().join("editors/code/package.json");
1063 let mut package_json = fs::read_to_string(&package_json_path).unwrap(); 1063 let mut package_json = fs::read_to_string(&package_json_path).unwrap();
1064 1064
1065 let start_marker = " \"$generated-start\": false,\n"; 1065 let start_marker = " \"$generated-start\": {},\n";
1066 let end_marker = " \"$generated-end\": false\n"; 1066 let end_marker = " \"$generated-end\": {}\n";
1067 1067
1068 let start = package_json.find(start_marker).unwrap() + start_marker.len(); 1068 let start = package_json.find(start_marker).unwrap() + start_marker.len();
1069 let end = package_json.find(end_marker).unwrap(); 1069 let end = package_json.find(end_marker).unwrap();
diff --git a/editors/code/package.json b/editors/code/package.json
index 0f3ed48a0..a88a5c44e 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -389,7 +389,7 @@
389 "default": {}, 389 "default": {},
390 "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`" 390 "markdownDescription": "Optional settings passed to the debug engine. Example: `{ \"lldb\": { \"terminal\":\"external\"} }`"
391 }, 391 },
392 "$generated-start": false, 392 "$generated-start": {},
393 "rust-analyzer.assist.importGranularity": { 393 "rust-analyzer.assist.importGranularity": {
394 "markdownDescription": "How imports should be grouped into use statements.", 394 "markdownDescription": "How imports should be grouped into use statements.",
395 "default": "crate", 395 "default": "crate",
@@ -841,7 +841,7 @@
841 "Search for all symbols kinds" 841 "Search for all symbols kinds"
842 ] 842 ]
843 }, 843 },
844 "$generated-end": false 844 "$generated-end": {}
845 } 845 }
846 }, 846 },
847 "problemPatterns": [ 847 "problemPatterns": [
diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts
index 747c02db9..5c48c74e8 100644
--- a/editors/code/src/net.ts
+++ b/editors/code/src/net.ts
@@ -127,17 +127,19 @@ async function downloadFile(
127 httpProxy: string | null | undefined, 127 httpProxy: string | null | undefined,
128 onProgress: (readBytes: number, totalBytes: number) => void 128 onProgress: (readBytes: number, totalBytes: number) => void
129): Promise<void> { 129): Promise<void> {
130 const urlString = url.toString();
131
130 const res = await (() => { 132 const res = await (() => {
131 if (httpProxy) { 133 if (httpProxy) {
132 log.debug(`Downloading ${url.path} via proxy: ${httpProxy}`); 134 log.debug(`Downloading ${urlString} via proxy: ${httpProxy}`);
133 return fetch(url.path, { agent: new HttpsProxyAgent(httpProxy) }); 135 return fetch(urlString, { agent: new HttpsProxyAgent(httpProxy) });
134 } 136 }
135 137
136 return fetch(url.path); 138 return fetch(urlString);
137 })(); 139 })();
138 140
139 if (!res.ok) { 141 if (!res.ok) {
140 log.error("Error", res.status, "while downloading file from", url.path); 142 log.error("Error", res.status, "while downloading file from", urlString);
141 log.error({ body: await res.text(), headers: res.headers }); 143 log.error({ body: await res.text(), headers: res.headers });
142 144
143 throw new Error(`Got response ${res.status} when trying to download a file.`); 145 throw new Error(`Got response ${res.status} when trying to download a file.`);
@@ -146,7 +148,7 @@ async function downloadFile(
146 const totalBytes = Number(res.headers.get('content-length')); 148 const totalBytes = Number(res.headers.get('content-length'));
147 assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); 149 assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol");
148 150
149 log.debug("Downloading file of", totalBytes, "bytes size from", url.path, "to", destFilePath.path); 151 log.debug("Downloading file of", totalBytes, "bytes size from", urlString, "to", destFilePath.path);
150 152
151 let readBytes = 0; 153 let readBytes = 0;
152 res.body.on("data", (chunk: Buffer) => { 154 res.body.on("data", (chunk: Buffer) => {
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs
index 3a67294c5..c7363688a 100644
--- a/xtask/src/dist.rs
+++ b/xtask/src/dist.rs
@@ -45,8 +45,8 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> {
45 patch 45 patch
46 .replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version)) 46 .replace(r#""version": "0.4.0-dev""#, &format!(r#""version": "{}""#, version))
47 .replace(r#""releaseTag": null"#, &format!(r#""releaseTag": "{}""#, release_tag)) 47 .replace(r#""releaseTag": null"#, &format!(r#""releaseTag": "{}""#, release_tag))
48 .replace(r#""$generated-start": false,"#, "") 48 .replace(r#""$generated-start": {},"#, "")
49 .replace(",\n \"$generated-end\": false", ""); 49 .replace(",\n \"$generated-end\": {}", "");
50 50
51 if nightly { 51 if nightly {
52 patch.replace( 52 patch.replace(