mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 18:51:59 +00:00
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. |
||
|---|---|---|
| .. | ||
| testutils | ||
| typings | ||
| helpers.ts | ||
| hoverifier.test.ts | ||
| hoverifier.ts | ||
| index.ts | ||
| loading.test.ts | ||
| loading.ts | ||
| overlayPosition.test.ts | ||
| overlayPosition.ts | ||
| positions.test.ts | ||
| positions.ts | ||
| README.md | ||
| state.ts | ||
| testSetup.test.ts | ||
| tokenPosition.test.ts | ||
| tokenPosition.ts | ||
| types.ts | ||
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 aHoverifierobject (there should only be one on the page, to have only one HoverOverlay shown). - The Hoverifier exposes an Observable
hoverStateUpdatesthat 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 fromfindPositionsFromEvents(). hoverify()returns aSubscriptionthat 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. |