Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

blob: Refactor blame decorations #58042

Merged
fkling merged 5 commits into
mainfrom
fkling/blame-decorations
Nov 2, 2023
Merged

blob: Refactor blame decorations #58042
fkling merged 5 commits into
mainfrom
fkling/blame-decorations

Conversation

@fkling

@fkling fkling commented Nov 1, 2023

Copy link
Copy Markdown
Contributor

This commit refactors blame decorations to be more configuration driven. Specific changes and fixes:

  • Fixed "lock first line" behavior. It think this was because the lock line behavior was triggered multiple times due to data loading. Separating showing the column and showing the data seems to fix this.
  • Wrong (no) blame decoration shown after a folded range. This was an interesting issue. The root issue was that the blame decoration component would only render something when it was shown in its start line. But when a range is folded that start line might be hidden. Removing this condition together with other changes fixes this issue.
  • Previously every line was rendering a blame decoration component, but for most lines the component wouldn't display anything. Even without displaying anything, creating a react root per line contributed to unnecessary overhead.
    The implementation was changed to only render the a decoration in the first (visible) line of the hunk. In order to still show the recency indicator across all
    lines it is moved into its own gutter and rendered directly via the DOM.
  • Recency colors have been refactored to avoid having to use useIsLightTheme.
  • BlameColumn wasn't used anymore and could be removed which also allowed changes to the BlameDecoration component itself.
  • Instead of just highlighting the line when hovering over the blame information the whole hunk is highlighted. It should be possible to highlight the whole hunk when hovering anywhere in the blame column, but due to how we implement it (widget decorations) it would require some more work.

Additional notes:

  • Using React for this, even with fewer occurrences, still has some performance penalty. This becomes apparent when scrolling in a larger document with blame enabled, and hovering over blame information. The more often this is done the slower the blame decorations seem to react (ha!) to hover events (to be fair, I assume it's due to React, it could also be for other reasons)
  • Scenario: Hunk 1/Commit A | Hunk 2/Commit B | Hunk 3/Commit A
    If code is folded so that Hunk 2 is completely hidden, it would be nice if we only displayed Hunk 1/Commit A instead of Hunk 1/Commit A | Hunk 3/Commit A. That's actually relatively easy to do but getting the new "highlight hunk lines" to work properly then is more difficult.

Test plan

Manual testing:

sg-blame-changes-final.mp4

@fkling fkling added the team/code-search Issues owned by the code search team label Nov 1, 2023
@fkling fkling requested review from a team, philipp-spiess and taras-yemets November 1, 2023 13:12
@cla-bot cla-bot Bot added the cla-signed label Nov 1, 2023

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.

Most of this is copied from blameRecency.tsx.

@sourcegraph-bot

sourcegraph-bot commented Nov 1, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in OWNERS files for diff a0c1aae...82a1bd2.

Notify File(s)
@sourcegraph/code-exploration-devs client/wildcard/src/global-styles/colors.scss
@vovakulikov client/wildcard/src/global-styles/colors.scss

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.

Optional effects was added to useCompartment to support the 'lock first line' use case.

@sourcegraph-bot

sourcegraph-bot commented Nov 1, 2023

Copy link
Copy Markdown
Contributor

📖 Storybook live preview

@fkling fkling force-pushed the fkling/blame-decorations branch from 6fd447c to a6d4093 Compare November 1, 2023 13:20

@taras-yemets taras-yemets 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.

Great work, @fkling! Thank you!

On the demo video (sec 20-21) the version on the right (with current PR changes) has slightly misaligned background colors on hover. Is it fixed in the final version?

@fkling

fkling commented Nov 1, 2023

Copy link
Copy Markdown
Contributor Author

@taras-yemets That's also an issue in the current version. It happens when selecting an empty line and is somehow related to us using a layer to mark selected lines. I haven't figured out how to fix that yet.

@fkling fkling enabled auto-merge (squash) November 1, 2023 19:55

@camdencheek camdencheek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I at least read through this PR to try to get a feel for things, but I don't really know enough to provide any valuable feedback. Looks good though 😄

Comment on lines 29 to 31

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't want a scale that is too sensible 😄

@fkling fkling Nov 1, 2023

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.

In my defense that's copy and paste :D

This commit refactors blame decorations to be more configuration driven
and to fix the following issues:

- Not working "lock first line" behavior
- Wrong (no) blame decoration shown after a folded range

The implementation is changed to only render a React node in a line
where we actually show a decoration. This should slighlty improve
performance. In order to still show the recency indicator across all
lines it is moved into its own gutter and rendered directly via the DOM.

Recency colors have been refactored to avoid having to use
`useIsLightTheme`.

`BlameColumn` wasn't used anymore and could be removed which also
allowed changes to the BlameDecoration` itself.
@fkling fkling force-pushed the fkling/blame-decorations branch from fc83317 to 02f13cc Compare November 1, 2023 21:18
@fkling fkling force-pushed the fkling/blame-decorations branch from 9497a44 to 82a1bd2 Compare November 2, 2023 07:45
@fkling fkling merged commit 493c59e into main Nov 2, 2023
@fkling fkling deleted the fkling/blame-decorations branch November 2, 2023 07:51
vovakulikov pushed a commit that referenced this pull request Dec 12, 2023
This commit refactors blame decorations to be more configuration driven. Specific changes and fixes:

- Fixed "lock first line" behavior. It think this was because the lock line behavior was triggered multiple times due to data loading. Separating showing the column and showing the data seems to fix this.
- Wrong (no) blame decoration shown after a folded range. This was an interesting issue. The root issue was that the blame decoration component would only render something when it was shown in its start line. But when a range is folded that start line might be hidden. Removing this condition together with other changes fixes this issue.
- Previously every line was rendering a blame decoration component, but for most lines the component wouldn't display anything. Even without displaying anything, creating a react root per line contributed to unnecessary overhead.
  The implementation was changed to only render the a decoration in the first (visible) line of the hunk. In order to still show the recency indicator across all
lines it is moved into its own gutter and rendered directly via the DOM.
- Recency colors have been refactored to avoid having to use `useIsLightTheme`.
- `BlameColumn` wasn't used anymore and could be removed which also allowed changes to the `BlameDecoration` component itself.
- Instead of just highlighting the line when hovering over the blame information the whole hunk is highlighted. It should be possible to highlight the whole hunk when hovering anywhere in the blame column, but due to how we implement it (widget decorations) it would require some more work.

Additional notes:
- Using React for this, even with fewer occurrences, still has some performance penalty. This becomes apparent when scrolling in a larger document with blame enabled, and hovering over blame information. The more often this is done the slower the blame decorations seem to react (ha!) to hover events (to be fair, I assume it's due to React, it could also be for other reasons)
- Scenario: `Hunk 1/Commit A | Hunk 2/Commit B | Hunk 3/Commit A`
  If code is folded so that Hunk 2 is completely hidden, it would be nice if we only displayed `Hunk 1/Commit A` instead of `Hunk 1/Commit A | Hunk 3/Commit A`. That's actually relatively easy to do but getting the new "highlight hunk lines" to work properly then is more difficult.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/code-search Issues owned by the code search team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants