Correctly highlight ranges of diagnostics from macros

closes #2799
This commit is contained in:
Aleksey Kladov 2020-04-17 13:06:02 +02:00
parent 302bf97bbf
commit a8196ffe84
5 changed files with 89 additions and 21 deletions

View file

@ -20,6 +20,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
use crate::{
db::HirDatabase,
diagnostics::Diagnostic,
semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
source_analyzer::{resolve_hir_path, SourceAnalyzer},
AssocItem, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef, Name,
@ -126,6 +127,13 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
original_range(self.db, node.as_ref())
}
pub fn diagnostics_range(&self, diagnostics: &dyn Diagnostic) -> FileRange {
let src = diagnostics.source();
let root = self.db.parse_or_expand(src.file_id).unwrap();
let node = src.value.to_node(&root);
original_range(self.db, src.with_value(&node))
}
pub fn ancestors_with_macros(&self, node: SyntaxNode) -> impl Iterator<Item = SyntaxNode> + '_ {
let node = self.find_file(node);
node.ancestors_with_macros(self.db).map(|it| it.value)