@@ -46,6 +46,11 @@ interface IResponseData {
46
46
ce_editor : CodeEditor . IEditor ;
47
47
}
48
48
49
+ interface IOnHoverResponse {
50
+ hover : lsProtocol . Hover ;
51
+ position : IVirtualPosition ;
52
+ }
53
+
49
54
/**
50
55
* Check whether mouse is close to given element (within a specified number of pixels)
51
56
* @param what target element
@@ -127,12 +132,10 @@ export class HoverCM extends CodeMirrorIntegration {
127
132
private virtual_position : IVirtualPosition ;
128
133
protected cache : ResponseCache ;
129
134
130
- private debounced_get_hover : Throttler <
131
- Promise < lsProtocol . Hover | undefined | null >
132
- > ;
135
+ private debounced_get_hover : Throttler < Promise < IOnHoverResponse | null > > ;
133
136
private tooltip : FreeTooltip ;
134
137
private _previousHoverRequest : Promise <
135
- Promise < lsProtocol . Hover | undefined | null >
138
+ Promise < IOnHoverResponse | null >
136
139
> | null = null ;
137
140
138
141
constructor ( options : IEditorIntegrationOptions ) {
@@ -251,13 +254,10 @@ export class HoverCM extends CodeMirrorIntegration {
251
254
}
252
255
253
256
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
- ) ;
257
+ return new Throttler < Promise < IOnHoverResponse | null > > ( this . on_hover , {
258
+ limit : this . settings . composite . throttlerDelay ,
259
+ edge : 'trailing'
260
+ } ) ;
261
261
}
262
262
263
263
afterChange ( change : IEditorChange , root_position : IRootPosition ) {
@@ -268,17 +268,20 @@ export class HoverCM extends CodeMirrorIntegration {
268
268
this . remove_range_highlight ( ) ;
269
269
}
270
270
271
- protected on_hover = async ( ) => {
271
+ protected on_hover = async (
272
+ position : IVirtualPosition
273
+ ) : Promise < IOnHoverResponse | null > => {
272
274
if (
273
275
! (
274
276
this . connection . isReady &&
275
277
this . connection . serverCapabilities ?. hoverProvider
276
278
)
277
279
) {
278
- return ;
280
+ return null ;
279
281
}
280
- let position = this . virtual_position ;
281
- return await this . connection . clientRequests [ 'textDocument/hover' ] . request ( {
282
+ const hover = await this . connection . clientRequests [
283
+ 'textDocument/hover'
284
+ ] . request ( {
282
285
textDocument : {
283
286
// this might be wrong - should not it be using the specific virtual document?
284
287
uri : this . virtual_document . document_info . uri
@@ -288,6 +291,15 @@ export class HoverCM extends CodeMirrorIntegration {
288
291
character : position . ch
289
292
}
290
293
} ) ;
294
+
295
+ if ( hover == null ) {
296
+ return null ;
297
+ }
298
+
299
+ return {
300
+ hover : hover ,
301
+ position : position
302
+ } ;
291
303
} ;
292
304
293
305
protected static get_markup_for_hover (
@@ -442,28 +454,32 @@ export class HoverCM extends CodeMirrorIntegration {
442
454
let response_data = this . restore_from_cache ( document , virtual_position ) ;
443
455
444
456
if ( response_data == null ) {
445
- const promise = this . debounced_get_hover . invoke ( ) ;
457
+ const promise = this . debounced_get_hover . invoke ( virtual_position ) ;
446
458
this . _previousHoverRequest = promise ;
447
459
let response = await promise ;
448
460
if ( this . _previousHoverRequest === promise ) {
449
461
this . _previousHoverRequest = null ;
450
462
}
451
- if ( response && this . is_useful_response ( response ) ) {
463
+ if (
464
+ response &&
465
+ is_equal ( response . position , virtual_position ) &&
466
+ this . is_useful_response ( response . hover )
467
+ ) {
452
468
let ce_editor =
453
469
this . virtual_editor . get_editor_at_root_position ( root_position ) ;
454
470
let cm_editor =
455
471
this . virtual_editor . ce_editor_to_cm_editor . get ( ce_editor ) ! ;
456
472
457
473
let editor_range = this . get_editor_range (
458
- response ,
474
+ response . hover ,
459
475
root_position ,
460
476
token ,
461
477
cm_editor
462
478
) ;
463
479
464
480
response_data = {
465
481
response : this . add_range_if_needed (
466
- response ,
482
+ response . hover ,
467
483
editor_range ,
468
484
ce_editor
469
485
) ,
0 commit comments