Skip to content

Commit

Permalink
fix: set link for first uncovered line
Browse files Browse the repository at this point in the history
A link tag existed that should move to the first uncovered line in
source view, but it never contained a proper working URL.

Also, the link won't be generated anymore if there aren't any uncovered
lines in the file.
  • Loading branch information
dnaka91 committed Oct 6, 2023
1 parent 86cd5c7 commit 481434a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ pub struct Source<'a> {
}

impl<'a> Source<'a> {
fn get_first(&self) -> Option<usize> {
(1..=self.lines.len())
.find(|line| matches!(self.get_coverage(line), Coverage::Uncovered(_)))
}

fn get_coverage(&self, index: &usize) -> Coverage {
self.info
.covered
Expand Down
6 changes: 5 additions & 1 deletion templates/source.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
<tr>
<th>Line</th>
<th>Count</th>
<th>Source (<a>jump to first uncovered line</a>)</th>
<th>Source
{%- if let Some(line) = self.get_first() %}
(<a href="#L{{line}}">jump to first uncovered line</a>)
{% endif -%}
</th>
</tr>
</thead>
<tbody class="syntect-code">
Expand Down

0 comments on commit 481434a

Please sign in to comment.