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

Commit bf778c4

Browse files
committed
docs: add documentation
1 parent 752a696 commit bf778c4

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

README.md

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,50 @@
77

88
> Adds code intelligence to code views on the web
99
10-
## API
10+
## What it does
1111

12-
Use in React TODO
12+
- Listens to hover and click events on the code view
13+
- On mouse hovers, determines the line+column position, does an LSP hover request and renders it in a nice tooltip overlay at the token
14+
- Shows buttons for go-to-definition, find-references, find-implementations
15+
- When clicking a token, pins the tooltip to that token
16+
- Highlights the hovered token
1317

14-
Use with native DOM TODO
18+
## Usage
19+
20+
- Call `createHoverifier()` to create a `Hoverifier` object (there should only be one on the page, to have only one HoverOverlay shown).
21+
- The Hoverifier exposes an Observable `hoverStateUpdates` that a consumer can subscribe to, which emits all data needed to render the `HoverOverlay` React component.
22+
- For each code view on the page, call `hoverifier.hoverify()`, passing the position events coming from `findPositionsFromEvents()`.
23+
- `hoverify()` returns a `Subscription` that will "unhoverify" the code view again if unsubscribed from
1524

1625
## Development
1726

18-
```shell
19-
npm i
27+
```sh
28+
npm install
2029
npm test
30+
31+
# Helpful options:
32+
npm test -- --single-run # Don't rerun on changes
33+
npm test -- --browsers Chrome # Only run in Chrome
2134
```
2235

2336
Development is done by running tests. [Karma](https://github.com/karma-runner/karma) is used to run
2437
[Mocha](https://github.com/mochajs/mocha) tests in the browser. You can debug by opening http://localhost:9876/debug.html in
25-
a browser while the test running is active.
38+
a browser while the test running is active. The tests will rerun automatically when files are changed.
39+
40+
You can run specific tests by [adding `.only` to `describe` or `it` calls](https://mochajs.org/#exclusive-tests).
41+
42+
## Releases
43+
44+
Releases are done automatically in CI when commits are merged into master by analyzing [Conventional Commit Messages](https://conventionalcommits.org/).
45+
After running `npm install`, commit messages will be linted automatically when committing.
46+
You may have to rebase a branch before merging to ensure it has a proper commit history.
47+
48+
## Glossary
2649

27-
All tests are ran against DOM that is generated to match the DOM used by the supported code hosts.
50+
| Term | Definition |
51+
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
52+
| Code view | The DOM element that contains all the line elements |
53+
| Line number element | The DOM element that contains the line number label for that line |
54+
| Code element | The DOM element that contains the code for one line |
55+
| 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. |
56+
| Hover overlay | Also called tooltip |

src/hoverifier.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ export const TOOLTIP_DISPLAY_DELAY = 100
212212

213213
export type HoverFetcher = (position: HoveredToken & HoveredTokenContext) => Observable<HoverMerged | null>
214214
export type JumpURLFetcher = (position: HoveredToken & HoveredTokenContext) => Observable<string | null>
215+
216+
/**
217+
* Function responsible for resolving the position of a hovered token
218+
* and its diff part to a full context including repository, commit ID and file path.
219+
*/
215220
export type ContextResolver = (hoveredToken: HoveredToken) => HoveredTokenContext
216221

217222
export interface HoveredTokenContext extends RepoSpec, RevSpec, FileSpec, ResolvedRevSpec {}

0 commit comments

Comments
 (0)