Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

feat: support highlighting tokens by range - #331

Merged
tjkandala merged 2 commits into
masterfrom
get-element-range
Nov 16, 2020
Merged

tjkandala merged 2 commits into
masterfrom
get-element-range

Conversation

@tjkandala

Copy link
Copy Markdown
Contributor

Closes #224

Find and highlight tokens by range, not just position.

Limitations:

  • start and end position must be on the same line
  • Highlight class will be applied to all elements within the range
@tjkandala
tjkandala requested review from a team, felixfbecker and marekweb and removed request for a team November 9, 2020 07:18
@codecov

codecov Bot commented Nov 9, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #331 (c3972ae) into master (5a0a826) will increase coverage by 0.22%.
The diff coverage is 91.52%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #331      +/-   ##
==========================================
+ Coverage   85.64%   85.86%   +0.22%     
==========================================
  Files          14       14              
  Lines         620      651      +31     
  Branches      158      174      +16     
==========================================
+ Hits          531      559      +28     
- Misses         89       92       +3     
Impacted Files Coverage Δ
src/hoverifier.ts 85.65% <75.00%> (-0.13%) ⬇️
src/token_position.ts 91.80% <92.72%> (-0.20%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a0a826...c3972ae. Read the comment docs.

@felixfbecker felixfbecker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Codecov shows there are a couple of branches in the new code never hit by tests (decreasing coverage). Are they testable?

Comment thread src/hoverifier.ts Resolved
Comment thread src/token_position.ts
break
let startNode: Node
let endNode: Node
if (typeof offsetEnd === 'number' && offsetEnd > offsetStart) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: why do ranges and positions need to be handled in completely separate branches?

@tjkandala tjkandala Nov 11, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not much overlap between these branches. When findElementWithOffset is called with a Position, we should look forwards and backwards to find all elements the token at that position is comprised of. When it's called with a Range we assume that the position boundaries are intentional (i.e. that the user either already knows the start and end positions of the token, or doesn't want to highlight a discrete token)

@tjkandala

Copy link
Copy Markdown
Contributor Author

I don't see much new logic that's untested:

  • The case where getCodeElementFromLineNumber returns undefined wasn't tested before, but is now duplicated due to branching on positionOrRange, which adds an "untested" line.
  • The case where isFirstCharacterDiffIndicator is provided and returns true for the code element wasn't tested before, but is now duplicated due to branching on positionOrRange, which adds an "untested" line.
  • The whole hoverOverlayRerenders subscription is untested.

I'll add tests for invalid ranges. Should we also test the previously untested cases?

@felixfbecker felixfbecker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marekweb could you review too?

@tjkandala
tjkandala merged commit 67d30ee into master Nov 16, 2020
@tjkandala
tjkandala deleted the get-element-range branch November 16, 2020 23:45
@sourcegraph-bot

Copy link
Copy Markdown

🎉 This PR is included in version 7.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

3 participants