Skip to content

Commit d2a7a7d

Browse files
authored
Merge pull request #864 from yamaton/add-mouseover-hover
Add option to show up hover tooltip automatically
2 parents 72834bc + 3dd359a commit d2a7a7d

File tree

6 files changed

+68
-4
lines changed

6 files changed

+68
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
- features:
66
- implement jump target selector and jump to references ([#739])
77
- implement settings UI using native JupyterLab 3.3 UI ([#778])
8+
- add option to show hover tooltip automatically ([#864], thanks @yamaton)
89
- bug fixes
910
- use correct websocket URL if configured as different from base URL ([#820], thanks @MikeSem)
1011
- clean up all completer styles when completer feature is disabled ([#829]).
1112
- fix `undefined` being inserted for path-like completion items with no `insertText` ([#833])
1213
- reduce signature flickering when typing and hover flicker when moving mouse ([#836])
14+
- fix sporadic misplacement of hover tooltips ([#860], thanks @yamaton)
1315
- refactoring:
1416
- changed NPM packages namespace from `@krassowski` to `@jupyter-lsp` ([#862])
1517
- move client capabilities to features ([#738])
@@ -34,6 +36,8 @@
3436
[#829]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/829
3537
[#833]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/833
3638
[#836]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/836
39+
[#860]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/860
40+
[#864]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/864
3741

3842
### `@krassowski/jupyterlab-lsp 3.10.1` (2022-03-21)
3943

atest/05_Features/Hover.robot

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ ${HOVER_SIGNAL} css:.cm-lsp-hover-available
1515

1616

1717
*** Test Cases ***
18+
Hover Does Not Trigger Automatically
19+
Enter Cell Editor 1
20+
${sel} = Last Occurrence python_add
21+
Configure JupyterLab Plugin {"autoActivate": false}
22+
... plugin id=${HOVER PLUGIN ID}
23+
Trigger Automatically By Hover ${sel}
24+
Sleep 1s
25+
Element Text Should Be ${HOVER_SIGNAL} python_add
26+
Page Should Not Contain Element ${HOVER_BOX}
27+
28+
Hover Triggers Automatically
29+
Enter Cell Editor 1
30+
${sel} = Last Occurrence python_add
31+
Configure JupyterLab Plugin {"delay": 100, "autoActivate": true}
32+
... plugin id=${HOVER PLUGIN ID}
33+
Trigger Automatically By Hover ${sel}
34+
Wait Until Keyword Succeeds 4x 0.1s Page Should Contain Element ${HOVER_BOX}
35+
1836
Hover works in notebooks
1937
Enter Cell Editor 1
2038
Trigger Tooltip python_add
@@ -56,6 +74,14 @@ Last Occurrence
5674
... xpath:(//span[@role="presentation"][contains(., "${symbol}")])[last()]
5775
RETURN ${sel}
5876

77+
Trigger Automatically By Hover
78+
[Arguments] ${sel}
79+
# bring the cursor to the element
80+
Wokraround Visibility Problem ${sel}
81+
Mouse Over ${sel}
82+
Wait Until Page Contains Element ${HOVER_SIGNAL} timeout=10s
83+
Mouse Over And Wiggle ${sel} 5
84+
5985
Trigger Via Hover With Modifier
6086
[Arguments] ${sel}
6187
# bring the cursor to the element

atest/Variables.resource

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ ${COMPLETION PLUGIN ID} @jupyter-lsp/jupyterlab-lsp:completion
5757
${HIGHLIGHTS PLUGIN ID} @jupyter-lsp/jupyterlab-lsp:highlights
5858
${JUMP PLUGIN ID} @jupyter-lsp/jupyterlab-lsp:jump_to
5959
${DIAGNOSTICS PLUGIN ID} @jupyter-lsp/jupyterlab-lsp:diagnostics
60+
${HOVER PLUGIN ID} @jupyter-lsp/jupyterlab-lsp:hover
6061
${CSS USER SETTINGS} .jp-SettingsRawEditor-user
6162
${JLAB XP CLOSE SETTINGS}
6263
... ${JLAB XP DOCK TAB}\[contains(., 'Settings')]/*[contains(@class, 'm-TabBar-tabCloseIcon')]

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: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ export class HoverCM extends CodeMirrorIntegration {
141141
return this.settings.composite.modifierKey;
142142
}
143143

144+
protected get isHoverAutomatic(): boolean {
145+
return this.settings.composite.autoActivate;
146+
}
147+
144148
get lab_integration() {
145149
return super.lab_integration as HoverLabIntegration;
146150
}
@@ -387,15 +391,19 @@ export class HoverCM extends CodeMirrorIntegration {
387391
protected async _updateUnderlineAndTooltip(
388392
event: MouseEvent
389393
): Promise<boolean> {
390-
const target = event.target as HTMLElement;
394+
const target = event.target;
391395

392396
// if over an empty space in a line (and not over a token) then not worth checking
393-
if (target.classList.contains('CodeMirror-line')) {
397+
if (
398+
target == null ||
399+
(target as HTMLElement).classList.contains('CodeMirror-line')
400+
) {
394401
this.remove_range_highlight();
395402
return false;
396403
}
397404

398-
const show_tooltip = getModifierState(event, this.modifierKey);
405+
const show_tooltip =
406+
this.isHoverAutomatic || getModifierState(event, this.modifierKey);
399407

400408
// currently the events are coming from notebook panel; ideally these would be connected to individual cells,
401409
// (only cells with code) instead, but this is more complex to implement right. In any case filtering
@@ -445,6 +453,7 @@ export class HoverCM extends CodeMirrorIntegration {
445453
]);
446454
}
447455
let response_data = this.restore_from_cache(document, virtual_position);
456+
let delay_ms = this.settings.composite.delay;
448457

449458
if (response_data == null) {
450459
const ce_editor =
@@ -493,12 +502,21 @@ export class HoverCM extends CodeMirrorIntegration {
493502
};
494503

495504
this.cache.store(response_data);
505+
delay_ms = Math.max(
506+
0,
507+
this.settings.composite.delay -
508+
this.settings.composite.throttlerDelay
509+
);
496510
} else {
497511
this.remove_range_highlight();
498512
return false;
499513
}
500514
}
501515

516+
if (this.isHoverAutomatic) {
517+
await new Promise(resolve => setTimeout(resolve, delay_ms));
518+
}
519+
502520
return this.handleResponse(response_data, root_position, show_tooltip);
503521
} else {
504522
return true;

python_packages/jupyterlab_lsp/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
LABEXTENSIONS_DIR = Path("jupyterlab_lsp/labextensions")
88
LABEXTENSIONS_INSTALL_DIR = Path("share") / "jupyter" / "labextensions"
9-
LAB_PACKAGE_PATH = LABEXTENSIONS_DIR / "@jupyter-lsp" / "jupyterlab-lsp" / "package.json"
9+
LAB_PACKAGE_PATH = (
10+
LABEXTENSIONS_DIR / "@jupyter-lsp" / "jupyterlab-lsp" / "package.json"
11+
)
1012

1113

1214
def get_data_files():

0 commit comments

Comments
 (0)