@@ -4,7 +4,6 @@ import { EMPTY, NEVER, Observable, of, Subject, Subscription } from 'rxjs'
44import { distinctUntilChanged , filter , map } from 'rxjs/operators'
55import { TestScheduler } from 'rxjs/testing'
66
7- import { noop } from 'lodash'
87import { propertyIsDefined } from './helpers'
98import {
109 AdjustmentDirection ,
@@ -18,7 +17,7 @@ import {
1817import { HoverOverlayProps } from './HoverOverlay'
1918import { findPositionsFromEvents , SupportedMouseEvent } from './positions'
2019import { CodeViewProps , DOM } from './testutils/dom'
21- import { createHoverAttachment , createStubHoverFetcher , createStubJumpURLFetcher } from './testutils/lsp'
20+ import { createHoverAttachment , createStubActionsFetcher , createStubHoverFetcher } from './testutils/lsp'
2221import { dispatchMouseEventAtPositionImpure } from './testutils/mouse'
2322import { LOADING } from './types'
2423
@@ -46,8 +45,7 @@ describe('Hoverifier', () => {
4645 hoverOverlayElements : of ( null ) ,
4746 hoverOverlayRerenders : EMPTY ,
4847 fetchHover : createStubHoverFetcher ( { range : hoverRange } , LOADER_DELAY + delayTime ) ,
49- fetchJumpURL : ( ) => of ( null ) ,
50- pushHistory : noop ,
48+ fetchActions : ( ) => of ( null ) ,
5149 } )
5250
5351 const positionJumps = new Subject < PositionJump > ( )
@@ -100,7 +98,6 @@ describe('Hoverifier', () => {
10098 const scheduler = new TestScheduler ( ( a , b ) => chai . assert . deepEqual ( a , b ) )
10199
102100 const hover = { }
103- const defURL = 'def url'
104101 const delayTime = 10
105102
106103 scheduler . run ( ( { cold, expectObservable } ) => {
@@ -110,8 +107,7 @@ describe('Hoverifier', () => {
110107 hoverOverlayElements : of ( null ) ,
111108 hoverOverlayRerenders : EMPTY ,
112109 fetchHover : createStubHoverFetcher ( hover , delayTime ) ,
113- fetchJumpURL : createStubJumpURLFetcher ( defURL , delayTime ) ,
114- pushHistory : noop ,
110+ fetchActions : createStubActionsFetcher ( [ 'foo' , 'bar' ] , delayTime ) ,
115111 } )
116112
117113 const positionJumps = new Subject < PositionJump > ( )
@@ -202,9 +198,10 @@ describe('Hoverifier', () => {
202198 // Only show on line 24, not line 25 (which is the 2nd click event below).
203199 fetchHover : position =>
204200 position . line === 24 ? createStubHoverFetcher ( { } , delayTime ) ( position ) : of ( null ) ,
205- fetchJumpURL : position =>
206- position . line === 24 ? createStubJumpURLFetcher ( 'def url' , delayTime ) ( position ) : of ( null ) ,
207- pushHistory : noop ,
201+ fetchActions : position =>
202+ position . line === 24
203+ ? createStubActionsFetcher ( [ 'foo' , 'bar' ] , delayTime ) ( position )
204+ : of ( null ) ,
208205 } )
209206
210207 const positionJumps = new Subject < PositionJump > ( )
@@ -274,9 +271,8 @@ describe('Hoverifier', () => {
274271 // Only show on line 24, not line 25 (which is the 2nd click event below).
275272 fetchHover : position =>
276273 position . line === 24 ? createStubHoverFetcher ( { } ) ( position ) : of ( null ) ,
277- fetchJumpURL : position =>
278- position . line === 24 ? createStubJumpURLFetcher ( 'def url' ) ( position ) : of ( null ) ,
279- pushHistory : noop ,
274+ fetchActions : position =>
275+ position . line === 24 ? createStubActionsFetcher ( [ 'foo' , 'bar' ] ) ( position ) : of ( null ) ,
280276 } )
281277
282278 const positionJumps = new Subject < PositionJump > ( )
@@ -345,7 +341,7 @@ describe('Hoverifier', () => {
345341
346342 const delayTime = LOADER_DELAY + 100
347343 const hover = { }
348- const defURL = 'def url'
344+ const actions = [ 'foo' , 'bar' ]
349345
350346 scheduler . run ( ( { cold, expectObservable } ) => {
351347 const hoverifier = createHoverifier ( {
@@ -354,8 +350,7 @@ describe('Hoverifier', () => {
354350 hoverOverlayElements : of ( null ) ,
355351 hoverOverlayRerenders : EMPTY ,
356352 fetchHover : createStubHoverFetcher ( hover , delayTime ) ,
357- fetchJumpURL : createStubJumpURLFetcher ( defURL , delayTime ) ,
358- pushHistory : noop ,
353+ fetchActions : createStubActionsFetcher ( actions , delayTime ) ,
359354 } )
360355
361356 const positionJumps = new Subject < PositionJump > ( )
@@ -374,21 +369,18 @@ describe('Hoverifier', () => {
374369 } )
375370 )
376371
377- const hoverAndDefinitionUpdates = hoverifier . hoverStateUpdates . pipe (
372+ const hoverAndActionsUpdates = hoverifier . hoverStateUpdates . pipe (
378373 filter ( propertyIsDefined ( 'hoverOverlayProps' ) ) ,
379- map ( ( { hoverOverlayProps : { definitionURLOrError , hoverOrError } } ) => ( {
380- definitionURLOrError ,
374+ map ( ( { hoverOverlayProps : { actionsOrError , hoverOrError } } ) => ( {
375+ actionsOrError ,
381376 hoverOrError,
382377 } ) ) ,
383- distinctUntilChanged ( isEqual ) ,
384- // For this test, only emit when both hover and def are here.
385- // Even though the fetchers are emitting at the same time, this observable emits twice .
378+ distinctUntilChanged ( ( a , b ) => isEqual ( a , b ) ) ,
379+ // For this test, filter out the intermediate emissions where exactly one of the fetchers is
380+ // loading .
386381 filter (
387- ( { definitionURLOrError, hoverOrError } ) =>
388- ! (
389- ( definitionURLOrError && hoverOrError === LOADING ) ||
390- ( hoverOrError !== LOADING && ! definitionURLOrError )
391- )
382+ ( { actionsOrError, hoverOrError } ) =>
383+ ( actionsOrError === LOADING ) === ( hoverOrError === LOADING )
392384 )
393385 )
394386
@@ -398,10 +390,10 @@ describe('Hoverifier', () => {
398390 const outputDiagram = `${ LOADER_DELAY } ms a ${ TOOLTIP_DISPLAY_DELAY - 1 } ms b`
399391
400392 const outputValues : {
401- [ key : string ] : Pick < HoverOverlayProps , 'hoverOrError' | 'definitionURLOrError ' >
393+ [ key : string ] : Pick < HoverOverlayProps < { } , string > , 'hoverOrError' | 'actionsOrError ' >
402394 } = {
403- a : { hoverOrError : LOADING , definitionURLOrError : undefined } , // def url is undefined when it is loading
404- b : { hoverOrError : createHoverAttachment ( hover ) , definitionURLOrError : { jumpURL : defURL } } ,
395+ a : { hoverOrError : LOADING , actionsOrError : LOADING } , // actions is undefined when it is loading
396+ b : { hoverOrError : createHoverAttachment ( hover ) , actionsOrError : actions } ,
405397 }
406398
407399 // Click https://sourcegraph.sgdev.org/github.com/gorilla/mux@cb 4698366aa625048f3b815af6a0dea8aef9280a/-/blob/mux.go#L24:6
@@ -412,7 +404,7 @@ describe('Hoverifier', () => {
412404 } )
413405 )
414406
415- expectObservable ( hoverAndDefinitionUpdates ) . toBe ( outputDiagram , outputValues )
407+ expectObservable ( hoverAndActionsUpdates ) . toBe ( outputDiagram , outputValues )
416408 } )
417409 }
418410 } )
@@ -422,7 +414,6 @@ describe('Hoverifier', () => {
422414 const scheduler = new TestScheduler ( ( a , b ) => chai . assert . deepEqual ( a , b ) )
423415
424416 const hover = { }
425- const defURL = 'def url'
426417
427418 scheduler . run ( ( { cold, expectObservable } ) => {
428419 const hoverifier = createHoverifier ( {
@@ -431,8 +422,7 @@ describe('Hoverifier', () => {
431422 hoverOverlayElements : of ( null ) ,
432423 hoverOverlayRerenders : EMPTY ,
433424 fetchHover : createStubHoverFetcher ( hover ) ,
434- fetchJumpURL : createStubJumpURLFetcher ( defURL ) ,
435- pushHistory : noop ,
425+ fetchActions : ( ) => of ( null ) ,
436426 } )
437427
438428 const positionJumps = new Subject < PositionJump > ( )
@@ -486,7 +476,6 @@ describe('Hoverifier', () => {
486476 const scheduler = new TestScheduler ( ( a , b ) => chai . assert . deepEqual ( a , b ) )
487477
488478 const hover = { }
489- const defURL = 'def url'
490479
491480 scheduler . run ( ( { cold, expectObservable } ) => {
492481 const hoverifier = createHoverifier ( {
@@ -495,8 +484,7 @@ describe('Hoverifier', () => {
495484 hoverOverlayElements : of ( null ) ,
496485 hoverOverlayRerenders : EMPTY ,
497486 fetchHover : createStubHoverFetcher ( hover ) ,
498- fetchJumpURL : createStubJumpURLFetcher ( defURL ) ,
499- pushHistory : noop ,
487+ fetchActions : ( ) => of ( null ) ,
500488 } )
501489
502490 const positionJumps = new Subject < PositionJump > ( )
@@ -551,7 +539,7 @@ describe('Hoverifier', () => {
551539 /**
552540 * This test ensures that the adjustPosition options is being called in the ways we expect. This test is actually not the best way to ensure the feature
553541 * works as expected. This is a good example of a bad side effect of how the main `hoverifier.ts` file is too tightly integrated with itself. Ideally, I'd be able to assert
554- * that the effected positions have actually been adjusted as intended but this is impossible with the current implementation. We can assert that the `HoverFetcher` and `JumpURLFetcher `s
542+ * that the effected positions have actually been adjusted as intended but this is impossible with the current implementation. We can assert that the `HoverFetcher` and `ActionsFetcher `s
555543 * have the adjusted positions (AdjustmentDirection.CodeViewToActual). However, we cannot reliably assert that the code "highlighting" the token has the position adjusted (AdjustmentDirection.ActualToCodeView).
556544 */
557545 /**
@@ -565,7 +553,7 @@ describe('Hoverifier', () => {
565553 const adjustmentDirections = new Subject < AdjustmentDirection > ( )
566554
567555 const fetchHover = createStubHoverFetcher ( { } )
568- const fetchJumpURL = createStubJumpURLFetcher ( 'def' )
556+ const fetchActions = createStubActionsFetcher ( [ 'foo' , 'bar' ] )
569557
570558 const adjustPosition : PositionAdjuster < { } > = ( { direction, position } ) => {
571559 adjustmentDirections . next ( direction )
@@ -579,8 +567,7 @@ describe('Hoverifier', () => {
579567 hoverOverlayElements : of ( null ) ,
580568 hoverOverlayRerenders : EMPTY ,
581569 fetchHover,
582- fetchJumpURL,
583- pushHistory : noop ,
570+ fetchActions,
584571 } )
585572
586573 const positionJumps = new Subject < PositionJump > ( )
0 commit comments