Fix a panic when diagnostics contain multiple links (#16601)

Follow up from #14518

Release Notes:

- Fixed a panic when diagnostics contain multiple links
This commit is contained in:
Conrad Irwin 2024-08-21 11:18:43 -06:00 committed by GitHub
parent 8a5fcc2c22
commit 09c698d8d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 3 deletions

View file

@ -96,8 +96,8 @@ pub fn parse_links_only(text: &str) -> Vec<(Range<usize>, MarkdownEvent)> {
start: 0,
end: text.len(),
};
for link in finder.links(&text[text_range.clone()]) {
let link_range = text_range.start + link.start()..text_range.start + link.end();
for link in finder.links(&text) {
let link_range = link.start()..link.end();
if link_range.start > text_range.start {
events.push((text_range.start..link_range.start, MarkdownEvent::Text));
@ -118,7 +118,9 @@ pub fn parse_links_only(text: &str) -> Vec<(Range<usize>, MarkdownEvent)> {
text_range.start = link_range.end;
}
events.push((text_range, MarkdownEvent::Text));
if text_range.end > text_range.start {
events.push((text_range, MarkdownEvent::Text));
}
events
}