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

fix: error emitted from a hover provider broke other hover providers #117

Merged
merged 3 commits into from
Oct 31, 2018
Merged
Changes from 1 commit
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
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 { map, switchMap, catchError } 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