Skip to content

Commit 0d87b9b

Browse files
committed
Add an option to show hover tooltip automatically
Introduce a new item 'autoHover' and 'delay' to Code Hover setting.
1 parent 8125308 commit 0d87b9b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/jupyterlab-lsp/schema/hover.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
"description": "LSP Hover over the code tooltip settings.",
66
"type": "object",
77
"properties": {
8+
"autoActivate": {
9+
"title": "Automatic hover",
10+
"type": "boolean",
11+
"default": false,
12+
"description": "Automatic activation of hover without pressing a key. It will still be possible to show up tooltips with the modifier key."
13+
},
14+
"delay": {
15+
"title": "Hover delay",
16+
"type": "number",
17+
"default": 300,
18+
"minimum": 0,
19+
"description": "Number of milliseconds after which the hover tooltip should be shown. Ignored if 'Automatic hover' is OFF."
20+
},
821
"modifierKey": {
922
"title": "Modifier key",
1023
"type": "string",

packages/jupyterlab-lsp/src/features/hover.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ export class HoverCM extends CodeMirrorIntegration {
143143
return this.settings.composite.modifierKey;
144144
}
145145

146+
protected get isHoverAutomatic(): boolean {
147+
return this.settings.composite.autoActivate;
148+
}
149+
146150
get lab_integration() {
147151
return super.lab_integration as HoverLabIntegration;
148152
}
@@ -390,7 +394,8 @@ export class HoverCM extends CodeMirrorIntegration {
390394
return false;
391395
}
392396

393-
const show_tooltip = getModifierState(event, this.modifierKey);
397+
const show_tooltip =
398+
this.isHoverAutomatic || getModifierState(event, this.modifierKey);
394399

395400
// currently the events are coming from notebook panel; ideally these would be connected to individual cells,
396401
// (only cells with code) instead, but this is more complex to implement right. In any case filtering
@@ -440,6 +445,7 @@ export class HoverCM extends CodeMirrorIntegration {
440445
]);
441446
}
442447
let response_data = this.restore_from_cache(document, virtual_position);
448+
let delay_ms = this.settings.composite.delay;
443449

444450
if (response_data == null) {
445451
const promise = this.debounced_get_hover.invoke();
@@ -473,12 +479,21 @@ export class HoverCM extends CodeMirrorIntegration {
473479
};
474480

475481
this.cache.store(response_data);
482+
delay_ms = Math.max(
483+
0,
484+
this.settings.composite.delay -
485+
this.settings.composite.throttlerDelay
486+
);
476487
} else {
477488
this.remove_range_highlight();
478489
return false;
479490
}
480491
}
481492

493+
if (this.isHoverAutomatic) {
494+
await new Promise(resolve => setTimeout(resolve, delay_ms));
495+
}
496+
482497
return this.handleResponse(response_data, root_position, show_tooltip);
483498
} else {
484499
return true;

0 commit comments

Comments
 (0)