aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/source_analyzer.rs30
-rw-r--r--crates/ra_ide/src/diagnostics.rs3
-rw-r--r--crates/ra_ide/src/goto_definition.rs80
-rw-r--r--editors/code/src/net.ts13
4 files changed, 120 insertions, 6 deletions
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index 757d1e397..1d6c47103 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -216,13 +216,43 @@ impl SourceAnalyzer {
216 if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_expr(expr_id) { 216 if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_expr(expr_id) {
217 return Some(PathResolution::AssocItem(assoc.into())); 217 return Some(PathResolution::AssocItem(assoc.into()));
218 } 218 }
219 if let Some(VariantId::EnumVariantId(variant)) =
220 self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
221 {
222 return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into())));
223 }
219 } 224 }
225
220 if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) { 226 if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) {
221 let pat_id = self.pat_id(&path_pat.into())?; 227 let pat_id = self.pat_id(&path_pat.into())?;
222 if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) { 228 if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
223 return Some(PathResolution::AssocItem(assoc.into())); 229 return Some(PathResolution::AssocItem(assoc.into()));
224 } 230 }
231 if let Some(VariantId::EnumVariantId(variant)) =
232 self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
233 {
234 return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into())));
235 }
236 }
237
238 if let Some(rec_lit) = path.syntax().parent().and_then(ast::RecordLit::cast) {
239 let expr_id = self.expr_id(db, &rec_lit.into())?;
240 if let Some(VariantId::EnumVariantId(variant)) =
241 self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
242 {
243 return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into())));
244 }
225 } 245 }
246
247 if let Some(rec_pat) = path.syntax().parent().and_then(ast::RecordPat::cast) {
248 let pat_id = self.pat_id(&rec_pat.into())?;
249 if let Some(VariantId::EnumVariantId(variant)) =
250 self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
251 {
252 return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into())));
253 }
254 }
255
226 // This must be a normal source file rather than macro file. 256 // This must be a normal source file rather than macro file.
227 let hir_path = 257 let hir_path =
228 crate::Path::from_src(path.clone(), &Hygiene::new(db.upcast(), self.file_id))?; 258 crate::Path::from_src(path.clone(), &Hygiene::new(db.upcast(), self.file_id))?;
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index a88a978d7..9bde1db8e 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -167,6 +167,9 @@ fn missing_struct_field_fix(
167 }; 167 };
168 168
169 let new_field_type = sema.type_of_expr(&record_expr.expr()?)?; 169 let new_field_type = sema.type_of_expr(&record_expr.expr()?)?;
170 if new_field_type.is_unknown() {
171 return None;
172 }
170 let new_field = make::record_field_def( 173 let new_field = make::record_field_def(
171 record_expr.field_name()?, 174 record_expr.field_name()?,
172 make::type_ref(&new_field_type.display_source_code(sema.db, module.into()).ok()?), 175 make::type_ref(&new_field_type.display_source_code(sema.db, module.into()).ok()?),
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index 0798d2c36..450ce0ba7 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -908,4 +908,84 @@ mod tests {
908 "x: i32|x", 908 "x: i32|x",
909 ); 909 );
910 } 910 }
911
912 #[test]
913 fn goto_def_for_enum_variant_self_pattern_const() {
914 check_goto(
915 "
916 //- /lib.rs
917 enum Foo {
918 Bar,
919 }
920 impl Foo {
921 fn baz(self) {
922 match self {
923 Self::Bar<|> => {}
924 }
925 }
926 }
927 ",
928 "Bar ENUM_VARIANT FileId(1) 15..18 15..18",
929 "Bar|Bar",
930 );
931 }
932
933 #[test]
934 fn goto_def_for_enum_variant_self_pattern_record() {
935 check_goto(
936 "
937 //- /lib.rs
938 enum Foo {
939 Bar { val: i32 },
940 }
941 impl Foo {
942 fn baz(self) -> i32 {
943 match self {
944 Self::Bar<|> { val } => {}
945 }
946 }
947 }
948 ",
949 "Bar ENUM_VARIANT FileId(1) 15..31 15..18",
950 "Bar { val: i32 }|Bar",
951 );
952 }
953
954 #[test]
955 fn goto_def_for_enum_variant_self_expr_const() {
956 check_goto(
957 "
958 //- /lib.rs
959 enum Foo {
960 Bar,
961 }
962 impl Foo {
963 fn baz(self) {
964 Self::Bar<|>;
965 }
966 }
967 ",
968 "Bar ENUM_VARIANT FileId(1) 15..18 15..18",
969 "Bar|Bar",
970 );
971 }
972
973 #[test]
974 fn goto_def_for_enum_variant_self_expr_record() {
975 check_goto(
976 "
977 //- /lib.rs
978 enum Foo {
979 Bar { val: i32 },
980 }
981 impl Foo {
982 fn baz(self) {
983 Self::Bar<|> {val: 4};
984 }
985 }
986 ",
987 "Bar ENUM_VARIANT FileId(1) 15..31 15..18",
988 "Bar { val: i32 }|Bar",
989 );
990 }
911} 991}
diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts
index 0e7dd29c2..9debdc57b 100644
--- a/editors/code/src/net.ts
+++ b/editors/code/src/net.ts
@@ -114,15 +114,16 @@ async function downloadFile(
114 114
115 log.debug("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); 115 log.debug("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath);
116 116
117 let readBytes = 0;
118 res.body.on("data", (chunk: Buffer) => {
119 readBytes += chunk.length;
120 onProgress(readBytes, totalBytes);
121 });
122
123 // Put the artifact into a temporary folder to prevent partially downloaded files when user kills vscode 117 // Put the artifact into a temporary folder to prevent partially downloaded files when user kills vscode
124 await withTempFile(async tempFilePath => { 118 await withTempFile(async tempFilePath => {
125 const destFileStream = fs.createWriteStream(tempFilePath, { mode }); 119 const destFileStream = fs.createWriteStream(tempFilePath, { mode });
120
121 let readBytes = 0;
122 res.body.on("data", (chunk: Buffer) => {
123 readBytes += chunk.length;
124 onProgress(readBytes, totalBytes);
125 });
126
126 await pipeline(res.body, destFileStream); 127 await pipeline(res.body, destFileStream);
127 await new Promise<void>(resolve => { 128 await new Promise<void>(resolve => {
128 destFileStream.on("close", resolve); 129 destFileStream.on("close", resolve);