Skip to content

Commit

Permalink
Add an option to show hover tooltip automatically
Browse files Browse the repository at this point in the history
Introduce a new item 'autoHover' and 'delay' to Code Hover setting.
  • Loading branch information
yamaton committed Sep 28, 2022
1 parent ba8846c commit 4f88373
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/jupyterlab-lsp/schema/hover.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 16 additions & 1 deletion packages/jupyterlab-lsp/src/features/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4f88373

Please sign in to comment.