aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-08-08 23:59:26 +0100
committerKirill Bulatov <[email protected]>2020-08-11 13:09:08 +0100
commit9963f43d51071ea02f8f6d490b9c49882034b42c (patch)
tree7ecdbbd66fb8c988989e6de17c77ab14262589c0 /crates/ra_hir/src
parentcfbbd91a886e2394e7411f9d7f4966dcbd454764 (diff)
Refactor the diagnostics
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/semantics.rs28
1 files changed, 10 insertions, 18 deletions
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 1c5dc3d51..b4420d378 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -109,11 +109,14 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
109 self.imp.parse(file_id) 109 self.imp.parse(file_id)
110 } 110 }
111 111
112 pub fn ast<T: AstDiagnostic + Diagnostic>(&self, d: &T) -> <T as AstDiagnostic>::AST { 112 pub fn diagnostic_fix_source<T: AstDiagnostic + Diagnostic>(
113 let file_id = d.source().file_id; 113 &self,
114 d: &T,
115 ) -> <T as AstDiagnostic>::AST {
116 let file_id = d.presentation().file_id;
114 let root = self.db.parse_or_expand(file_id).unwrap(); 117 let root = self.db.parse_or_expand(file_id).unwrap();
115 self.imp.cache(root, file_id); 118 self.imp.cache(root, file_id);
116 d.ast(self.db.upcast()) 119 d.fix_source(self.db.upcast())
117 } 120 }
118 121
119 pub fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> { 122 pub fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> {
@@ -145,12 +148,8 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
145 self.imp.original_range(node) 148 self.imp.original_range(node)
146 } 149 }
147 150
148 pub fn diagnostics_fix_range(&self, diagnostics: &dyn Diagnostic) -> FileRange { 151 pub fn diagnostics_presentation_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
149 self.imp.diagnostics_fix_range(diagnostics) 152 self.imp.diagnostics_presentation_range(diagnostics)
150 }
151
152 pub fn diagnostics_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
153 self.imp.diagnostics_range(diagnostics)
154 } 153 }
155 154
156 pub fn ancestors_with_macros(&self, node: SyntaxNode) -> impl Iterator<Item = SyntaxNode> + '_ { 155 pub fn ancestors_with_macros(&self, node: SyntaxNode) -> impl Iterator<Item = SyntaxNode> + '_ {
@@ -380,15 +379,8 @@ impl<'db> SemanticsImpl<'db> {
380 original_range(self.db, node.as_ref()) 379 original_range(self.db, node.as_ref())
381 } 380 }
382 381
383 fn diagnostics_fix_range(&self, diagnostics: &dyn Diagnostic) -> FileRange { 382 fn diagnostics_presentation_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
384 let src = diagnostics.fix_source(); 383 let src = diagnostics.presentation();
385 let root = self.db.parse_or_expand(src.file_id).unwrap();
386 let node = src.value.to_node(&root);
387 original_range(self.db, src.with_value(&node))
388 }
389
390 fn diagnostics_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
391 let src = diagnostics.source();
392 let root = self.db.parse_or_expand(src.file_id).unwrap(); 384 let root = self.db.parse_or_expand(src.file_id).unwrap();
393 let node = src.value.to_node(&root); 385 let node = src.value.to_node(&root);
394 original_range(self.db, src.with_value(&node)) 386 original_range(self.db, src.with_value(&node))