@@ -127,12 +127,10 @@ export class HoverCM extends CodeMirrorIntegration {
127
127
private virtual_position : IVirtualPosition ;
128
128
protected cache : ResponseCache ;
129
129
130
- private debounced_get_hover : Throttler <
131
- Promise < lsProtocol . Hover | undefined | null >
132
- > ;
130
+ private debounced_get_hover : Throttler < Promise < lsProtocol . Hover | null > > ;
133
131
private tooltip : FreeTooltip ;
134
132
private _previousHoverRequest : Promise <
135
- Promise < lsProtocol . Hover | undefined | null >
133
+ Promise < lsProtocol . Hover | null >
136
134
> | null = null ;
137
135
138
136
constructor ( options : IEditorIntegrationOptions ) {
@@ -251,13 +249,10 @@ export class HoverCM extends CodeMirrorIntegration {
251
249
}
252
250
253
251
protected create_throttler ( ) {
254
- return new Throttler < Promise < lsProtocol . Hover | undefined | null > > (
255
- this . on_hover ,
256
- {
257
- limit : this . settings . composite . throttlerDelay ,
258
- edge : 'trailing'
259
- }
260
- ) ;
252
+ return new Throttler < Promise < lsProtocol . Hover | null > > ( this . on_hover , {
253
+ limit : this . settings . composite . throttlerDelay ,
254
+ edge : 'trailing'
255
+ } ) ;
261
256
}
262
257
263
258
afterChange ( change : IEditorChange , root_position : IRootPosition ) {
@@ -268,26 +263,36 @@ export class HoverCM extends CodeMirrorIntegration {
268
263
this . remove_range_highlight ( ) ;
269
264
}
270
265
271
- protected on_hover = async ( ) => {
266
+ protected on_hover = async (
267
+ virtual_position : IVirtualPosition ,
268
+ add_range_fn : ( hover : lsProtocol . Hover ) => lsProtocol . Hover
269
+ ) : Promise < lsProtocol . Hover | null > => {
272
270
if (
273
271
! (
274
272
this . connection . isReady &&
275
273
this . connection . serverCapabilities ?. hoverProvider
276
274
)
277
275
) {
278
- return ;
276
+ return null ;
279
277
}
280
- let position = this . virtual_position ;
281
- return await this . connection . clientRequests [ 'textDocument/hover' ] . request ( {
278
+ let hover = await this . connection . clientRequests [
279
+ 'textDocument/hover'
280
+ ] . request ( {
282
281
textDocument : {
283
282
// this might be wrong - should not it be using the specific virtual document?
284
283
uri : this . virtual_document . document_info . uri
285
284
} ,
286
285
position : {
287
- line : position . line ,
288
- character : position . ch
286
+ line : virtual_position . line ,
287
+ character : virtual_position . ch
289
288
}
290
289
} ) ;
290
+
291
+ if ( hover == null ) {
292
+ return null ;
293
+ }
294
+
295
+ return add_range_fn ( hover ) ;
291
296
} ;
292
297
293
298
protected static get_markup_for_hover (
@@ -396,7 +401,7 @@ export class HoverCM extends CodeMirrorIntegration {
396
401
// (only cells with code) instead, but this is more complex to implement right. In any case filtering
397
402
// is needed to determine in hovered character belongs to this virtual document
398
403
399
- let root_position = this . position_from_mouse ( event ) ;
404
+ const root_position = this . position_from_mouse ( event ) ;
400
405
401
406
// happens because mousemove is attached to panel, not individual code cells,
402
407
// and because some regions of the editor (between lines) have no characters
@@ -442,31 +447,46 @@ export class HoverCM extends CodeMirrorIntegration {
442
447
let response_data = this . restore_from_cache ( document , virtual_position ) ;
443
448
444
449
if ( response_data == null ) {
445
- const promise = this . debounced_get_hover . invoke ( ) ;
450
+ const ce_editor =
451
+ this . virtual_editor . get_editor_at_root_position ( root_position ) ;
452
+ const cm_editor =
453
+ this . virtual_editor . ce_editor_to_cm_editor . get ( ce_editor ) ! ;
454
+ const add_range_fn = ( hover : lsProtocol . Hover ) : lsProtocol . Hover => {
455
+ const editor_range = this . get_editor_range (
456
+ hover ,
457
+ root_position ,
458
+ token ,
459
+ cm_editor
460
+ ) ;
461
+ return this . add_range_if_needed ( hover , editor_range , ce_editor ) ;
462
+ } ;
463
+
464
+ const promise = this . debounced_get_hover . invoke (
465
+ virtual_position ,
466
+ add_range_fn
467
+ ) ;
446
468
this . _previousHoverRequest = promise ;
447
469
let response = await promise ;
448
470
if ( this . _previousHoverRequest === promise ) {
449
471
this . _previousHoverRequest = null ;
450
472
}
451
- if ( response && this . is_useful_response ( response ) ) {
452
- let ce_editor =
453
- this . virtual_editor . get_editor_at_root_position ( root_position ) ;
454
- let cm_editor =
455
- this . virtual_editor . ce_editor_to_cm_editor . get ( ce_editor ) ! ;
456
-
457
- let editor_range = this . get_editor_range (
473
+ if (
474
+ response &&
475
+ response . range &&
476
+ ProtocolCoordinates . isWithinRange (
477
+ { line : virtual_position . line , character : virtual_position . ch } ,
478
+ response . range
479
+ ) &&
480
+ this . is_useful_response ( response )
481
+ ) {
482
+ const editor_range = this . get_editor_range (
458
483
response ,
459
484
root_position ,
460
485
token ,
461
486
cm_editor
462
487
) ;
463
-
464
488
response_data = {
465
- response : this . add_range_if_needed (
466
- response ,
467
- editor_range ,
468
- ce_editor
469
- ) ,
489
+ response : response ,
470
490
document : document ,
471
491
editor_range : editor_range ,
472
492
ce_editor : ce_editor
0 commit comments