Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to show up hover tooltip automatically #864

Merged
merged 5 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
- features:
- implement jump target selector and jump to references ([#739])
- implement settings UI using native JupyterLab 3.3 UI ([#778])
- add option to show hover tooltip automatically ([#864], thanks @yamaton)
- bug fixes
- use correct websocket URL if configured as different from base URL ([#820], thanks @MikeSem)
- clean up all completer styles when completer feature is disabled ([#829]).
- fix `undefined` being inserted for path-like completion items with no `insertText` ([#833])
- reduce signature flickering when typing and hover flicker when moving mouse ([#836])
- fix sporadic misplacement of hover tooltips ([#860], thanks @yamaton)
- refactoring:
- changed NPM packages namespace from `@krassowski` to `@jupyter-lsp` ([#862])
- move client capabilities to features ([#738])
Expand All @@ -34,6 +36,8 @@
[#829]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/829
[#833]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/833
[#836]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/836
[#860]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/860
[#864]: https://github.com/jupyter-lsp/jupyterlab-lsp/pull/864

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

Expand Down
26 changes: 26 additions & 0 deletions atest/05_Features/Hover.robot
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ ${HOVER_SIGNAL} css:.cm-lsp-hover-available


*** Test Cases ***
Hover Does Not Trigger Automatically
Enter Cell Editor 1
${sel} = Last Occurrence python_add
Configure JupyterLab Plugin {"autoActivate": false}
... plugin id=${HOVER PLUGIN ID}
Trigger Automatically By Hover ${sel}
Sleep 1s
Element Text Should Be ${HOVER_SIGNAL} python_add
Page Should Not Contain Element ${HOVER_BOX}

Hover Triggers Automatically
Enter Cell Editor 1
${sel} = Last Occurrence python_add
Configure JupyterLab Plugin {"delay": 100, "autoActivate": true}
... plugin id=${HOVER PLUGIN ID}
Trigger Automatically By Hover ${sel}
Wait Until Keyword Succeeds 4x 0.1s Page Should Contain Element ${HOVER_BOX}

Hover works in notebooks
Enter Cell Editor 1
Trigger Tooltip python_add
Expand Down Expand Up @@ -56,6 +74,14 @@ Last Occurrence
... xpath:(//span[@role="presentation"][contains(., "${symbol}")])[last()]
RETURN ${sel}

Trigger Automatically By Hover
[Arguments] ${sel}
# bring the cursor to the element
Wokraround Visibility Problem ${sel}
Mouse Over ${sel}
Wait Until Page Contains Element ${HOVER_SIGNAL} timeout=10s
Mouse Over And Wiggle ${sel} 5

Trigger Via Hover With Modifier
[Arguments] ${sel}
# bring the cursor to the element
Expand Down
1 change: 1 addition & 0 deletions atest/Variables.resource
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ${COMPLETION PLUGIN ID} @jupyter-lsp/jupyterlab-lsp:completion
${HIGHLIGHTS PLUGIN ID} @jupyter-lsp/jupyterlab-lsp:highlights
${JUMP PLUGIN ID} @jupyter-lsp/jupyterlab-lsp:jump_to
${DIAGNOSTICS PLUGIN ID} @jupyter-lsp/jupyterlab-lsp:diagnostics
${HOVER PLUGIN ID} @jupyter-lsp/jupyterlab-lsp:hover
${CSS USER SETTINGS} .jp-SettingsRawEditor-user
${JLAB XP CLOSE SETTINGS}
... ${JLAB XP DOCK TAB}\[contains(., 'Settings')]/*[contains(@class, 'm-TabBar-tabCloseIcon')]
Expand Down
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
24 changes: 21 additions & 3 deletions packages/jupyterlab-lsp/src/features/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,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 @@ -382,15 +386,19 @@ export class HoverCM extends CodeMirrorIntegration {
protected async _updateUnderlineAndTooltip(
event: MouseEvent
): Promise<boolean> {
const target = event.target as HTMLElement;
const target = event.target;

// if over an empty space in a line (and not over a token) then not worth checking
if (target.classList.contains('CodeMirror-line')) {
if (
target == null ||
(target as HTMLElement).classList.contains('CodeMirror-line')
) {
this.remove_range_highlight();
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 @@ -440,6 +448,7 @@ export class HoverCM extends CodeMirrorIntegration {
]);
}
let response_data = this.restore_from_cache(document, virtual_position);
let delay_ms = this.settings.composite.delay;

if (response_data == null) {
const promise = this.debounced_get_hover.invoke();
Expand Down Expand Up @@ -473,12 +482,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
4 changes: 3 additions & 1 deletion python_packages/jupyterlab_lsp/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

LABEXTENSIONS_DIR = Path("jupyterlab_lsp/labextensions")
LABEXTENSIONS_INSTALL_DIR = Path("share") / "jupyter" / "labextensions"
LAB_PACKAGE_PATH = LABEXTENSIONS_DIR / "@jupyter-lsp" / "jupyterlab-lsp" / "package.json"
LAB_PACKAGE_PATH = (
LABEXTENSIONS_DIR / "@jupyter-lsp" / "jupyterlab-lsp" / "package.json"
)


def get_data_files():
Expand Down