sourcegraph/client/codeintellify/src
Felix Kling db3e905242
Migrate deprecated rxjs functions/methods (#61222)
As a follow up to https://github.com/sourcegraph/sourcegraph/pull/61122 this commit updates the deprecated methods with the suggested replacements.

**Note**

This only migrates functions/methods that are replaced with something else, or whose deprecated call signature can easily be identified (e.g. `throwError(error)` -> `throwError(() => error)`). It's possible that there are more functions which deprecate a specific signature that we are using. I'll migrate those as I encounter them.

**Notes about `.toPromise`**

The instances of `.toPromise` converted here are all instances where the updated return value of `Promise<X|undefined>` did not produce a TS error (the ones with errors have been converted in #61122). However that doesn't mean that they can simply be replaced with `firstValueFrom`, `lastValueFrom` (these two methods throw errors when the source observable hasn't emitted a value before closing).
I update the callsites under two assumptions:
- Callsites that involve GraphQL requests will always emit a value and thus can be converted to using `lastValueFrom`/`firstValueFrom`.
- For other callsites we cannot make the assumption that the source observable emits before closing and thus they need a default value.
2024-04-08 11:23:34 +02:00
..
testutils web: Update rxjs to v7 (#61122) 2024-03-18 14:02:57 +01:00
typings refactor: extract codeintellify as new package (#29233) 2022-01-10 22:29:47 +07:00
helpers.ts web: Update rxjs to v7 (#61122) 2024-03-18 14:02:57 +01:00
hoverifier.test.ts Migrate deprecated rxjs functions/methods (#61222) 2024-04-08 11:23:34 +02:00
hoverifier.ts Migrate deprecated rxjs functions/methods (#61222) 2024-04-08 11:23:34 +02:00
index.ts refactor: extract codeintellify as new package (#29233) 2022-01-10 22:29:47 +07:00
loading.test.ts reapply "switch from jest to vitest for faster, simpler tests (#57886)" (#58145) 2023-11-07 12:00:18 +02:00
loading.ts Migrate deprecated rxjs functions/methods (#61222) 2024-04-08 11:23:34 +02:00
overlayPosition.test.ts reapply "switch from jest to vitest for faster, simpler tests (#57886)" (#58145) 2023-11-07 12:00:18 +02:00
overlayPosition.ts disable slow eslint rules, remove unused disable directives (#57788) 2023-10-23 13:23:44 -07:00
positions.test.ts reapply "switch from jest to vitest for faster, simpler tests (#57886)" (#58145) 2023-11-07 12:00:18 +02:00
positions.ts web: Update rxjs to v7 (#61122) 2024-03-18 14:02:57 +01:00
README.md refactor: extract codeintellify as new package (#29233) 2022-01-10 22:29:47 +07:00
state.ts Eslint fix type imports (#54920) 2023-08-10 21:12:31 +02:00
testSetup.test.ts reapply "switch from jest to vitest for faster, simpler tests (#57886)" (#58145) 2023-11-07 12:00:18 +02:00
tokenPosition.test.ts reapply "switch from jest to vitest for faster, simpler tests (#57886)" (#58145) 2023-11-07 12:00:18 +02:00
tokenPosition.ts Eslint fix type imports (#54920) 2023-08-10 21:12:31 +02:00
types.ts Eslint fix type imports (#54920) 2023-08-10 21:12:31 +02:00

CodeIntellify

This library manages all of the inputs (mouse/keyboard events, location changes, hover information, and hover actions) necessary to display hover tooltips on with a code view. All together, this makes it easier to add code intelligence to code views on the web. Used in Sourcegraph.

What it does

  • Listens to hover and click events on the code view
  • On mouse hovers, determines the line+column position, performs a hover request, and renders it in a nice tooltip overlay at the token
  • Shows actions in the hover
  • When clicking a token, pins the tooltip to that token
  • Highlights the hovered token

You need to provide your own UI component (referred to as the HoverOverlay) that actually displays this information and exposes these actions to the user.

Usage

  • Call createHoverifier() to create a Hoverifier object (there should only be one on the page, to have only one HoverOverlay shown).
  • The Hoverifier exposes an Observable hoverStateUpdates that a consumer can subscribe to, which emits all data needed to render the HoverOverlay
  • For each code view on the page, call hoverifier.hoverify(), passing the position events coming from findPositionsFromEvents().
  • hoverify() returns a Subscription that will "unhoverify" the code view again if unsubscribed from

Glossary

Term Definition
Code view The DOM element that contains all the line elements
Line number element The DOM element that contains the line number label for that line
Code element The DOM element that contains the code for one line
Diff part The part of the diff, either base, head or both (if the line didn't change). Each line belongs to one diff part, and therefor to a different commit ID and potentially different file path.
Hover overlay Also called tooltip
hoverify To attach all the listeners needed to a code view so that it will display overlay on hovers and clicks.
unhoverify To unsubscribe from the Subscription returned by hoverifier.hoverify(). Removes all event listeners from the code view again and hides the hover overlay if it was triggered by the unhoverified code view.