1- import { getModifierState , uris_equal } from '../utils' ;
1+ import { getModifierState } from '../utils' ;
22import { IRootPosition , is_equal , IVirtualPosition } from '../positioning' ;
33import * as lsProtocol from 'vscode-languageserver-protocol' ;
44import * as CodeMirror from 'codemirror' ;
@@ -23,6 +23,7 @@ import hoverSvg from '../../style/icons/hover.svg';
2323import { IEditorChange } from '../virtual/editor' ;
2424import { CodeEditor } from '@jupyterlab/codeeditor' ;
2525import { PositionConverter } from '../converter' ;
26+ import { VirtualDocument } from '../virtual/document' ;
2627
2728export const hoverIcon = new LabIcon ( {
2829 name : 'lsp:hover' ,
@@ -31,7 +32,7 @@ export const hoverIcon = new LabIcon({
3132
3233interface IResponseData {
3334 response : lsProtocol . Hover ;
34- uri : string ;
35+ document : VirtualDocument ;
3536 editor_range : IEditorRange ;
3637 ce_editor : CodeEditor . IEditor ;
3738}
@@ -91,14 +92,12 @@ export class HoverCM extends CodeMirrorIntegration {
9192 }
9293
9394 protected restore_from_cache (
94- root_position : IRootPosition
95+ root_position : IRootPosition ,
96+ document : VirtualDocument ,
97+ virtual_position : IVirtualPosition
9598 ) : IResponseData | null {
96- const virtual_position = this . virtual_editor . root_position_to_virtual_position (
97- root_position
98- ) ;
99- const document_uri = this . virtual_document . document_info . uri ;
10099 const matching_items = this . cache . data . filter ( cache_item => {
101- if ( ! uris_equal ( cache_item . uri , document_uri ) ) {
100+ if ( cache_item . document !== document ) {
102101 return false ;
103102 }
104103 let range = cache_item . response . range ;
@@ -123,7 +122,17 @@ export class HoverCM extends CodeMirrorIntegration {
123122 getModifierState ( event , this . modifierKey ) &&
124123 typeof this . last_hover_character !== 'undefined'
125124 ) {
126- let response_data = this . restore_from_cache ( this . last_hover_character ) ;
125+ const document = this . virtual_editor . document_at_root_position (
126+ this . last_hover_character
127+ ) ;
128+ const virtual_position = this . virtual_editor . root_position_to_virtual_position (
129+ this . last_hover_character
130+ ) ;
131+ let response_data = this . restore_from_cache (
132+ this . last_hover_character ,
133+ document ,
134+ virtual_position
135+ ) ;
127136 if ( response_data == null ) {
128137 return ;
129138 }
@@ -157,6 +166,7 @@ export class HoverCM extends CodeMirrorIntegration {
157166 protected on_hover = async ( ) => {
158167 return await this . connection . getHoverTooltip (
159168 this . virtual_position ,
169+ // this might be wrong - should not it be using the specific virtual document?
160170 this . virtual_document . document_info ,
161171 false
162172 ) ;
@@ -281,7 +291,11 @@ export class HoverCM extends CodeMirrorIntegration {
281291 this . virtual_position = virtual_position ;
282292 this . last_hover_character = root_position ;
283293
284- let response_data = this . restore_from_cache ( root_position ) ;
294+ let response_data = this . restore_from_cache (
295+ root_position ,
296+ document ,
297+ virtual_position
298+ ) ;
285299
286300 if ( response_data == null ) {
287301 let response = await this . debounced_get_hover . invoke ( ) ;
@@ -306,7 +320,7 @@ export class HoverCM extends CodeMirrorIntegration {
306320 editor_range ,
307321 ce_editor
308322 ) ,
309- uri : this . virtual_document . document_info . uri ,
323+ document : document ,
310324 editor_range : editor_range ,
311325 ce_editor : ce_editor
312326 } ;
@@ -341,6 +355,8 @@ export class HoverCM extends CodeMirrorIntegration {
341355 if ( this . hover_marker ) {
342356 this . hover_marker . clear ( ) ;
343357 this . hover_marker = null ;
358+ this . last_hover_response = undefined ;
359+ this . last_hover_character = undefined ;
344360 }
345361 } ;
346362
0 commit comments