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

feat: allow hover providers to communicate loading state #251

Merged
merged 6 commits into from
Apr 17, 2020

Conversation

felixfbecker
Copy link
Contributor

@felixfbecker felixfbecker commented Apr 16, 2020

This addresses sourcegraph/sourcegraph#9349, sourcegraph/sourcegraph#9350 and sourcegraph/sourcegraph#9346.

Codeintellify was originally not written to support providers updating the hover content later. It accepted Observables for cancellation, but they were intended to only emit once.

With extensions, Observables started to emit multiple times to update the content. The problem is that the period between invocation and the first result is used to display a loading indicator. But with multiple emissions, the situation can arise where first an empty result is emitted (e.g. because no providers were registered yet), then providers get registered and start loading, then emit actual non-empty result. Codeintellify had no way to know that providers started loading again.

This changes the types so that when an Observable is returned, it has to contain information about when the provider is loading or not loading in addition to the result to show (through MaybeLoadingResult<T>). It's still possible to only emit a single result by returning a Promise, in which case this information does not need to be provided because it is known (time between invocation and resolution).

This information is then used to make the loading indicator logic smarter - it now shows a loader even if the provider had emitted an empty result before, given that the LOADER_DELAY has elapsed. This logic was also duplicated with only slight modifications for definitions (in the main repo), so it is now abstracted in its own reusable Rx operator, which has Rx marble unit tests.

PR for the main repo: sourcegraph/sourcegraph#9914

BREAKING CHANGE: Hover providers that return Subscribables MUST
communicate loading state.
If the hover provider only emits a single result, it can return a
Promise instead.
@codecov
Copy link

codecov bot commented Apr 16, 2020

Codecov Report

Merging #251 into master will increase coverage by 0.33%.
The diff coverage is 95.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #251      +/-   ##
==========================================
+ Coverage   84.95%   85.29%   +0.33%     
==========================================
  Files          13       14       +1     
  Lines         565      578      +13     
  Branches      141      145       +4     
==========================================
+ Hits          480      493      +13     
  Misses         85       85              
Impacted Files Coverage Δ
src/types.ts 100.00% <ø> (ø)
src/hoverifier.ts 85.14% <80.00%> (-0.08%) ⬇️
src/helpers.ts 79.16% <100.00%> (+4.16%) ⬆️
src/loading.ts 100.00% <100.00%> (ø)
src/testutils/fixtures.ts 100.00% <100.00%> (ø)

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 2becf28...f7caa81. Read the comment docs.

@felixfbecker felixfbecker marked this pull request as ready for review April 16, 2020 11:54
@felixfbecker felixfbecker requested a review from a team April 16, 2020 11:54
@felixfbecker felixfbecker added this to Needs review in Web Team :: Current iteration via automation Apr 16, 2020
Web Team :: Current iteration automation moved this from Needs review to Reviewer approved Apr 16, 2020
Copy link
Contributor

@lguychard lguychard left a comment

Choose a reason for hiding this comment

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

Nice work!

src/loading.ts Outdated Show resolved Hide resolved
import { TestScheduler } from 'rxjs/testing'
import { emitLoading, LOADING, MaybeLoadingResult } from './loading'

const inputAlphabet: Record<'l' | 'e' | 'r', MaybeLoadingResult<number | null>> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I love the "shared alphabets" for tests 🙂

src/loading.ts Outdated Show resolved Hide resolved
src/loading.ts Outdated Show resolved Hide resolved
src/hoverifier.ts Outdated Show resolved Hide resolved
src/hoverifier.ts Outdated Show resolved Hide resolved
src/loading.ts Show resolved Hide resolved
@felixfbecker
Copy link
Contributor Author

Thanks for the thorough review @lguychard! I'll wait with merging this until the main repo PR is approved too so this doesn't turn out to need more adjustments after merging

src/loading.ts Show resolved Hide resolved
src/loading.test.ts Show resolved Hide resolved
@felixfbecker felixfbecker merged commit 47cb2c5 into master Apr 17, 2020
Web Team :: Current iteration automation moved this from Reviewer approved to Done Apr 17, 2020
@felixfbecker felixfbecker deleted the loading-updates branch April 17, 2020 06:17
@sourcegraph-bot
Copy link

🎉 This PR is included in version 7.0.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
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants