diff options
38 files changed, 286 insertions, 216 deletions
diff --git a/Cargo.lock b/Cargo.lock index c29ce324e..55afcda7b 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -761,7 +761,7 @@ dependencies = [ | |||
761 | "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", | 761 | "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", |
762 | "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", | 762 | "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", |
763 | "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", | 763 | "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", |
764 | "smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", | 764 | "smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
765 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", | 765 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", |
766 | ] | 766 | ] |
767 | 767 | ||
@@ -948,6 +948,7 @@ dependencies = [ | |||
948 | "ra_hir_def 0.1.0", | 948 | "ra_hir_def 0.1.0", |
949 | "ra_hir_expand 0.1.0", | 949 | "ra_hir_expand 0.1.0", |
950 | "ra_hir_ty 0.1.0", | 950 | "ra_hir_ty 0.1.0", |
951 | "ra_prof 0.1.0", | ||
951 | "ra_syntax 0.1.0", | 952 | "ra_syntax 0.1.0", |
952 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 953 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
953 | ] | 954 | ] |
@@ -1076,7 +1077,7 @@ dependencies = [ | |||
1076 | "ra_syntax 0.1.0", | 1077 | "ra_syntax 0.1.0", |
1077 | "ra_tt 0.1.0", | 1078 | "ra_tt 0.1.0", |
1078 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1079 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1079 | "smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1080 | "smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1080 | "test_utils 0.1.0", | 1081 | "test_utils 0.1.0", |
1081 | ] | 1082 | ] |
1082 | 1083 | ||
@@ -1121,7 +1122,7 @@ dependencies = [ | |||
1121 | "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1122 | "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1122 | "ra_parser 0.1.0", | 1123 | "ra_parser 0.1.0", |
1123 | "ra_text_edit 0.1.0", | 1124 | "ra_text_edit 0.1.0", |
1124 | "rowan 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1125 | "rowan 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", |
1125 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1126 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1126 | "rustc_lexer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1127 | "rustc_lexer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1127 | "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", | 1128 | "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1387,7 +1388,7 @@ dependencies = [ | |||
1387 | 1388 | ||
1388 | [[package]] | 1389 | [[package]] |
1389 | name = "rowan" | 1390 | name = "rowan" |
1390 | version = "0.8.1" | 1391 | version = "0.8.2" |
1391 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1392 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1392 | dependencies = [ | 1393 | dependencies = [ |
1393 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1394 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1442,7 +1443,7 @@ dependencies = [ | |||
1442 | "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", | 1443 | "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", |
1443 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1444 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1444 | "salsa-macros 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1445 | "salsa-macros 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1445 | "smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1446 | "smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1446 | ] | 1447 | ] |
1447 | 1448 | ||
1448 | [[package]] | 1449 | [[package]] |
@@ -1539,7 +1540,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1539 | 1540 | ||
1540 | [[package]] | 1541 | [[package]] |
1541 | name = "smallvec" | 1542 | name = "smallvec" |
1542 | version = "1.0.0" | 1543 | version = "1.1.0" |
1543 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1544 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1544 | 1545 | ||
1545 | [[package]] | 1546 | [[package]] |
@@ -1642,7 +1643,7 @@ name = "unicode-normalization" | |||
1642 | version = "0.1.11" | 1643 | version = "0.1.11" |
1643 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1644 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1644 | dependencies = [ | 1645 | dependencies = [ |
1645 | "smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1646 | "smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1646 | ] | 1647 | ] |
1647 | 1648 | ||
1648 | [[package]] | 1649 | [[package]] |
@@ -1892,7 +1893,7 @@ dependencies = [ | |||
1892 | "checksum relative-path 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bedde000f40f2921ce439ea165c9c53fd629bfa115140c72e22aceacb4a21954" | 1893 | "checksum relative-path 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bedde000f40f2921ce439ea165c9c53fd629bfa115140c72e22aceacb4a21954" |
1893 | "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" | 1894 | "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" |
1894 | "checksum ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ece421e0c4129b90e4a35b6f625e472e96c552136f5093a2f4fa2bbb75a62d5" | 1895 | "checksum ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ece421e0c4129b90e4a35b6f625e472e96c552136f5093a2f4fa2bbb75a62d5" |
1895 | "checksum rowan 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "769d42f547015b761f70c3086ccb3f7bff355124d52e9bf96d17de41774ede4b" | 1896 | "checksum rowan 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3eb10a10a48f0f809a217bcf074b85a03dcf79831bae80e7f1a043d0897463e2" |
1896 | "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" | 1897 | "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" |
1897 | "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" | 1898 | "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" |
1898 | "checksum rustc_lexer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c86aae0c77166108c01305ee1a36a1e77289d7dc6ca0a3cd91ff4992de2d16a5" | 1899 | "checksum rustc_lexer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c86aae0c77166108c01305ee1a36a1e77289d7dc6ca0a3cd91ff4992de2d16a5" |
@@ -1910,7 +1911,7 @@ dependencies = [ | |||
1910 | "checksum serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573" | 1911 | "checksum serde_repr 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cd02c7587ec314570041b2754829f84d873ced14a96d1fd1823531e11db40573" |
1911 | "checksum serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)" = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35" | 1912 | "checksum serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)" = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35" |
1912 | "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" | 1913 | "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" |
1913 | "checksum smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecf3b85f68e8abaa7555aa5abdb1153079387e60b718283d732f03897fcfc86" | 1914 | "checksum smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44e59e0c9fa00817912ae6e4e6e3c4fe04455e75699d06eedc7d85917ed8e8f4" |
1914 | "checksum smol_str 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "34836c9a295c62c2ce3514471117c5cb269891e8421b2aafdd910050576c4d8b" | 1915 | "checksum smol_str 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "34836c9a295c62c2ce3514471117c5cb269891e8421b2aafdd910050576c4d8b" |
1915 | "checksum superslice 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" | 1916 | "checksum superslice 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" |
1916 | "checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238" | 1917 | "checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238" |
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index 6ca9cc2e7..7dc31ad3c 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml | |||
@@ -14,6 +14,7 @@ either = "1.5" | |||
14 | 14 | ||
15 | ra_syntax = { path = "../ra_syntax" } | 15 | ra_syntax = { path = "../ra_syntax" } |
16 | ra_db = { path = "../ra_db" } | 16 | ra_db = { path = "../ra_db" } |
17 | ra_prof = { path = "../ra_prof" } | ||
17 | hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" } | 18 | hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" } |
18 | hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } | 19 | hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } |
19 | hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } | 20 | hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index fca3a2950..4cd28eb4e 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -12,8 +12,8 @@ use hir_def::{ | |||
12 | resolver::HasResolver, | 12 | resolver::HasResolver, |
13 | type_ref::{Mutability, TypeRef}, | 13 | type_ref::{Mutability, TypeRef}, |
14 | AdtId, ConstId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, LocalEnumVariantId, | 14 | AdtId, ConstId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, LocalEnumVariantId, |
15 | LocalImportId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, StructId, | 15 | LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId, |
16 | TraitId, TypeAliasId, TypeParamId, UnionId, | 16 | TypeParamId, UnionId, |
17 | }; | 17 | }; |
18 | use hir_expand::{ | 18 | use hir_expand::{ |
19 | diagnostics::DiagnosticSink, | 19 | diagnostics::DiagnosticSink, |
@@ -180,13 +180,11 @@ impl Module { | |||
180 | } | 180 | } |
181 | 181 | ||
182 | /// Returns a `ModuleScope`: a set of items, visible in this module. | 182 | /// Returns a `ModuleScope`: a set of items, visible in this module. |
183 | pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef, Option<Import>)> { | 183 | pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef)> { |
184 | db.crate_def_map(self.id.krate)[self.id.local_id] | 184 | db.crate_def_map(self.id.krate)[self.id.local_id] |
185 | .scope | 185 | .scope |
186 | .entries() | 186 | .entries() |
187 | .map(|(name, res)| { | 187 | .map(|(name, res)| (name.clone(), res.def.into())) |
188 | (name.clone(), res.def.into(), res.import.map(|id| Import { parent: self, id })) | ||
189 | }) | ||
190 | .collect() | 188 | .collect() |
191 | } | 189 | } |
192 | 190 | ||
@@ -229,11 +227,6 @@ impl Module { | |||
229 | } | 227 | } |
230 | } | 228 | } |
231 | 229 | ||
232 | pub struct Import { | ||
233 | pub(crate) parent: Module, | ||
234 | pub(crate) id: LocalImportId, | ||
235 | } | ||
236 | |||
237 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 230 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
238 | pub struct StructField { | 231 | pub struct StructField { |
239 | pub(crate) parent: VariantDef, | 232 | pub(crate) parent: VariantDef, |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index bfae3660b..f5ffd64fa 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -4,8 +4,8 @@ pub use hir_def::db::{ | |||
4 | BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery, | 4 | BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery, |
5 | DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery, | 5 | DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery, |
6 | FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, | 6 | FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, |
7 | LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery, | 7 | LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, StaticDataQuery, StructDataQuery, |
8 | StaticDataQuery, StructDataQuery, TraitDataQuery, TypeAliasDataQuery, | 8 | TraitDataQuery, TypeAliasDataQuery, |
9 | }; | 9 | }; |
10 | pub use hir_expand::db::{ | 10 | pub use hir_expand::db::{ |
11 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, | 11 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, |
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 42ca55fe7..6314be8d4 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs | |||
@@ -7,6 +7,8 @@ use hir_def::{ | |||
7 | StaticId, StructId, TraitId, TypeAliasId, UnionId, VariantId, | 7 | StaticId, StructId, TraitId, TypeAliasId, UnionId, VariantId, |
8 | }; | 8 | }; |
9 | use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; | 9 | use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; |
10 | use ra_db::FileId; | ||
11 | use ra_prof::profile; | ||
10 | use ra_syntax::{ | 12 | use ra_syntax::{ |
11 | ast::{self, AstNode, NameOwner}, | 13 | ast::{self, AstNode, NameOwner}, |
12 | match_ast, SyntaxNode, | 14 | match_ast, SyntaxNode, |
@@ -169,6 +171,7 @@ impl TypeParam { | |||
169 | 171 | ||
170 | impl Module { | 172 | impl Module { |
171 | pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Option<Self> { | 173 | pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Option<Self> { |
174 | let _p = profile("Module::from_declaration"); | ||
172 | let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast); | 175 | let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast); |
173 | 176 | ||
174 | let parent_module = match parent_declaration { | 177 | let parent_module = match parent_declaration { |
@@ -191,6 +194,7 @@ impl Module { | |||
191 | } | 194 | } |
192 | 195 | ||
193 | pub fn from_definition(db: &impl DefDatabase, src: InFile<ModuleSource>) -> Option<Self> { | 196 | pub fn from_definition(db: &impl DefDatabase, src: InFile<ModuleSource>) -> Option<Self> { |
197 | let _p = profile("Module::from_definition"); | ||
194 | match src.value { | 198 | match src.value { |
195 | ModuleSource::Module(ref module) => { | 199 | ModuleSource::Module(ref module) => { |
196 | assert!(!module.has_semi()); | 200 | assert!(!module.has_semi()); |
@@ -203,10 +207,14 @@ impl Module { | |||
203 | }; | 207 | }; |
204 | 208 | ||
205 | let original_file = src.file_id.original_file(db); | 209 | let original_file = src.file_id.original_file(db); |
210 | Module::from_file(db, original_file) | ||
211 | } | ||
206 | 212 | ||
207 | let (krate, local_id) = db.relevant_crates(original_file).iter().find_map(|&crate_id| { | 213 | fn from_file(db: &impl DefDatabase, file: FileId) -> Option<Self> { |
214 | let _p = profile("Module::from_file"); | ||
215 | let (krate, local_id) = db.relevant_crates(file).iter().find_map(|&crate_id| { | ||
208 | let crate_def_map = db.crate_def_map(crate_id); | 216 | let crate_def_map = db.crate_def_map(crate_id); |
209 | let local_id = crate_def_map.modules_for_file(original_file).next()?; | 217 | let local_id = crate_def_map.modules_for_file(file).next()?; |
210 | Some((crate_id, local_id)) | 218 | Some((crate_id, local_id)) |
211 | })?; | 219 | })?; |
212 | Some(Module { id: ModuleId { krate, local_id } }) | 220 | Some(Module { id: ModuleId { krate, local_id } }) |
@@ -214,6 +222,7 @@ impl Module { | |||
214 | } | 222 | } |
215 | 223 | ||
216 | fn analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> DynMap { | 224 | fn analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> DynMap { |
225 | let _p = profile("analyze_container"); | ||
217 | return child_by_source(db, src).unwrap_or_default(); | 226 | return child_by_source(db, src).unwrap_or_default(); |
218 | 227 | ||
219 | fn child_by_source(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<DynMap> { | 228 | fn child_by_source(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> Option<DynMap> { |
diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs index 72afecf26..5541266e2 100644 --- a/crates/ra_hir/src/has_source.rs +++ b/crates/ra_hir/src/has_source.rs | |||
@@ -9,8 +9,8 @@ use hir_def::{ | |||
9 | use ra_syntax::ast; | 9 | use ra_syntax::ast; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, Import, MacroDef, | 12 | db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, MacroDef, Module, |
13 | Module, Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, | 13 | Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | pub use hir_expand::InFile; | 16 | pub use hir_expand::InFile; |
@@ -117,18 +117,6 @@ impl HasSource for ImplBlock { | |||
117 | self.id.lookup(db).source(db) | 117 | self.id.lookup(db).source(db) |
118 | } | 118 | } |
119 | } | 119 | } |
120 | impl HasSource for Import { | ||
121 | type Ast = Either<ast::UseTree, ast::ExternCrateItem>; | ||
122 | |||
123 | /// Returns the syntax of the last path segment corresponding to this import | ||
124 | fn source(self, db: &impl DefDatabase) -> InFile<Self::Ast> { | ||
125 | let src = self.parent.definition_source(db); | ||
126 | let (_, source_map) = db.raw_items_with_source_map(src.file_id); | ||
127 | let root = db.parse_or_expand(src.file_id).unwrap(); | ||
128 | let ptr = source_map.get(self.id); | ||
129 | src.with_value(ptr.map_left(|it| it.to_node(&root)).map_right(|it| it.to_node(&root))) | ||
130 | } | ||
131 | } | ||
132 | 120 | ||
133 | impl HasSource for TypeParam { | 121 | impl HasSource for TypeParam { |
134 | type Ast = Either<ast::TraitDef, ast::TypeParam>; | 122 | type Ast = Either<ast::TraitDef, ast::TypeParam>; |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 7f9aef770..0008a8858 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -40,8 +40,8 @@ mod from_source; | |||
40 | pub use crate::{ | 40 | pub use crate::{ |
41 | code_model::{ | 41 | code_model::{ |
42 | Adt, AssocItem, AttrDef, Const, Crate, CrateDependency, DefWithBody, Docs, Enum, | 42 | Adt, AssocItem, AttrDef, Const, Crate, CrateDependency, DefWithBody, Docs, Enum, |
43 | EnumVariant, FieldSource, Function, GenericDef, HasAttrs, ImplBlock, Import, Local, | 43 | EnumVariant, FieldSource, Function, GenericDef, HasAttrs, ImplBlock, Local, MacroDef, |
44 | MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias, | 44 | Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias, |
45 | TypeParam, Union, VariantDef, | 45 | TypeParam, Union, VariantDef, |
46 | }, | 46 | }, |
47 | from_source::FromSource, | 47 | from_source::FromSource, |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index b60a6b87e..85b378483 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -26,6 +26,7 @@ use hir_ty::{ | |||
26 | method_resolution::{self, implements_trait}, | 26 | method_resolution::{self, implements_trait}, |
27 | Canonical, InEnvironment, InferenceResult, TraitEnvironment, Ty, | 27 | Canonical, InEnvironment, InferenceResult, TraitEnvironment, Ty, |
28 | }; | 28 | }; |
29 | use ra_prof::profile; | ||
29 | use ra_syntax::{ | 30 | use ra_syntax::{ |
30 | ast::{self, AstNode}, | 31 | ast::{self, AstNode}, |
31 | match_ast, AstPtr, | 32 | match_ast, AstPtr, |
@@ -83,6 +84,7 @@ fn def_with_body_from_child_node( | |||
83 | db: &impl HirDatabase, | 84 | db: &impl HirDatabase, |
84 | child: InFile<&SyntaxNode>, | 85 | child: InFile<&SyntaxNode>, |
85 | ) -> Option<DefWithBody> { | 86 | ) -> Option<DefWithBody> { |
87 | let _p = profile("def_with_body_from_child_node"); | ||
86 | child.cloned().ancestors_with_macros(db).find_map(|node| { | 88 | child.cloned().ancestors_with_macros(db).find_map(|node| { |
87 | let n = &node.value; | 89 | let n = &node.value; |
88 | match_ast! { | 90 | match_ast! { |
@@ -169,6 +171,7 @@ impl SourceAnalyzer { | |||
169 | node: InFile<&SyntaxNode>, | 171 | node: InFile<&SyntaxNode>, |
170 | offset: Option<TextUnit>, | 172 | offset: Option<TextUnit>, |
171 | ) -> SourceAnalyzer { | 173 | ) -> SourceAnalyzer { |
174 | let _p = profile("SourceAnalyzer::new"); | ||
172 | let def_with_body = def_with_body_from_child_node(db, node); | 175 | let def_with_body = def_with_body_from_child_node(db, node); |
173 | if let Some(def) = def_with_body { | 176 | if let Some(def) = def_with_body { |
174 | let (_body, source_map) = db.body_with_source_map(def.into()); | 177 | let (_body, source_map) = db.body_with_source_map(def.into()); |
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index ec3d57d1a..d9ea693e3 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -8,6 +8,7 @@ use hir_expand::{ | |||
8 | InFile, | 8 | InFile, |
9 | }; | 9 | }; |
10 | use ra_arena::{map::ArenaMap, Arena}; | 10 | use ra_arena::{map::ArenaMap, Arena}; |
11 | use ra_prof::profile; | ||
11 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 12 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; |
12 | 13 | ||
13 | use crate::{ | 14 | use crate::{ |
@@ -72,6 +73,7 @@ impl StructData { | |||
72 | 73 | ||
73 | impl EnumData { | 74 | impl EnumData { |
74 | pub(crate) fn enum_data_query(db: &impl DefDatabase, e: EnumId) -> Arc<EnumData> { | 75 | pub(crate) fn enum_data_query(db: &impl DefDatabase, e: EnumId) -> Arc<EnumData> { |
76 | let _p = profile("enum_data_query"); | ||
75 | let src = e.lookup(db).source(db); | 77 | let src = e.lookup(db).source(db); |
76 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); | 78 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
77 | let mut trace = Trace::new_for_arena(); | 79 | let mut trace = Trace::new_for_arena(); |
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 445d215b7..148ff007e 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -11,6 +11,7 @@ use hir_expand::{ | |||
11 | ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroCallKind, MacroDefId, | 11 | ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroCallKind, MacroDefId, |
12 | }; | 12 | }; |
13 | use ra_arena::{map::ArenaMap, Arena}; | 13 | use ra_arena::{map::ArenaMap, Arena}; |
14 | use ra_prof::profile; | ||
14 | use ra_syntax::{ast, AstNode, AstPtr}; | 15 | use ra_syntax::{ast, AstNode, AstPtr}; |
15 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
16 | 17 | ||
@@ -168,6 +169,7 @@ impl Body { | |||
168 | db: &impl DefDatabase, | 169 | db: &impl DefDatabase, |
169 | def: DefWithBodyId, | 170 | def: DefWithBodyId, |
170 | ) -> (Arc<Body>, Arc<BodySourceMap>) { | 171 | ) -> (Arc<Body>, Arc<BodySourceMap>) { |
172 | let _p = profile("body_with_source_map_query"); | ||
171 | let mut params = None; | 173 | let mut params = None; |
172 | 174 | ||
173 | let (file_id, module, body) = match def { | 175 | let (file_id, module, body) = match def { |
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index 98bff6cb7..c55fd4111 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -13,10 +13,7 @@ use crate::{ | |||
13 | docs::Documentation, | 13 | docs::Documentation, |
14 | generics::GenericParams, | 14 | generics::GenericParams, |
15 | lang_item::{LangItemTarget, LangItems}, | 15 | lang_item::{LangItemTarget, LangItems}, |
16 | nameres::{ | 16 | nameres::{raw::RawItems, CrateDefMap}, |
17 | raw::{ImportSourceMap, RawItems}, | ||
18 | CrateDefMap, | ||
19 | }, | ||
20 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, | 17 | AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, |
21 | GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, | 18 | GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, |
22 | TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, | 19 | TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, |
@@ -46,12 +43,6 @@ pub trait InternDatabase: SourceDatabase { | |||
46 | 43 | ||
47 | #[salsa::query_group(DefDatabaseStorage)] | 44 | #[salsa::query_group(DefDatabaseStorage)] |
48 | pub trait DefDatabase: InternDatabase + AstDatabase { | 45 | pub trait DefDatabase: InternDatabase + AstDatabase { |
49 | #[salsa::invoke(RawItems::raw_items_with_source_map_query)] | ||
50 | fn raw_items_with_source_map( | ||
51 | &self, | ||
52 | file_id: HirFileId, | ||
53 | ) -> (Arc<RawItems>, Arc<ImportSourceMap>); | ||
54 | |||
55 | #[salsa::invoke(RawItems::raw_items_query)] | 46 | #[salsa::invoke(RawItems::raw_items_query)] |
56 | fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>; | 47 | fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>; |
57 | 48 | ||
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index 6b9be8325..9e082c5f7 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs | |||
@@ -5,7 +5,7 @@ use hir_expand::name::Name; | |||
5 | use once_cell::sync::Lazy; | 5 | use once_cell::sync::Lazy; |
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | 7 | ||
8 | use crate::{per_ns::PerNs, BuiltinType, ImplId, LocalImportId, MacroDefId, ModuleDefId, TraitId}; | 8 | use crate::{per_ns::PerNs, BuiltinType, ImplId, MacroDefId, ModuleDefId, TraitId}; |
9 | 9 | ||
10 | #[derive(Debug, Default, PartialEq, Eq)] | 10 | #[derive(Debug, Default, PartialEq, Eq)] |
11 | pub struct ItemScope { | 11 | pub struct ItemScope { |
@@ -30,7 +30,7 @@ static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| { | |||
30 | BuiltinType::ALL | 30 | BuiltinType::ALL |
31 | .iter() | 31 | .iter() |
32 | .map(|(name, ty)| { | 32 | .map(|(name, ty)| { |
33 | (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: None }) | 33 | (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: false }) |
34 | }) | 34 | }) |
35 | .collect() | 35 | .collect() |
36 | }); | 36 | }); |
@@ -54,7 +54,7 @@ impl ItemScope { | |||
54 | 54 | ||
55 | pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ { | 55 | pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ { |
56 | self.entries() | 56 | self.entries() |
57 | .filter_map(|(_name, res)| if res.import.is_none() { Some(res.def) } else { None }) | 57 | .filter_map(|(_name, res)| if !res.import { Some(res.def) } else { None }) |
58 | .flat_map(|per_ns| { | 58 | .flat_map(|per_ns| { |
59 | per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter()) | 59 | per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter()) |
60 | }) | 60 | }) |
@@ -112,36 +112,27 @@ impl ItemScope { | |||
112 | self.legacy_macros.insert(name, mac); | 112 | self.legacy_macros.insert(name, mac); |
113 | } | 113 | } |
114 | 114 | ||
115 | pub(crate) fn push_res( | 115 | pub(crate) fn push_res(&mut self, name: Name, res: &Resolution, import: bool) -> bool { |
116 | &mut self, | ||
117 | name: Name, | ||
118 | res: &Resolution, | ||
119 | import: Option<LocalImportId>, | ||
120 | ) -> bool { | ||
121 | let mut changed = false; | 116 | let mut changed = false; |
122 | let existing = self.items.entry(name.clone()).or_default(); | 117 | let existing = self.items.entry(name.clone()).or_default(); |
123 | 118 | ||
124 | if existing.def.types.is_none() && res.def.types.is_some() { | 119 | if existing.def.types.is_none() && res.def.types.is_some() { |
125 | existing.def.types = res.def.types; | 120 | existing.def.types = res.def.types; |
126 | existing.import = import.or(res.import); | 121 | existing.import = import || res.import; |
127 | changed = true; | 122 | changed = true; |
128 | } | 123 | } |
129 | if existing.def.values.is_none() && res.def.values.is_some() { | 124 | if existing.def.values.is_none() && res.def.values.is_some() { |
130 | existing.def.values = res.def.values; | 125 | existing.def.values = res.def.values; |
131 | existing.import = import.or(res.import); | 126 | existing.import = import || res.import; |
132 | changed = true; | 127 | changed = true; |
133 | } | 128 | } |
134 | if existing.def.macros.is_none() && res.def.macros.is_some() { | 129 | if existing.def.macros.is_none() && res.def.macros.is_some() { |
135 | existing.def.macros = res.def.macros; | 130 | existing.def.macros = res.def.macros; |
136 | existing.import = import.or(res.import); | 131 | existing.import = import || res.import; |
137 | changed = true; | 132 | changed = true; |
138 | } | 133 | } |
139 | 134 | ||
140 | if existing.def.is_none() | 135 | if existing.def.is_none() && res.def.is_none() && !existing.import && res.import { |
141 | && res.def.is_none() | ||
142 | && existing.import.is_none() | ||
143 | && res.import.is_some() | ||
144 | { | ||
145 | existing.import = res.import; | 136 | existing.import = res.import; |
146 | } | 137 | } |
147 | changed | 138 | changed |
@@ -160,6 +151,5 @@ impl ItemScope { | |||
160 | pub struct Resolution { | 151 | pub struct Resolution { |
161 | /// None for unresolved | 152 | /// None for unresolved |
162 | pub def: PerNs, | 153 | pub def: PerNs, |
163 | /// ident by which this is imported into local scope. | 154 | pub(crate) import: bool, |
164 | pub import: Option<LocalImportId>, | ||
165 | } | 155 | } |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index acd4f4af1..f6c7f38d1 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -52,10 +52,6 @@ use crate::body::Expander; | |||
52 | use crate::builtin_type::BuiltinType; | 52 | use crate::builtin_type::BuiltinType; |
53 | 53 | ||
54 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 54 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
55 | pub struct LocalImportId(RawId); | ||
56 | impl_arena_id!(LocalImportId); | ||
57 | |||
58 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
59 | pub struct ModuleId { | 55 | pub struct ModuleId { |
60 | pub krate: CrateId, | 56 | pub krate: CrateId, |
61 | pub local_id: LocalModuleId, | 57 | pub local_id: LocalModuleId, |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 45199fa11..2b194f488 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -26,8 +26,7 @@ use crate::{ | |||
26 | path::{ModPath, PathKind}, | 26 | path::{ModPath, PathKind}, |
27 | per_ns::PerNs, | 27 | per_ns::PerNs, |
28 | AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, | 28 | AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, |
29 | LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, | 29 | LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, |
30 | TypeAliasLoc, UnionLoc, | ||
31 | }; | 30 | }; |
32 | 31 | ||
33 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { | 32 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { |
@@ -93,7 +92,7 @@ impl PartialResolvedImport { | |||
93 | #[derive(Clone, Debug, Eq, PartialEq)] | 92 | #[derive(Clone, Debug, Eq, PartialEq)] |
94 | struct ImportDirective { | 93 | struct ImportDirective { |
95 | module_id: LocalModuleId, | 94 | module_id: LocalModuleId, |
96 | import_id: LocalImportId, | 95 | import_id: raw::Import, |
97 | import: raw::ImportData, | 96 | import: raw::ImportData, |
98 | status: PartialResolvedImport, | 97 | status: PartialResolvedImport, |
99 | } | 98 | } |
@@ -110,7 +109,7 @@ struct MacroDirective { | |||
110 | struct DefCollector<'a, DB> { | 109 | struct DefCollector<'a, DB> { |
111 | db: &'a DB, | 110 | db: &'a DB, |
112 | def_map: CrateDefMap, | 111 | def_map: CrateDefMap, |
113 | glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, LocalImportId)>>, | 112 | glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, raw::Import)>>, |
114 | unresolved_imports: Vec<ImportDirective>, | 113 | unresolved_imports: Vec<ImportDirective>, |
115 | resolved_imports: Vec<ImportDirective>, | 114 | resolved_imports: Vec<ImportDirective>, |
116 | unexpanded_macros: Vec<MacroDirective>, | 115 | unexpanded_macros: Vec<MacroDirective>, |
@@ -219,7 +218,7 @@ where | |||
219 | self.update( | 218 | self.update( |
220 | self.def_map.root, | 219 | self.def_map.root, |
221 | None, | 220 | None, |
222 | &[(name, Resolution { def: PerNs::macros(macro_), import: None })], | 221 | &[(name, Resolution { def: PerNs::macros(macro_), import: false })], |
223 | ); | 222 | ); |
224 | } | 223 | } |
225 | } | 224 | } |
@@ -404,7 +403,7 @@ where | |||
404 | let variant = EnumVariantId { parent: e, local_id }; | 403 | let variant = EnumVariantId { parent: e, local_id }; |
405 | let res = Resolution { | 404 | let res = Resolution { |
406 | def: PerNs::both(variant.into(), variant.into()), | 405 | def: PerNs::both(variant.into(), variant.into()), |
407 | import: Some(import_id), | 406 | import: true, |
408 | }; | 407 | }; |
409 | (name, res) | 408 | (name, res) |
410 | }) | 409 | }) |
@@ -431,7 +430,7 @@ where | |||
431 | } | 430 | } |
432 | } | 431 | } |
433 | 432 | ||
434 | let resolution = Resolution { def, import: Some(import_id) }; | 433 | let resolution = Resolution { def, import: true }; |
435 | self.update(module_id, Some(import_id), &[(name, resolution)]); | 434 | self.update(module_id, Some(import_id), &[(name, resolution)]); |
436 | } | 435 | } |
437 | None => tested_by!(bogus_paths), | 436 | None => tested_by!(bogus_paths), |
@@ -442,7 +441,7 @@ where | |||
442 | fn update( | 441 | fn update( |
443 | &mut self, | 442 | &mut self, |
444 | module_id: LocalModuleId, | 443 | module_id: LocalModuleId, |
445 | import: Option<LocalImportId>, | 444 | import: Option<raw::Import>, |
446 | resolutions: &[(Name, Resolution)], | 445 | resolutions: &[(Name, Resolution)], |
447 | ) { | 446 | ) { |
448 | self.update_recursive(module_id, import, resolutions, 0) | 447 | self.update_recursive(module_id, import, resolutions, 0) |
@@ -451,7 +450,7 @@ where | |||
451 | fn update_recursive( | 450 | fn update_recursive( |
452 | &mut self, | 451 | &mut self, |
453 | module_id: LocalModuleId, | 452 | module_id: LocalModuleId, |
454 | import: Option<LocalImportId>, | 453 | import: Option<raw::Import>, |
455 | resolutions: &[(Name, Resolution)], | 454 | resolutions: &[(Name, Resolution)], |
456 | depth: usize, | 455 | depth: usize, |
457 | ) { | 456 | ) { |
@@ -462,7 +461,7 @@ where | |||
462 | let scope = &mut self.def_map.modules[module_id].scope; | 461 | let scope = &mut self.def_map.modules[module_id].scope; |
463 | let mut changed = false; | 462 | let mut changed = false; |
464 | for (name, res) in resolutions { | 463 | for (name, res) in resolutions { |
465 | changed |= scope.push_res(name.clone(), res, import); | 464 | changed |= scope.push_res(name.clone(), res, import.is_some()); |
466 | } | 465 | } |
467 | 466 | ||
468 | if !changed { | 467 | if !changed { |
@@ -719,7 +718,7 @@ where | |||
719 | def: PerNs::types( | 718 | def: PerNs::types( |
720 | ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(), | 719 | ModuleId { krate: self.def_collector.def_map.krate, local_id: res }.into(), |
721 | ), | 720 | ), |
722 | import: None, | 721 | import: false, |
723 | }; | 722 | }; |
724 | self.def_collector.update(self.module_id, None, &[(name, resolution)]); | 723 | self.def_collector.update(self.module_id, None, &[(name, resolution)]); |
725 | res | 724 | res |
@@ -791,7 +790,7 @@ where | |||
791 | PerNs::types(def.into()) | 790 | PerNs::types(def.into()) |
792 | } | 791 | } |
793 | }; | 792 | }; |
794 | let resolution = Resolution { def, import: None }; | 793 | let resolution = Resolution { def, import: false }; |
795 | self.def_collector.update(self.module_id, None, &[(name, resolution)]) | 794 | self.def_collector.update(self.module_id, None, &[(name, resolution)]) |
796 | } | 795 | } |
797 | 796 | ||
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index ecb4d7c03..73dc08745 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -7,24 +7,21 @@ | |||
7 | 7 | ||
8 | use std::{ops::Index, sync::Arc}; | 8 | use std::{ops::Index, sync::Arc}; |
9 | 9 | ||
10 | use either::Either; | ||
11 | use hir_expand::{ | 10 | use hir_expand::{ |
12 | ast_id_map::AstIdMap, | 11 | ast_id_map::AstIdMap, |
13 | db::AstDatabase, | 12 | db::AstDatabase, |
14 | hygiene::Hygiene, | 13 | hygiene::Hygiene, |
15 | name::{AsName, Name}, | 14 | name::{AsName, Name}, |
16 | }; | 15 | }; |
17 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 16 | use ra_arena::{impl_arena_id, Arena, RawId}; |
17 | use ra_prof::profile; | ||
18 | use ra_syntax::{ | 18 | use ra_syntax::{ |
19 | ast::{self, AttrsOwner, NameOwner}, | 19 | ast::{self, AttrsOwner, NameOwner}, |
20 | AstNode, AstPtr, | 20 | AstNode, |
21 | }; | 21 | }; |
22 | use test_utils::tested_by; | 22 | use test_utils::tested_by; |
23 | 23 | ||
24 | use crate::{ | 24 | use crate::{attr::Attrs, db::DefDatabase, path::ModPath, FileAstId, HirFileId, InFile}; |
25 | attr::Attrs, db::DefDatabase, path::ModPath, trace::Trace, FileAstId, HirFileId, InFile, | ||
26 | LocalImportId, | ||
27 | }; | ||
28 | 25 | ||
29 | /// `RawItems` is a set of top-level items in a file (except for impls). | 26 | /// `RawItems` is a set of top-level items in a file (except for impls). |
30 | /// | 27 | /// |
@@ -33,7 +30,7 @@ use crate::{ | |||
33 | #[derive(Debug, Default, PartialEq, Eq)] | 30 | #[derive(Debug, Default, PartialEq, Eq)] |
34 | pub struct RawItems { | 31 | pub struct RawItems { |
35 | modules: Arena<Module, ModuleData>, | 32 | modules: Arena<Module, ModuleData>, |
36 | imports: Arena<LocalImportId, ImportData>, | 33 | imports: Arena<Import, ImportData>, |
37 | defs: Arena<Def, DefData>, | 34 | defs: Arena<Def, DefData>, |
38 | macros: Arena<Macro, MacroData>, | 35 | macros: Arena<Macro, MacroData>, |
39 | impls: Arena<Impl, ImplData>, | 36 | impls: Arena<Impl, ImplData>, |
@@ -41,35 +38,15 @@ pub struct RawItems { | |||
41 | items: Vec<RawItem>, | 38 | items: Vec<RawItem>, |
42 | } | 39 | } |
43 | 40 | ||
44 | #[derive(Debug, Default, PartialEq, Eq)] | ||
45 | pub struct ImportSourceMap { | ||
46 | map: ArenaMap<LocalImportId, ImportSourcePtr>, | ||
47 | } | ||
48 | |||
49 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; | ||
50 | |||
51 | impl ImportSourceMap { | ||
52 | pub fn get(&self, import: LocalImportId) -> ImportSourcePtr { | ||
53 | self.map[import].clone() | ||
54 | } | ||
55 | } | ||
56 | |||
57 | impl RawItems { | 41 | impl RawItems { |
58 | pub(crate) fn raw_items_query( | 42 | pub(crate) fn raw_items_query( |
59 | db: &(impl DefDatabase + AstDatabase), | 43 | db: &(impl DefDatabase + AstDatabase), |
60 | file_id: HirFileId, | 44 | file_id: HirFileId, |
61 | ) -> Arc<RawItems> { | 45 | ) -> Arc<RawItems> { |
62 | db.raw_items_with_source_map(file_id).0 | 46 | let _p = profile("raw_items_query"); |
63 | } | ||
64 | |||
65 | pub(crate) fn raw_items_with_source_map_query( | ||
66 | db: &(impl DefDatabase + AstDatabase), | ||
67 | file_id: HirFileId, | ||
68 | ) -> (Arc<RawItems>, Arc<ImportSourceMap>) { | ||
69 | let mut collector = RawItemsCollector { | 47 | let mut collector = RawItemsCollector { |
70 | raw_items: RawItems::default(), | 48 | raw_items: RawItems::default(), |
71 | source_ast_id_map: db.ast_id_map(file_id), | 49 | source_ast_id_map: db.ast_id_map(file_id), |
72 | imports: Trace::new(), | ||
73 | file_id, | 50 | file_id, |
74 | hygiene: Hygiene::new(db, file_id), | 51 | hygiene: Hygiene::new(db, file_id), |
75 | }; | 52 | }; |
@@ -80,11 +57,8 @@ impl RawItems { | |||
80 | collector.process_module(None, item_list); | 57 | collector.process_module(None, item_list); |
81 | } | 58 | } |
82 | } | 59 | } |
83 | let mut raw_items = collector.raw_items; | 60 | let raw_items = collector.raw_items; |
84 | let (arena, map) = collector.imports.into_arena_and_map(); | 61 | Arc::new(raw_items) |
85 | raw_items.imports = arena; | ||
86 | let source_map = ImportSourceMap { map }; | ||
87 | (Arc::new(raw_items), Arc::new(source_map)) | ||
88 | } | 62 | } |
89 | 63 | ||
90 | pub(super) fn items(&self) -> &[RawItem] { | 64 | pub(super) fn items(&self) -> &[RawItem] { |
@@ -99,9 +73,9 @@ impl Index<Module> for RawItems { | |||
99 | } | 73 | } |
100 | } | 74 | } |
101 | 75 | ||
102 | impl Index<LocalImportId> for RawItems { | 76 | impl Index<Import> for RawItems { |
103 | type Output = ImportData; | 77 | type Output = ImportData; |
104 | fn index(&self, idx: LocalImportId) -> &ImportData { | 78 | fn index(&self, idx: Import) -> &ImportData { |
105 | &self.imports[idx] | 79 | &self.imports[idx] |
106 | } | 80 | } |
107 | } | 81 | } |
@@ -136,7 +110,7 @@ pub(super) struct RawItem { | |||
136 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 110 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
137 | pub(super) enum RawItemKind { | 111 | pub(super) enum RawItemKind { |
138 | Module(Module), | 112 | Module(Module), |
139 | Import(LocalImportId), | 113 | Import(Import), |
140 | Def(Def), | 114 | Def(Def), |
141 | Macro(Macro), | 115 | Macro(Macro), |
142 | Impl(Impl), | 116 | Impl(Impl), |
@@ -152,6 +126,10 @@ pub(super) enum ModuleData { | |||
152 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, | 126 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, |
153 | } | 127 | } |
154 | 128 | ||
129 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
130 | pub(crate) struct Import(RawId); | ||
131 | impl_arena_id!(Import); | ||
132 | |||
155 | #[derive(Debug, Clone, PartialEq, Eq)] | 133 | #[derive(Debug, Clone, PartialEq, Eq)] |
156 | pub struct ImportData { | 134 | pub struct ImportData { |
157 | pub(super) path: ModPath, | 135 | pub(super) path: ModPath, |
@@ -223,7 +201,6 @@ pub(super) struct ImplData { | |||
223 | 201 | ||
224 | struct RawItemsCollector { | 202 | struct RawItemsCollector { |
225 | raw_items: RawItems, | 203 | raw_items: RawItems, |
226 | imports: Trace<LocalImportId, ImportData, ImportSourcePtr>, | ||
227 | source_ast_id_map: Arc<AstIdMap>, | 204 | source_ast_id_map: Arc<AstIdMap>, |
228 | file_id: HirFileId, | 205 | file_id: HirFileId, |
229 | hygiene: Hygiene, | 206 | hygiene: Hygiene, |
@@ -330,7 +307,7 @@ impl RawItemsCollector { | |||
330 | ModPath::expand_use_item( | 307 | ModPath::expand_use_item( |
331 | InFile { value: use_item, file_id: self.file_id }, | 308 | InFile { value: use_item, file_id: self.file_id }, |
332 | &self.hygiene, | 309 | &self.hygiene, |
333 | |path, use_tree, is_glob, alias| { | 310 | |path, _use_tree, is_glob, alias| { |
334 | let import_data = ImportData { | 311 | let import_data = ImportData { |
335 | path, | 312 | path, |
336 | alias, | 313 | alias, |
@@ -339,11 +316,11 @@ impl RawItemsCollector { | |||
339 | is_extern_crate: false, | 316 | is_extern_crate: false, |
340 | is_macro_use: false, | 317 | is_macro_use: false, |
341 | }; | 318 | }; |
342 | buf.push((import_data, Either::Left(AstPtr::new(use_tree)))); | 319 | buf.push(import_data); |
343 | }, | 320 | }, |
344 | ); | 321 | ); |
345 | for (import_data, ptr) in buf { | 322 | for import_data in buf { |
346 | self.push_import(current_module, attrs.clone(), import_data, ptr); | 323 | self.push_import(current_module, attrs.clone(), import_data); |
347 | } | 324 | } |
348 | } | 325 | } |
349 | 326 | ||
@@ -366,12 +343,7 @@ impl RawItemsCollector { | |||
366 | is_extern_crate: true, | 343 | is_extern_crate: true, |
367 | is_macro_use, | 344 | is_macro_use, |
368 | }; | 345 | }; |
369 | self.push_import( | 346 | self.push_import(current_module, attrs, import_data); |
370 | current_module, | ||
371 | attrs, | ||
372 | import_data, | ||
373 | Either::Right(AstPtr::new(&extern_crate)), | ||
374 | ); | ||
375 | } | 347 | } |
376 | } | 348 | } |
377 | 349 | ||
@@ -402,14 +374,8 @@ impl RawItemsCollector { | |||
402 | self.push_item(current_module, attrs, RawItemKind::Impl(imp)) | 374 | self.push_item(current_module, attrs, RawItemKind::Impl(imp)) |
403 | } | 375 | } |
404 | 376 | ||
405 | fn push_import( | 377 | fn push_import(&mut self, current_module: Option<Module>, attrs: Attrs, data: ImportData) { |
406 | &mut self, | 378 | let import = self.raw_items.imports.alloc(data); |
407 | current_module: Option<Module>, | ||
408 | attrs: Attrs, | ||
409 | data: ImportData, | ||
410 | source: ImportSourcePtr, | ||
411 | ) { | ||
412 | let import = self.imports.alloc(|| source, || data); | ||
413 | self.push_item(current_module, attrs, RawItemKind::Import(import)) | 379 | self.push_item(current_module, attrs, RawItemKind::Import(import)) |
414 | } | 380 | } |
415 | 381 | ||
diff --git a/crates/ra_hir_def/src/trace.rs b/crates/ra_hir_def/src/trace.rs index 2bcd707bc..9769e88df 100644 --- a/crates/ra_hir_def/src/trace.rs +++ b/crates/ra_hir_def/src/trace.rs | |||
@@ -18,10 +18,6 @@ pub(crate) struct Trace<ID: ArenaId, T, V> { | |||
18 | } | 18 | } |
19 | 19 | ||
20 | impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> { | 20 | impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> { |
21 | pub(crate) fn new() -> Trace<ID, T, V> { | ||
22 | Trace { arena: Some(Arena::default()), map: Some(ArenaMap::default()), len: 0 } | ||
23 | } | ||
24 | |||
25 | pub(crate) fn new_for_arena() -> Trace<ID, T, V> { | 21 | pub(crate) fn new_for_arena() -> Trace<ID, T, V> { |
26 | Trace { arena: Some(Arena::default()), map: None, len: 0 } | 22 | Trace { arena: Some(Arena::default()), map: None, len: 0 } |
27 | } | 23 | } |
@@ -52,8 +48,4 @@ impl<ID: ra_arena::ArenaId + Copy, T, V> Trace<ID, T, V> { | |||
52 | pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> { | 48 | pub(crate) fn into_map(mut self) -> ArenaMap<ID, V> { |
53 | self.map.take().unwrap() | 49 | self.map.take().unwrap() |
54 | } | 50 | } |
55 | |||
56 | pub(crate) fn into_arena_and_map(mut self) -> (Arena<ID, T>, ArenaMap<ID, V>) { | ||
57 | (self.arena.take().unwrap(), self.map.take().unwrap()) | ||
58 | } | ||
59 | } | 51 | } |
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index 857f8a444..2c119269c 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -26,6 +26,13 @@ macro_rules! register_builtin { | |||
26 | }; | 26 | }; |
27 | expander(db, id, tt) | 27 | expander(db, id, tt) |
28 | } | 28 | } |
29 | |||
30 | fn by_name(ident: &name::Name) -> Option<BuiltinFnLikeExpander> { | ||
31 | match ident { | ||
32 | $( id if id == &name::name![$name] => Some(BuiltinFnLikeExpander::$kind), )* | ||
33 | _ => return None, | ||
34 | } | ||
35 | } | ||
29 | } | 36 | } |
30 | 37 | ||
31 | pub fn find_builtin_macro( | 38 | pub fn find_builtin_macro( |
@@ -33,10 +40,7 @@ macro_rules! register_builtin { | |||
33 | krate: CrateId, | 40 | krate: CrateId, |
34 | ast_id: AstId<ast::MacroCall>, | 41 | ast_id: AstId<ast::MacroCall>, |
35 | ) -> Option<MacroDefId> { | 42 | ) -> Option<MacroDefId> { |
36 | let kind = match ident { | 43 | let kind = BuiltinFnLikeExpander::by_name(ident)?; |
37 | $( id if id == &name::name![$name] => BuiltinFnLikeExpander::$kind, )* | ||
38 | _ => return None, | ||
39 | }; | ||
40 | 44 | ||
41 | Some(MacroDefId { krate: Some(krate), ast_id: Some(ast_id), kind: MacroDefKind::BuiltIn(kind) }) | 45 | Some(MacroDefId { krate: Some(krate), ast_id: Some(ast_id), kind: MacroDefKind::BuiltIn(kind) }) |
42 | } | 46 | } |
@@ -50,6 +54,8 @@ register_builtin! { | |||
50 | (line, Line) => line_expand, | 54 | (line, Line) => line_expand, |
51 | (stringify, Stringify) => stringify_expand, | 55 | (stringify, Stringify) => stringify_expand, |
52 | (format_args, FormatArgs) => format_args_expand, | 56 | (format_args, FormatArgs) => format_args_expand, |
57 | (env, Env) => env_expand, | ||
58 | (option_env, OptionEnv) => option_env_expand, | ||
53 | // format_args_nl only differs in that it adds a newline in the end, | 59 | // format_args_nl only differs in that it adds a newline in the end, |
54 | // so we use the same stub expansion for now | 60 | // so we use the same stub expansion for now |
55 | (format_args_nl, FormatArgsNl) => format_args_expand | 61 | (format_args_nl, FormatArgsNl) => format_args_expand |
@@ -121,6 +127,28 @@ fn stringify_expand( | |||
121 | Ok(expanded) | 127 | Ok(expanded) |
122 | } | 128 | } |
123 | 129 | ||
130 | fn env_expand( | ||
131 | _db: &dyn AstDatabase, | ||
132 | _id: MacroCallId, | ||
133 | _tt: &tt::Subtree, | ||
134 | ) -> Result<tt::Subtree, mbe::ExpandError> { | ||
135 | // dummy implementation for type-checking purposes | ||
136 | let expanded = quote! { "" }; | ||
137 | |||
138 | Ok(expanded) | ||
139 | } | ||
140 | |||
141 | fn option_env_expand( | ||
142 | _db: &dyn AstDatabase, | ||
143 | _id: MacroCallId, | ||
144 | _tt: &tt::Subtree, | ||
145 | ) -> Result<tt::Subtree, mbe::ExpandError> { | ||
146 | // dummy implementation for type-checking purposes | ||
147 | let expanded = quote! { std::option::Option::None::<&str> }; | ||
148 | |||
149 | Ok(expanded) | ||
150 | } | ||
151 | |||
124 | fn to_col_number(db: &dyn AstDatabase, file: HirFileId, pos: TextUnit) -> usize { | 152 | fn to_col_number(db: &dyn AstDatabase, file: HirFileId, pos: TextUnit) -> usize { |
125 | // FIXME: Use expansion info | 153 | // FIXME: Use expansion info |
126 | let file_id = file.original_file(db); | 154 | let file_id = file.original_file(db); |
@@ -248,10 +276,11 @@ fn format_args_expand( | |||
248 | #[cfg(test)] | 276 | #[cfg(test)] |
249 | mod tests { | 277 | mod tests { |
250 | use super::*; | 278 | use super::*; |
251 | use crate::{test_db::TestDB, MacroCallKind, MacroCallLoc}; | 279 | use crate::{name::AsName, test_db::TestDB, MacroCallKind, MacroCallLoc}; |
252 | use ra_db::{fixture::WithFixture, SourceDatabase}; | 280 | use ra_db::{fixture::WithFixture, SourceDatabase}; |
281 | use ra_syntax::ast::NameOwner; | ||
253 | 282 | ||
254 | fn expand_builtin_macro(s: &str, expander: BuiltinFnLikeExpander) -> String { | 283 | fn expand_builtin_macro(s: &str) -> String { |
255 | let (db, file_id) = TestDB::with_single_file(&s); | 284 | let (db, file_id) = TestDB::with_single_file(&s); |
256 | let parsed = db.parse(file_id); | 285 | let parsed = db.parse(file_id); |
257 | let macro_calls: Vec<_> = | 286 | let macro_calls: Vec<_> = |
@@ -259,6 +288,9 @@ mod tests { | |||
259 | 288 | ||
260 | let ast_id_map = db.ast_id_map(file_id.into()); | 289 | let ast_id_map = db.ast_id_map(file_id.into()); |
261 | 290 | ||
291 | let expander = | ||
292 | BuiltinFnLikeExpander::by_name(¯o_calls[0].name().unwrap().as_name()).unwrap(); | ||
293 | |||
262 | // the first one should be a macro_rules | 294 | // the first one should be a macro_rules |
263 | let def = MacroDefId { | 295 | let def = MacroDefId { |
264 | krate: Some(CrateId(0)), | 296 | krate: Some(CrateId(0)), |
@@ -284,25 +316,23 @@ mod tests { | |||
284 | fn test_column_expand() { | 316 | fn test_column_expand() { |
285 | let expanded = expand_builtin_macro( | 317 | let expanded = expand_builtin_macro( |
286 | r#" | 318 | r#" |
287 | #[rustc_builtin_macro] | 319 | #[rustc_builtin_macro] |
288 | macro_rules! column {() => {}} | 320 | macro_rules! column {() => {}} |
289 | column!() | 321 | column!() |
290 | "#, | 322 | "#, |
291 | BuiltinFnLikeExpander::Column, | ||
292 | ); | 323 | ); |
293 | 324 | ||
294 | assert_eq!(expanded, "9"); | 325 | assert_eq!(expanded, "13"); |
295 | } | 326 | } |
296 | 327 | ||
297 | #[test] | 328 | #[test] |
298 | fn test_line_expand() { | 329 | fn test_line_expand() { |
299 | let expanded = expand_builtin_macro( | 330 | let expanded = expand_builtin_macro( |
300 | r#" | 331 | r#" |
301 | #[rustc_builtin_macro] | 332 | #[rustc_builtin_macro] |
302 | macro_rules! line {() => {}} | 333 | macro_rules! line {() => {}} |
303 | line!() | 334 | line!() |
304 | "#, | 335 | "#, |
305 | BuiltinFnLikeExpander::Line, | ||
306 | ); | 336 | ); |
307 | 337 | ||
308 | assert_eq!(expanded, "4"); | 338 | assert_eq!(expanded, "4"); |
@@ -312,25 +342,49 @@ mod tests { | |||
312 | fn test_stringify_expand() { | 342 | fn test_stringify_expand() { |
313 | let expanded = expand_builtin_macro( | 343 | let expanded = expand_builtin_macro( |
314 | r#" | 344 | r#" |
315 | #[rustc_builtin_macro] | 345 | #[rustc_builtin_macro] |
316 | macro_rules! stringify {() => {}} | 346 | macro_rules! stringify {() => {}} |
317 | stringify!(a b c) | 347 | stringify!(a b c) |
318 | "#, | 348 | "#, |
319 | BuiltinFnLikeExpander::Stringify, | ||
320 | ); | 349 | ); |
321 | 350 | ||
322 | assert_eq!(expanded, "\"a b c\""); | 351 | assert_eq!(expanded, "\"a b c\""); |
323 | } | 352 | } |
324 | 353 | ||
325 | #[test] | 354 | #[test] |
355 | fn test_env_expand() { | ||
356 | let expanded = expand_builtin_macro( | ||
357 | r#" | ||
358 | #[rustc_builtin_macro] | ||
359 | macro_rules! env {() => {}} | ||
360 | env!("TEST_ENV_VAR") | ||
361 | "#, | ||
362 | ); | ||
363 | |||
364 | assert_eq!(expanded, "\"\""); | ||
365 | } | ||
366 | |||
367 | #[test] | ||
368 | fn test_option_env_expand() { | ||
369 | let expanded = expand_builtin_macro( | ||
370 | r#" | ||
371 | #[rustc_builtin_macro] | ||
372 | macro_rules! option_env {() => {}} | ||
373 | option_env!("TEST_ENV_VAR") | ||
374 | "#, | ||
375 | ); | ||
376 | |||
377 | assert_eq!(expanded, "std::option::Option::None:: <&str>"); | ||
378 | } | ||
379 | |||
380 | #[test] | ||
326 | fn test_file_expand() { | 381 | fn test_file_expand() { |
327 | let expanded = expand_builtin_macro( | 382 | let expanded = expand_builtin_macro( |
328 | r#" | 383 | r#" |
329 | #[rustc_builtin_macro] | 384 | #[rustc_builtin_macro] |
330 | macro_rules! file {() => {}} | 385 | macro_rules! file {() => {}} |
331 | file!() | 386 | file!() |
332 | "#, | 387 | "#, |
333 | BuiltinFnLikeExpander::File, | ||
334 | ); | 388 | ); |
335 | 389 | ||
336 | assert_eq!(expanded, "\"\""); | 390 | assert_eq!(expanded, "\"\""); |
@@ -340,14 +394,13 @@ mod tests { | |||
340 | fn test_compile_error_expand() { | 394 | fn test_compile_error_expand() { |
341 | let expanded = expand_builtin_macro( | 395 | let expanded = expand_builtin_macro( |
342 | r#" | 396 | r#" |
343 | #[rustc_builtin_macro] | 397 | #[rustc_builtin_macro] |
344 | macro_rules! compile_error { | 398 | macro_rules! compile_error { |
345 | ($msg:expr) => ({ /* compiler built-in */ }); | 399 | ($msg:expr) => ({ /* compiler built-in */ }); |
346 | ($msg:expr,) => ({ /* compiler built-in */ }) | 400 | ($msg:expr,) => ({ /* compiler built-in */ }) |
347 | } | 401 | } |
348 | compile_error!("error!"); | 402 | compile_error!("error!"); |
349 | "#, | 403 | "#, |
350 | BuiltinFnLikeExpander::CompileError, | ||
351 | ); | 404 | ); |
352 | 405 | ||
353 | assert_eq!(expanded, r#"loop{"error!"}"#); | 406 | assert_eq!(expanded, r#"loop{"error!"}"#); |
@@ -357,14 +410,13 @@ mod tests { | |||
357 | fn test_format_args_expand() { | 410 | fn test_format_args_expand() { |
358 | let expanded = expand_builtin_macro( | 411 | let expanded = expand_builtin_macro( |
359 | r#" | 412 | r#" |
360 | #[rustc_builtin_macro] | 413 | #[rustc_builtin_macro] |
361 | macro_rules! format_args { | 414 | macro_rules! format_args { |
362 | ($fmt:expr) => ({ /* compiler built-in */ }); | 415 | ($fmt:expr) => ({ /* compiler built-in */ }); |
363 | ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ }) | 416 | ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ }) |
364 | } | 417 | } |
365 | format_args!("{} {:?}", arg1(a, b, c), arg2); | 418 | format_args!("{} {:?}", arg1(a, b, c), arg2); |
366 | "#, | 419 | "#, |
367 | BuiltinFnLikeExpander::FormatArgs, | ||
368 | ); | 420 | ); |
369 | 421 | ||
370 | assert_eq!( | 422 | assert_eq!( |
diff --git a/crates/ra_hir_expand/src/name.rs b/crates/ra_hir_expand/src/name.rs index fd02ffa4e..e62693b68 100644 --- a/crates/ra_hir_expand/src/name.rs +++ b/crates/ra_hir_expand/src/name.rs | |||
@@ -170,6 +170,8 @@ pub mod known { | |||
170 | stringify, | 170 | stringify, |
171 | format_args, | 171 | format_args, |
172 | format_args_nl, | 172 | format_args_nl, |
173 | env, | ||
174 | option_env, | ||
173 | // Builtin derives | 175 | // Builtin derives |
174 | Copy, | 176 | Copy, |
175 | Clone, | 177 | Clone, |
diff --git a/crates/ra_hir_expand/src/quote.rs b/crates/ra_hir_expand/src/quote.rs index 49155fe62..4de219ce4 100644 --- a/crates/ra_hir_expand/src/quote.rs +++ b/crates/ra_hir_expand/src/quote.rs | |||
@@ -102,6 +102,8 @@ macro_rules! __quote { | |||
102 | ( : ) => {$crate::__quote!(@PUNCT ':')}; | 102 | ( : ) => {$crate::__quote!(@PUNCT ':')}; |
103 | ( :: ) => {$crate::__quote!(@PUNCT ':', ':')}; | 103 | ( :: ) => {$crate::__quote!(@PUNCT ':', ':')}; |
104 | ( . ) => {$crate::__quote!(@PUNCT '.')}; | 104 | ( . ) => {$crate::__quote!(@PUNCT '.')}; |
105 | ( < ) => {$crate::__quote!(@PUNCT '<')}; | ||
106 | ( > ) => {$crate::__quote!(@PUNCT '>')}; | ||
105 | 107 | ||
106 | ( $first:tt $($tail:tt)+ ) => { | 108 | ( $first:tt $($tail:tt)+ ) => { |
107 | { | 109 | { |
diff --git a/crates/ra_ide/src/change.rs b/crates/ra_ide/src/change.rs index 4a76d1dd8..387a9cafb 100644 --- a/crates/ra_ide/src/change.rs +++ b/crates/ra_ide/src/change.rs | |||
@@ -270,7 +270,6 @@ impl RootDatabase { | |||
270 | 270 | ||
271 | self.query(hir::db::AstIdMapQuery).sweep(sweep); | 271 | self.query(hir::db::AstIdMapQuery).sweep(sweep); |
272 | 272 | ||
273 | self.query(hir::db::RawItemsWithSourceMapQuery).sweep(sweep); | ||
274 | self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); | 273 | self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); |
275 | 274 | ||
276 | self.query(hir::db::ExprScopesQuery).sweep(sweep); | 275 | self.query(hir::db::ExprScopesQuery).sweep(sweep); |
@@ -309,7 +308,6 @@ impl RootDatabase { | |||
309 | hir::db::StructDataQuery | 308 | hir::db::StructDataQuery |
310 | hir::db::EnumDataQuery | 309 | hir::db::EnumDataQuery |
311 | hir::db::TraitDataQuery | 310 | hir::db::TraitDataQuery |
312 | hir::db::RawItemsWithSourceMapQuery | ||
313 | hir::db::RawItemsQuery | 311 | hir::db::RawItemsQuery |
314 | hir::db::CrateDefMapQuery | 312 | hir::db::CrateDefMapQuery |
315 | hir::db::GenericParamsQuery | 313 | hir::db::GenericParamsQuery |
diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs index 28f94e0a7..cc1f7c830 100644 --- a/crates/ra_ide/src/completion/complete_path.rs +++ b/crates/ra_ide/src/completion/complete_path.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use either::Either; | 3 | use hir::{Adt, PathResolution, ScopeDef}; |
4 | use hir::{Adt, HasSource, PathResolution}; | ||
5 | use ra_syntax::AstNode; | 4 | use ra_syntax::AstNode; |
6 | use test_utils::tested_by; | 5 | use test_utils::tested_by; |
7 | 6 | ||
@@ -19,17 +18,15 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
19 | match def { | 18 | match def { |
20 | hir::ModuleDef::Module(module) => { | 19 | hir::ModuleDef::Module(module) => { |
21 | let module_scope = module.scope(ctx.db); | 20 | let module_scope = module.scope(ctx.db); |
22 | for (name, def, import) in module_scope { | 21 | for (name, def) in module_scope { |
23 | if let hir::ScopeDef::ModuleDef(hir::ModuleDef::BuiltinType(..)) = def { | 22 | if ctx.use_item_syntax.is_some() { |
24 | if ctx.use_item_syntax.is_some() { | 23 | if let hir::ScopeDef::ModuleDef(hir::ModuleDef::BuiltinType(..)) = def { |
25 | tested_by!(dont_complete_primitive_in_use); | 24 | tested_by!(dont_complete_primitive_in_use); |
26 | continue; | 25 | continue; |
27 | } | 26 | } |
28 | } | 27 | if let ScopeDef::Unknown = def { |
29 | if Some(module) == ctx.module { | 28 | if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { |
30 | if let Some(import) = import { | 29 | if &name_ref.syntax().text() == name.to_string().as_str() { |
31 | if let Either::Left(use_tree) = import.source(ctx.db).value { | ||
32 | if use_tree.syntax().text_range().contains_inclusive(ctx.offset) { | ||
33 | // for `use self::foo<|>`, don't suggest `foo` as a completion | 30 | // for `use self::foo<|>`, don't suggest `foo` as a completion |
34 | tested_by!(dont_complete_current_use); | 31 | tested_by!(dont_complete_current_use); |
35 | continue; | 32 | continue; |
@@ -37,6 +34,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
37 | } | 34 | } |
38 | } | 35 | } |
39 | } | 36 | } |
37 | |||
40 | acc.add_resolution(ctx, name.to_string(), &def); | 38 | acc.add_resolution(ctx, name.to_string(), &def); |
41 | } | 39 | } |
42 | } | 40 | } |
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 4894ea2f6..48d69f7e5 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -19,6 +19,7 @@ pub(crate) struct CompletionContext<'a> { | |||
19 | pub(super) offset: TextUnit, | 19 | pub(super) offset: TextUnit, |
20 | pub(super) token: SyntaxToken, | 20 | pub(super) token: SyntaxToken, |
21 | pub(super) module: Option<hir::Module>, | 21 | pub(super) module: Option<hir::Module>, |
22 | pub(super) name_ref_syntax: Option<ast::NameRef>, | ||
22 | pub(super) function_syntax: Option<ast::FnDef>, | 23 | pub(super) function_syntax: Option<ast::FnDef>, |
23 | pub(super) use_item_syntax: Option<ast::UseItem>, | 24 | pub(super) use_item_syntax: Option<ast::UseItem>, |
24 | pub(super) record_lit_syntax: Option<ast::RecordLit>, | 25 | pub(super) record_lit_syntax: Option<ast::RecordLit>, |
@@ -69,6 +70,7 @@ impl<'a> CompletionContext<'a> { | |||
69 | token, | 70 | token, |
70 | offset: position.offset, | 71 | offset: position.offset, |
71 | module, | 72 | module, |
73 | name_ref_syntax: None, | ||
72 | function_syntax: None, | 74 | function_syntax: None, |
73 | use_item_syntax: None, | 75 | use_item_syntax: None, |
74 | record_lit_syntax: None, | 76 | record_lit_syntax: None, |
@@ -142,6 +144,8 @@ impl<'a> CompletionContext<'a> { | |||
142 | } | 144 | } |
143 | 145 | ||
144 | fn classify_name_ref(&mut self, original_file: SourceFile, name_ref: ast::NameRef) { | 146 | fn classify_name_ref(&mut self, original_file: SourceFile, name_ref: ast::NameRef) { |
147 | self.name_ref_syntax = | ||
148 | find_node_at_offset(original_file.syntax(), name_ref.syntax().text_range().start()); | ||
145 | let name_range = name_ref.syntax().text_range(); | 149 | let name_range = name_ref.syntax().text_range(); |
146 | if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() { | 150 | if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() { |
147 | self.record_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); | 151 | self.record_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); |
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 3154df457..c5e406977 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -1,12 +1,15 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use crate::{db::RootDatabase, FileId}; | ||
4 | use hir::{HirDisplay, SourceAnalyzer}; | 3 | use hir::{HirDisplay, SourceAnalyzer}; |
4 | use once_cell::unsync::Lazy; | ||
5 | use ra_prof::profile; | ||
5 | use ra_syntax::{ | 6 | use ra_syntax::{ |
6 | ast::{self, AstNode, TypeAscriptionOwner}, | 7 | ast::{self, AstNode, TypeAscriptionOwner}, |
7 | match_ast, SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange, | 8 | match_ast, SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange, |
8 | }; | 9 | }; |
9 | 10 | ||
11 | use crate::{db::RootDatabase, FileId}; | ||
12 | |||
10 | #[derive(Debug, PartialEq, Eq)] | 13 | #[derive(Debug, PartialEq, Eq)] |
11 | pub enum InlayKind { | 14 | pub enum InlayKind { |
12 | TypeHint, | 15 | TypeHint, |
@@ -27,7 +30,7 @@ pub(crate) fn inlay_hints( | |||
27 | ) -> Vec<InlayHint> { | 30 | ) -> Vec<InlayHint> { |
28 | file.syntax() | 31 | file.syntax() |
29 | .descendants() | 32 | .descendants() |
30 | .map(|node| get_inlay_hints(db, file_id, &node, max_inlay_hint_length).unwrap_or_default()) | 33 | .flat_map(|node| get_inlay_hints(db, file_id, &node, max_inlay_hint_length)) |
31 | .flatten() | 34 | .flatten() |
32 | .collect() | 35 | .collect() |
33 | } | 36 | } |
@@ -38,7 +41,9 @@ fn get_inlay_hints( | |||
38 | node: &SyntaxNode, | 41 | node: &SyntaxNode, |
39 | max_inlay_hint_length: Option<usize>, | 42 | max_inlay_hint_length: Option<usize>, |
40 | ) -> Option<Vec<InlayHint>> { | 43 | ) -> Option<Vec<InlayHint>> { |
41 | let analyzer = SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None); | 44 | let _p = profile("get_inlay_hints"); |
45 | let analyzer = | ||
46 | Lazy::new(|| SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None)); | ||
42 | match_ast! { | 47 | match_ast! { |
43 | match node { | 48 | match node { |
44 | ast::LetStmt(it) => { | 49 | ast::LetStmt(it) => { |
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index d812ff7ca..eeca67ee1 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Advertizes the capabilities of the LSP Server. |
2 | 2 | ||
3 | use lsp_types::{ | 3 | use lsp_types::{ |
4 | CodeActionProviderCapability, CodeLensOptions, CompletionOptions, | 4 | CodeActionProviderCapability, CodeLensOptions, CompletionOptions, |
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 5561f6270..e93d4ea33 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Convenience module responsible for translating between rust-analyzer's types and LSP types. |
2 | 2 | ||
3 | use lsp_types::{ | 3 | use lsp_types::{ |
4 | self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation, | 4 | self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation, |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 9e207415e..81fd08c91 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! The main loop of `ra_lsp_server` responsible for dispatching LSP requests/replies and |
2 | //! notifications back to the client. | ||
2 | 3 | ||
3 | mod handlers; | 4 | mod handlers; |
4 | mod subscriptions; | 5 | mod subscriptions; |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 5e3b1a73f..39eb3df3e 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! This module is responsible for implementing handlers for Lanuage Server Protocol. |
2 | //! The majority of requests are fulfilled by calling into the `ra_ide` crate. | ||
2 | 3 | ||
3 | use std::{fmt::Write as _, io::Write as _}; | 4 | use std::{fmt::Write as _, io::Write as _}; |
4 | 5 | ||
diff --git a/crates/ra_lsp_server/src/main_loop/pending_requests.rs b/crates/ra_lsp_server/src/main_loop/pending_requests.rs index e7ea7aa5b..2d2213464 100644 --- a/crates/ra_lsp_server/src/main_loop/pending_requests.rs +++ b/crates/ra_lsp_server/src/main_loop/pending_requests.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Datastructures that keep track of inflight requests. |
2 | 2 | ||
3 | use std::time::{Duration, Instant}; | 3 | use std::time::{Duration, Instant}; |
4 | 4 | ||
diff --git a/crates/ra_lsp_server/src/main_loop/subscriptions.rs b/crates/ra_lsp_server/src/main_loop/subscriptions.rs index 609b2adcc..b0bae90f5 100644 --- a/crates/ra_lsp_server/src/main_loop/subscriptions.rs +++ b/crates/ra_lsp_server/src/main_loop/subscriptions.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Keeps track of file subscriptions. |
2 | 2 | ||
3 | use ra_ide::FileId; | 3 | use ra_ide::FileId; |
4 | use rustc_hash::FxHashSet; | 4 | use rustc_hash::FxHashSet; |
diff --git a/crates/ra_lsp_server/src/markdown.rs b/crates/ra_lsp_server/src/markdown.rs index f51fc4ade..76bef45cc 100644 --- a/crates/ra_lsp_server/src/markdown.rs +++ b/crates/ra_lsp_server/src/markdown.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Transforms markdown |
2 | 2 | ||
3 | pub(crate) fn format_docs(src: &str) -> String { | 3 | pub(crate) fn format_docs(src: &str) -> String { |
4 | let mut processed_lines = Vec::new(); | 4 | let mut processed_lines = Vec::new(); |
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 2a22b655c..b34e6f9b8 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Defines `rust-analyzer` specific custom messages. |
2 | 2 | ||
3 | use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url}; | 3 | use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url}; |
4 | use rustc_hash::FxHashMap; | 4 | use rustc_hash::FxHashMap; |
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index f89b23089..5e53b0278 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs | |||
@@ -1,4 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! The context or environment in which the language server functions. |
2 | //! In our server implementation this is know as the `WorldState`. | ||
3 | //! | ||
4 | //! Each tick provides an immutable snapshot of the state as `WorldSnapshot`. | ||
2 | 5 | ||
3 | use std::{ | 6 | use std::{ |
4 | path::{Path, PathBuf}, | 7 | path::{Path, PathBuf}, |
diff --git a/crates/ra_parser/src/grammar/type_params.rs b/crates/ra_parser/src/grammar/type_params.rs index 34406b5bd..50e4900c3 100644 --- a/crates/ra_parser/src/grammar/type_params.rs +++ b/crates/ra_parser/src/grammar/type_params.rs | |||
@@ -25,6 +25,7 @@ fn type_param_list(p: &mut Parser) { | |||
25 | match p.current() { | 25 | match p.current() { |
26 | LIFETIME => lifetime_param(p, m), | 26 | LIFETIME => lifetime_param(p, m), |
27 | IDENT => type_param(p, m), | 27 | IDENT => type_param(p, m), |
28 | CONST_KW => type_const_param(p, m), | ||
28 | _ => { | 29 | _ => { |
29 | m.abandon(p); | 30 | m.abandon(p); |
30 | p.err_and_bump("expected type parameter") | 31 | p.err_and_bump("expected type parameter") |
@@ -62,6 +63,16 @@ fn type_param(p: &mut Parser, m: Marker) { | |||
62 | m.complete(p, TYPE_PARAM); | 63 | m.complete(p, TYPE_PARAM); |
63 | } | 64 | } |
64 | 65 | ||
66 | // test const_param | ||
67 | // struct S<const N: u32>; | ||
68 | fn type_const_param(p: &mut Parser, m: Marker) { | ||
69 | assert!(p.at(CONST_KW)); | ||
70 | p.bump(T![const]); | ||
71 | name(p); | ||
72 | types::ascription(p); | ||
73 | m.complete(p, CONST_PARAM); | ||
74 | } | ||
75 | |||
65 | // test type_param_bounds | 76 | // test type_param_bounds |
66 | // struct S<T: 'a + ?Sized + (Copy)>; | 77 | // struct S<T: 'a + ?Sized + (Copy)>; |
67 | pub(super) fn bounds(p: &mut Parser) { | 78 | pub(super) fn bounds(p: &mut Parser) { |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index afe4ce51a..af2945f57 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -229,6 +229,7 @@ pub enum SyntaxKind { | |||
229 | TYPE_PARAM_LIST, | 229 | TYPE_PARAM_LIST, |
230 | LIFETIME_PARAM, | 230 | LIFETIME_PARAM, |
231 | TYPE_PARAM, | 231 | TYPE_PARAM, |
232 | CONST_PARAM, | ||
232 | TYPE_ARG_LIST, | 233 | TYPE_ARG_LIST, |
233 | LIFETIME_ARG, | 234 | LIFETIME_ARG, |
234 | TYPE_ARG, | 235 | TYPE_ARG, |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 8d65e2e08..9f9d6e63c 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -551,6 +551,36 @@ impl ConstDef { | |||
551 | } | 551 | } |
552 | } | 552 | } |
553 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 553 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
554 | pub struct ConstParam { | ||
555 | pub(crate) syntax: SyntaxNode, | ||
556 | } | ||
557 | impl AstNode for ConstParam { | ||
558 | fn can_cast(kind: SyntaxKind) -> bool { | ||
559 | match kind { | ||
560 | CONST_PARAM => true, | ||
561 | _ => false, | ||
562 | } | ||
563 | } | ||
564 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
565 | if Self::can_cast(syntax.kind()) { | ||
566 | Some(Self { syntax }) | ||
567 | } else { | ||
568 | None | ||
569 | } | ||
570 | } | ||
571 | fn syntax(&self) -> &SyntaxNode { | ||
572 | &self.syntax | ||
573 | } | ||
574 | } | ||
575 | impl ast::NameOwner for ConstParam {} | ||
576 | impl ast::AttrsOwner for ConstParam {} | ||
577 | impl ast::TypeAscriptionOwner for ConstParam {} | ||
578 | impl ConstParam { | ||
579 | pub fn default_val(&self) -> Option<Expr> { | ||
580 | AstChildren::new(&self.syntax).next() | ||
581 | } | ||
582 | } | ||
583 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
554 | pub struct ContinueExpr { | 584 | pub struct ContinueExpr { |
555 | pub(crate) syntax: SyntaxNode, | 585 | pub(crate) syntax: SyntaxNode, |
556 | } | 586 | } |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 3f1cd0b90..08aafb610 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -245,6 +245,7 @@ Grammar( | |||
245 | "TYPE_PARAM_LIST", | 245 | "TYPE_PARAM_LIST", |
246 | "LIFETIME_PARAM", | 246 | "LIFETIME_PARAM", |
247 | "TYPE_PARAM", | 247 | "TYPE_PARAM", |
248 | "CONST_PARAM", | ||
248 | "TYPE_ARG_LIST", | 249 | "TYPE_ARG_LIST", |
249 | "LIFETIME_ARG", | 250 | "LIFETIME_ARG", |
250 | "TYPE_ARG", | 251 | "TYPE_ARG", |
@@ -604,6 +605,10 @@ Grammar( | |||
604 | options: [("default_type", "TypeRef")], | 605 | options: [("default_type", "TypeRef")], |
605 | traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner"], | 606 | traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner"], |
606 | ), | 607 | ), |
608 | "ConstParam": ( | ||
609 | options: [("default_val", "Expr")], | ||
610 | traits: ["NameOwner", "AttrsOwner", "TypeAscriptionOwner"], | ||
611 | ), | ||
607 | "LifetimeParam": ( | 612 | "LifetimeParam": ( |
608 | traits: ["AttrsOwner"], | 613 | traits: ["AttrsOwner"], |
609 | ), | 614 | ), |
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.rs b/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.rs new file mode 100644 index 000000000..8cdb3b703 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.rs | |||
@@ -0,0 +1 @@ | |||
struct S<const N: u32>; | |||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.txt b/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.txt new file mode 100644 index 000000000..f81de7bac --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0147_const_param.txt | |||
@@ -0,0 +1,23 @@ | |||
1 | SOURCE_FILE@[0; 24) | ||
2 | STRUCT_DEF@[0; 23) | ||
3 | STRUCT_KW@[0; 6) "struct" | ||
4 | WHITESPACE@[6; 7) " " | ||
5 | NAME@[7; 8) | ||
6 | IDENT@[7; 8) "S" | ||
7 | TYPE_PARAM_LIST@[8; 22) | ||
8 | L_ANGLE@[8; 9) "<" | ||
9 | CONST_PARAM@[9; 21) | ||
10 | CONST_KW@[9; 14) "const" | ||
11 | WHITESPACE@[14; 15) " " | ||
12 | NAME@[15; 16) | ||
13 | IDENT@[15; 16) "N" | ||
14 | COLON@[16; 17) ":" | ||
15 | WHITESPACE@[17; 18) " " | ||
16 | PATH_TYPE@[18; 21) | ||
17 | PATH@[18; 21) | ||
18 | PATH_SEGMENT@[18; 21) | ||
19 | NAME_REF@[18; 21) | ||
20 | IDENT@[18; 21) "u32" | ||
21 | R_ANGLE@[21; 22) ">" | ||
22 | SEMI@[22; 23) ";" | ||
23 | WHITESPACE@[23; 24) "\n" | ||