mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-11 04:36:24 +00:00
Fix off-by-one highlighting in hover tooltip
rust analyzer has a tendency to return markdown of the form: ```rust // <-- note the leading space blah blah blah ``` This is clearly defectuous, so we used to .trim() the output. Unfortunately we trim after applying syntax highlighting, so that causes the output to look goofy. Fix this by updating the highlighting when we trim.
This commit is contained in:
parent
43c21925ac
commit
98d514f5bf
1 changed files with 21 additions and 0 deletions
|
@ -394,6 +394,27 @@ async fn parse_blocks(
|
|||
}
|
||||
}
|
||||
|
||||
let leading_space = text.chars().take_while(|c| c.is_whitespace()).count();
|
||||
if leading_space > 0 {
|
||||
highlights = highlights
|
||||
.into_iter()
|
||||
.map(|(range, style)| {
|
||||
(
|
||||
range.start.saturating_sub(leading_space)
|
||||
..range.end.saturating_sub(leading_space),
|
||||
style,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
region_ranges = region_ranges
|
||||
.into_iter()
|
||||
.map(|range| {
|
||||
range.start.saturating_sub(leading_space)
|
||||
..range.end.saturating_sub(leading_space),
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
|
||||
ParsedMarkdown {
|
||||
text: text.trim().to_string(),
|
||||
highlights,
|
||||
|
|
Loading…
Reference in a new issue