diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/semantics.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/semantics/source_to_def.rs | 7 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_syntax/src/tests.rs | 47 |
5 files changed, 48 insertions, 18 deletions
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 97125b32a..155b666d7 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs | |||
@@ -485,6 +485,7 @@ impl<'db> SemanticsImpl<'db> { | |||
485 | ChildContainer::ModuleId(it) => it.resolver(self.db.upcast()), | 485 | ChildContainer::ModuleId(it) => it.resolver(self.db.upcast()), |
486 | ChildContainer::EnumId(it) => it.resolver(self.db.upcast()), | 486 | ChildContainer::EnumId(it) => it.resolver(self.db.upcast()), |
487 | ChildContainer::VariantId(it) => it.resolver(self.db.upcast()), | 487 | ChildContainer::VariantId(it) => it.resolver(self.db.upcast()), |
488 | ChildContainer::TypeAliasId(it) => it.resolver(self.db.upcast()), | ||
488 | ChildContainer::GenericDefId(it) => it.resolver(self.db.upcast()), | 489 | ChildContainer::GenericDefId(it) => it.resolver(self.db.upcast()), |
489 | }; | 490 | }; |
490 | SourceAnalyzer::new_for_resolver(resolver, src) | 491 | SourceAnalyzer::new_for_resolver(resolver, src) |
diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 8af64fdc1..0e1d92fb3 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs | |||
@@ -194,6 +194,10 @@ impl SourceToDefCtx<'_, '_> { | |||
194 | let def = self.const_to_def(container.with_value(it))?; | 194 | let def = self.const_to_def(container.with_value(it))?; |
195 | DefWithBodyId::from(def).into() | 195 | DefWithBodyId::from(def).into() |
196 | }, | 196 | }, |
197 | ast::TypeAliasDef(it) => { | ||
198 | let def = self.type_alias_to_def(container.with_value(it))?; | ||
199 | def.into() | ||
200 | }, | ||
197 | _ => continue, | 201 | _ => continue, |
198 | } | 202 | } |
199 | }; | 203 | }; |
@@ -246,6 +250,7 @@ pub(crate) enum ChildContainer { | |||
246 | ImplId(ImplId), | 250 | ImplId(ImplId), |
247 | EnumId(EnumId), | 251 | EnumId(EnumId), |
248 | VariantId(VariantId), | 252 | VariantId(VariantId), |
253 | TypeAliasId(TypeAliasId), | ||
249 | /// XXX: this might be the same def as, for example an `EnumId`. However, | 254 | /// XXX: this might be the same def as, for example an `EnumId`. However, |
250 | /// here the children generic parameters, and not, eg enum variants. | 255 | /// here the children generic parameters, and not, eg enum variants. |
251 | GenericDefId(GenericDefId), | 256 | GenericDefId(GenericDefId), |
@@ -258,6 +263,7 @@ impl_froms! { | |||
258 | ImplId, | 263 | ImplId, |
259 | EnumId, | 264 | EnumId, |
260 | VariantId, | 265 | VariantId, |
266 | TypeAliasId, | ||
261 | GenericDefId | 267 | GenericDefId |
262 | } | 268 | } |
263 | 269 | ||
@@ -271,6 +277,7 @@ impl ChildContainer { | |||
271 | ChildContainer::ImplId(it) => it.child_by_source(db), | 277 | ChildContainer::ImplId(it) => it.child_by_source(db), |
272 | ChildContainer::EnumId(it) => it.child_by_source(db), | 278 | ChildContainer::EnumId(it) => it.child_by_source(db), |
273 | ChildContainer::VariantId(it) => it.child_by_source(db), | 279 | ChildContainer::VariantId(it) => it.child_by_source(db), |
280 | ChildContainer::TypeAliasId(_) => DynMap::default(), | ||
274 | ChildContainer::GenericDefId(it) => it.child_by_source(db), | 281 | ChildContainer::GenericDefId(it) => it.child_by_source(db), |
275 | } | 282 | } |
276 | } | 283 | } |
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 8fc33d031..f575d738f 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -856,4 +856,14 @@ impl Foo { | |||
856 | "#, | 856 | "#, |
857 | ); | 857 | ); |
858 | } | 858 | } |
859 | |||
860 | #[test] | ||
861 | fn goto_def_for_type_alias_generic_parameter() { | ||
862 | check( | ||
863 | r#" | ||
864 | type Alias<T> = T<|>; | ||
865 | //^ | ||
866 | "#, | ||
867 | ) | ||
868 | } | ||
859 | } | 869 | } |
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index cb21b8053..57cc09854 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml | |||
@@ -33,3 +33,4 @@ serde = { version = "1.0.106", features = ["derive"] } | |||
33 | test_utils = { path = "../test_utils" } | 33 | test_utils = { path = "../test_utils" } |
34 | expect = { path = "../expect" } | 34 | expect = { path = "../expect" } |
35 | walkdir = "2.3.1" | 35 | walkdir = "2.3.1" |
36 | rayon = "1" | ||
diff --git a/crates/ra_syntax/src/tests.rs b/crates/ra_syntax/src/tests.rs index aa78735da..8447dcad7 100644 --- a/crates/ra_syntax/src/tests.rs +++ b/crates/ra_syntax/src/tests.rs | |||
@@ -1,10 +1,11 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | fmt::Write, | 2 | fmt::Write, |
3 | fs, | 3 | fs, |
4 | path::{Component, Path, PathBuf}, | 4 | path::{Path, PathBuf}, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use expect::expect_file; | 7 | use expect::expect_file; |
8 | use rayon::prelude::*; | ||
8 | use test_utils::project_dir; | 9 | use test_utils::project_dir; |
9 | 10 | ||
10 | use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextSize, Token}; | 11 | use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextSize, Token}; |
@@ -121,33 +122,43 @@ fn reparse_fuzz_tests() { | |||
121 | /// FIXME: Use this as a benchmark | 122 | /// FIXME: Use this as a benchmark |
122 | #[test] | 123 | #[test] |
123 | fn self_hosting_parsing() { | 124 | fn self_hosting_parsing() { |
124 | use std::ffi::OsStr; | ||
125 | let dir = project_dir().join("crates"); | 125 | let dir = project_dir().join("crates"); |
126 | let mut count = 0; | 126 | let files = walkdir::WalkDir::new(dir) |
127 | for entry in walkdir::WalkDir::new(dir) | ||
128 | .into_iter() | 127 | .into_iter() |
129 | .filter_entry(|entry| { | 128 | .filter_entry(|entry| { |
130 | !entry.path().components().any(|component| { | 129 | // Get all files which are not in the crates/ra_syntax/test_data folder |
131 | // Get all files which are not in the crates/ra_syntax/test_data folder | 130 | !entry.path().components().any(|component| component.as_os_str() == "test_data") |
132 | component == Component::Normal(OsStr::new("test_data")) | ||
133 | }) | ||
134 | }) | 131 | }) |
135 | .map(|e| e.unwrap()) | 132 | .map(|e| e.unwrap()) |
136 | .filter(|entry| { | 133 | .filter(|entry| { |
137 | // Get all `.rs ` files | 134 | // Get all `.rs ` files |
138 | !entry.path().is_dir() && (entry.path().extension() == Some(OsStr::new("rs"))) | 135 | !entry.path().is_dir() && (entry.path().extension().unwrap_or_default() == "rs") |
139 | }) | 136 | }) |
140 | { | 137 | .map(|entry| entry.into_path()) |
141 | count += 1; | 138 | .collect::<Vec<_>>(); |
142 | let text = read_text(entry.path()); | ||
143 | if let Err(errors) = SourceFile::parse(&text).ok() { | ||
144 | panic!("Parsing errors:\n{:?}\n{}\n", errors, entry.path().display()); | ||
145 | } | ||
146 | } | ||
147 | assert!( | 139 | assert!( |
148 | count > 30, | 140 | files.len() > 100, |
149 | "self_hosting_parsing found too few files - is it running in the right directory?" | 141 | "self_hosting_parsing found too few files - is it running in the right directory?" |
150 | ) | 142 | ); |
143 | |||
144 | let errors = files | ||
145 | .into_par_iter() | ||
146 | .filter_map(|file| { | ||
147 | let text = read_text(&file); | ||
148 | match SourceFile::parse(&text).ok() { | ||
149 | Ok(_) => None, | ||
150 | Err(err) => Some((file, err)), | ||
151 | } | ||
152 | }) | ||
153 | .collect::<Vec<_>>(); | ||
154 | |||
155 | if !errors.is_empty() { | ||
156 | let errors = errors | ||
157 | .into_iter() | ||
158 | .map(|(path, err)| format!("{}: {:?}\n", path.display(), err)) | ||
159 | .collect::<String>(); | ||
160 | panic!("Parsing errors:\n{}\n", errors); | ||
161 | } | ||
151 | } | 162 | } |
152 | 163 | ||
153 | fn test_data_dir() -> PathBuf { | 164 | fn test_data_dir() -> PathBuf { |