Skip to content
This repository was archived by the owner on Nov 6, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/client/providers/hover.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as assert from 'assert'
import { of } from 'rxjs'
import { of, throwError } from 'rxjs'
import { TestScheduler } from 'rxjs/testing'
import { Hover, MarkupKind } from 'sourcegraph'
import { HoverMerged } from '../../client/types/hover'
Expand Down Expand Up @@ -83,6 +83,20 @@ describe('getHover', () => {
})
))

it('omits error result from 1 provider', () =>
scheduler().run(({ cold, expectObservable }) =>
expectObservable(
getHover(
cold<ProvideTextDocumentHoverSignature[]>('-a-|', {
a: [() => throwError('err'), () => of(FIXTURE_RESULT)],
}),
FIXTURE.TextDocumentPositionParams
)
).toBe('-a-|', {
a: FIXTURE_RESULT_MERGED,
})
))

it('merges results from providers', () =>
scheduler().run(({ cold, expectObservable }) =>
expectObservable(
Expand Down
23 changes: 20 additions & 3 deletions src/client/providers/hover.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { combineLatest, from, Observable } from 'rxjs'
import { map, switchMap } from 'rxjs/operators'
import { catchError, map, switchMap } from 'rxjs/operators'
import { HoverMerged } from '../../client/types/hover'
import { TextDocumentPositionParams, TextDocumentRegistrationOptions } from '../../protocol'
import { Hover } from '../../protocol/plainTypes'
Expand All @@ -14,14 +14,20 @@ export class TextDocumentHoverProviderRegistry extends FeatureProviderRegistry<
TextDocumentRegistrationOptions,
ProvideTextDocumentHoverSignature
> {
/**
* Returns an observable that emits all providers' hovers whenever any of the last-emitted set of providers emits
* hovers. If any provider emits an error, the error is logged and the provider is omitted from the emission of
* the observable (the observable does not emit the error).
*/
public getHover(params: TextDocumentPositionParams): Observable<HoverMerged | null> {
return getHover(this.providers, params)
}
}

/**
* Returns an observable that emits all providers' hovers whenever any of the last-emitted set of providers emits
* hovers.
* hovers. If any provider emits an error, the error is logged and the provider is omitted from the emission of
* the observable (the observable does not emit the error).
*
* Most callers should use TextDocumentHoverProviderRegistry's getHover method, which uses the registered hover
* providers.
Expand All @@ -36,7 +42,18 @@ export function getHover(
if (providers.length === 0) {
return [[null]]
}
return combineLatest(providers.map(provider => from(provider(params))))
return combineLatest(
providers.map(provider =>
from(
provider(params).pipe(
catchError(err => {
console.error(err)
return [null]
})
)
)
)
)
})
)
.pipe(map(HoverMerged.from))
Expand Down