@@ -46,11 +46,6 @@ interface IResponseData {
46
46
ce_editor : CodeEditor . IEditor ;
47
47
}
48
48
49
- interface IOnHoverResponse {
50
- hover : lsProtocol . Hover ;
51
- position : IVirtualPosition ;
52
- }
53
-
54
49
/**
55
50
* Check whether mouse is close to given element (within a specified number of pixels)
56
51
* @param what target element
@@ -132,10 +127,10 @@ export class HoverCM extends CodeMirrorIntegration {
132
127
private virtual_position : IVirtualPosition ;
133
128
protected cache : ResponseCache ;
134
129
135
- private debounced_get_hover : Throttler < Promise < IOnHoverResponse | null > > ;
130
+ private debounced_get_hover : Throttler < Promise < lsProtocol . Hover | null > > ;
136
131
private tooltip : FreeTooltip ;
137
132
private _previousHoverRequest : Promise <
138
- Promise < IOnHoverResponse | null >
133
+ Promise < lsProtocol . Hover | null >
139
134
> | null = null ;
140
135
141
136
constructor ( options : IEditorIntegrationOptions ) {
@@ -254,7 +249,7 @@ export class HoverCM extends CodeMirrorIntegration {
254
249
}
255
250
256
251
protected create_throttler ( ) {
257
- return new Throttler < Promise < IOnHoverResponse | null > > ( this . on_hover , {
252
+ return new Throttler < Promise < lsProtocol . Hover | null > > ( this . on_hover , {
258
253
limit : this . settings . composite . throttlerDelay ,
259
254
edge : 'trailing'
260
255
} ) ;
@@ -269,8 +264,9 @@ export class HoverCM extends CodeMirrorIntegration {
269
264
}
270
265
271
266
protected on_hover = async (
272
- position : IVirtualPosition
273
- ) : Promise < IOnHoverResponse | null > => {
267
+ virtual_position : IVirtualPosition ,
268
+ add_range_fn : ( hover : lsProtocol . Hover ) => lsProtocol . Hover
269
+ ) : Promise < lsProtocol . Hover | null > => {
274
270
if (
275
271
! (
276
272
this . connection . isReady &&
@@ -279,27 +275,24 @@ export class HoverCM extends CodeMirrorIntegration {
279
275
) {
280
276
return null ;
281
277
}
282
- const hover = await this . connection . clientRequests [
278
+ let hover = await this . connection . clientRequests [
283
279
'textDocument/hover'
284
280
] . request ( {
285
281
textDocument : {
286
282
// this might be wrong - should not it be using the specific virtual document?
287
283
uri : this . virtual_document . document_info . uri
288
284
} ,
289
285
position : {
290
- line : position . line ,
291
- character : position . ch
286
+ line : virtual_position . line ,
287
+ character : virtual_position . ch
292
288
}
293
289
} ) ;
294
290
295
291
if ( hover == null ) {
296
292
return null ;
297
293
}
298
294
299
- return {
300
- hover : hover ,
301
- position : position
302
- } ;
295
+ return add_range_fn ( hover ) ;
303
296
} ;
304
297
305
298
protected static get_markup_for_hover (
@@ -408,7 +401,7 @@ export class HoverCM extends CodeMirrorIntegration {
408
401
// (only cells with code) instead, but this is more complex to implement right. In any case filtering
409
402
// is needed to determine in hovered character belongs to this virtual document
410
403
411
- let root_position = this . position_from_mouse ( event ) ;
404
+ const root_position = this . position_from_mouse ( event ) ;
412
405
413
406
// happens because mousemove is attached to panel, not individual code cells,
414
407
// and because some regions of the editor (between lines) have no characters
@@ -454,35 +447,46 @@ export class HoverCM extends CodeMirrorIntegration {
454
447
let response_data = this . restore_from_cache ( document , virtual_position ) ;
455
448
456
449
if ( response_data == null ) {
457
- const promise = this . debounced_get_hover . invoke ( virtual_position ) ;
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
+ ) ;
458
468
this . _previousHoverRequest = promise ;
459
469
let response = await promise ;
460
470
if ( this . _previousHoverRequest === promise ) {
461
471
this . _previousHoverRequest = null ;
462
472
}
463
473
if (
464
474
response &&
465
- is_equal ( response . position , virtual_position ) &&
466
- this . is_useful_response ( response . hover )
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 )
467
481
) {
468
- let ce_editor =
469
- this . virtual_editor . get_editor_at_root_position ( root_position ) ;
470
- let cm_editor =
471
- this . virtual_editor . ce_editor_to_cm_editor . get ( ce_editor ) ! ;
472
-
473
- let editor_range = this . get_editor_range (
474
- response . hover ,
482
+ const editor_range = this . get_editor_range (
483
+ response ,
475
484
root_position ,
476
485
token ,
477
486
cm_editor
478
487
) ;
479
-
480
488
response_data = {
481
- response : this . add_range_if_needed (
482
- response . hover ,
483
- editor_range ,
484
- ce_editor
485
- ) ,
489
+ response : response ,
486
490
document : document ,
487
491
editor_range : editor_range ,
488
492
ce_editor : ce_editor
0 commit comments