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:
parent
ca9cee85e1
commit
9b2bc458e3
11 changed files with 284 additions and 43 deletions
|
@ -39,6 +39,7 @@ smallvec.workspace = true
|
|||
sum_tree.workspace = true
|
||||
text.workspace = true
|
||||
theme.workspace = true
|
||||
tree-sitter.workspace = true
|
||||
util.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -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>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue