diff --git a/packages/jupyterlab-lsp/schema/hover.json b/packages/jupyterlab-lsp/schema/hover.json index 91d29e9f3..892ccaae3 100644 --- a/packages/jupyterlab-lsp/schema/hover.json +++ b/packages/jupyterlab-lsp/schema/hover.json @@ -5,6 +5,19 @@ "description": "LSP Hover over the code tooltip settings.", "type": "object", "properties": { + "autoActivate": { + "title": "Automatic hover", + "type": "boolean", + "default": false, + "description": "Automatic activation of hover without pressing a key. It will still be possible to show up tooltips with the modifier key." + }, + "delay": { + "title": "Hover delay", + "type": "number", + "default": 300, + "minimum": 0, + "description": "Number of milliseconds after which the hover tooltip should be shown. Ignored if 'Automatic hover' is OFF." + }, "modifierKey": { "title": "Modifier key", "type": "string", diff --git a/packages/jupyterlab-lsp/src/features/hover.ts b/packages/jupyterlab-lsp/src/features/hover.ts index bb0a99ecc..1f304335c 100644 --- a/packages/jupyterlab-lsp/src/features/hover.ts +++ b/packages/jupyterlab-lsp/src/features/hover.ts @@ -141,6 +141,10 @@ export class HoverCM extends CodeMirrorIntegration { return this.settings.composite.modifierKey; } + protected get isHoverAutomatic(): boolean { + return this.settings.composite.autoActivate; + } + get lab_integration() { return super.lab_integration as HoverLabIntegration; } @@ -395,7 +399,8 @@ export class HoverCM extends CodeMirrorIntegration { return false; } - const show_tooltip = getModifierState(event, this.modifierKey); + const show_tooltip = + this.isHoverAutomatic || getModifierState(event, this.modifierKey); // currently the events are coming from notebook panel; ideally these would be connected to individual cells, // (only cells with code) instead, but this is more complex to implement right. In any case filtering @@ -423,6 +428,7 @@ export class HoverCM extends CodeMirrorIntegration { return false; } + let delay_ms = this.settings.composite.delay; if ( !this.last_hover_character || !is_equal(root_position, this.last_hover_character) @@ -493,12 +499,21 @@ export class HoverCM extends CodeMirrorIntegration { }; this.cache.store(response_data); + delay_ms = Math.max( + 0, + this.settings.composite.delay - + this.settings.composite.throttlerDelay + ); } else { this.remove_range_highlight(); return false; } } + if (this.isHoverAutomatic) { + await new Promise(resolve => setTimeout(resolve, delay_ms)); + } + return this.handleResponse(response_data, root_position, show_tooltip); } else { return true;