aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-05-23 21:31:59 +0100
committerAleksey Kladov <[email protected]>2021-05-25 15:49:59 +0100
commit5c9f31d4c28478b4373e6cf5ec155745c840ee3f (patch)
tree6d105121d271c7532170875feafaadcd7ad500ba /crates/hir_expand/src/lib.rs
parentb7414fa14a85f4acd37b5bdfdc2a4ab97a072bd2 (diff)
internal: move diagnostics to hir
The idea here is to eventually get rid of `dyn Diagnostic` and `DiagnosticSink` infrastructure altogether, and just have a `enum hir::Diagnostic` instead. The problem with `dyn Diagnostic` is that it is defined in the lowest level of the stack (hir_expand), but is used by the highest level (ide). As a first step, we free hir_expand and hir_def from `dyn Diagnostic` and kick the can up to `hir_ty`, as an intermediate state. The plan is then to move DiagnosticSink similarly to the hir crate, and, as final third step, remove its usage from the ide. One currently unsolved problem is testing. You can notice that the test which checks precise diagnostic ranges, unresolved_import_in_use_tree, was moved to the ide layer. Logically, only IDE should have the infra to render a specific range. At the same time, the range is determined with the data produced in hir_def and hir crates, so this layering is rather unfortunate. Working on hir_def shouldn't require compiling `ide` for testing.
Diffstat (limited to 'crates/hir_expand/src/lib.rs')
-rw-r--r--crates/hir_expand/src/lib.rs7
1 files changed, 3 insertions, 4 deletions
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 6be4516a3..10d37234e 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -8,7 +8,6 @@ pub mod db;
8pub mod ast_id_map; 8pub mod ast_id_map;
9pub mod name; 9pub mod name;
10pub mod hygiene; 10pub mod hygiene;
11pub mod diagnostics;
12pub mod builtin_derive; 11pub mod builtin_derive;
13pub mod builtin_macro; 12pub mod builtin_macro;
14pub mod proc_macro; 13pub mod proc_macro;
@@ -108,7 +107,7 @@ impl HirFileId {
108 HirFileIdRepr::FileId(_) => None, 107 HirFileIdRepr::FileId(_) => None,
109 HirFileIdRepr::MacroFile(macro_file) => { 108 HirFileIdRepr::MacroFile(macro_file) => {
110 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id); 109 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
111 Some(loc.kind.node(db)) 110 Some(loc.kind.to_node(db))
112 } 111 }
113 } 112 }
114 } 113 }
@@ -153,7 +152,7 @@ impl HirFileId {
153 HirFileIdRepr::MacroFile(macro_file) => { 152 HirFileIdRepr::MacroFile(macro_file) => {
154 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id); 153 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
155 let item = match loc.def.kind { 154 let item = match loc.def.kind {
156 MacroDefKind::BuiltInDerive(..) => loc.kind.node(db), 155 MacroDefKind::BuiltInDerive(..) => loc.kind.to_node(db),
157 _ => return None, 156 _ => return None,
158 }; 157 };
159 Some(item.with_value(ast::Item::cast(item.value.clone())?)) 158 Some(item.with_value(ast::Item::cast(item.value.clone())?))
@@ -269,7 +268,7 @@ impl MacroCallKind {
269 } 268 }
270 } 269 }
271 270
272 fn node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> { 271 pub fn to_node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> {
273 match self { 272 match self {
274 MacroCallKind::FnLike { ast_id, .. } => { 273 MacroCallKind::FnLike { ast_id, .. } => {
275 ast_id.with_value(ast_id.to_node(db).syntax().clone()) 274 ast_id.with_value(ast_id.to_node(db).syntax().clone())