Expand diagnostic excerpts using heuristics on syntactic information from TreeSitter (#21942)
This is quite experimental and untested in languages other than Rust. It's written to attempt to do something sensible in many languages. Due to its experimental nature, just releasing to staff, and so not including it in release notes. Future release note might be "Improved diagnostic excerpts by using syntactic info to determine the context lines to show." Release Notes: - N/A
This commit is contained in:
@@ -3920,15 +3920,16 @@ impl MultiBufferSnapshot {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn range_for_syntax_ancestor<T: ToOffset>(&self, range: Range<T>) -> Option<Range<usize>> {
|
||||
pub fn syntax_ancestor<T: ToOffset>(
|
||||
&self,
|
||||
range: Range<T>,
|
||||
) -> Option<(tree_sitter::Node, Range<usize>)> {
|
||||
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||
let excerpt = self.excerpt_containing(range.clone())?;
|
||||
|
||||
let ancestor_buffer_range = excerpt
|
||||
let node = excerpt
|
||||
.buffer()
|
||||
.range_for_syntax_ancestor(excerpt.map_range_to_buffer(range))?;
|
||||
|
||||
Some(excerpt.map_range_from_buffer(ancestor_buffer_range))
|
||||
.syntax_ancestor(excerpt.map_range_to_buffer(range))?;
|
||||
Some((node, excerpt.map_range_from_buffer(node.byte_range())))
|
||||
}
|
||||
|
||||
pub fn outline(&self, theme: Option<&SyntaxTheme>) -> Option<Outline<Anchor>> {
|
||||
|
||||
Reference in New Issue
Block a user