Skip to content

Commit

Permalink
Merge pull request #653 from krassowski/improve-hover
Browse files Browse the repository at this point in the history
Fix hover rendering for `MarkedString`s, fix hover disappearing when moving mouse towards it
  • Loading branch information
krassowski authored Aug 1, 2021
2 parents 1b18dc3 + ddd31d1 commit 84782eb
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
### `@krassowski/jupyterlab-lsp 3.8.1` (unreleased)

- bug fixes:
- `%Rdevice` magic is now properly overridden and won't be extracted to R code [(#646)]
- remove spurious `ValidationError` warnings for non-installed servers ([#645)], thanks @karlaspuldaro)
- `%Rdevice` magic is now properly overridden and won't be extracted to R code ([#646)])
- Fix hover rendering for MarkedStrings, fix hover disappearing when moving mouse towards it ([#653)])

[#645]: https://github.com/krassowski/jupyterlab-lsp/pull/645
[#646]: https://github.com/krassowski/jupyterlab-lsp/pull/646
[#653]: https://github.com/krassowski/jupyterlab-lsp/pull/653

### `@krassowski/jupyterlab-lsp 3.8.0` (2021-07-04)

Expand Down
1 change: 0 additions & 1 deletion atest/05_Features/Hover.robot
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Trigger Via Hover With Modifier
Mouse Over ${sel}
# move it back and forth (wiggle) while hodling the ctrl modifier
Mouse Over With Control ${sel} x_wiggle=5
Wait Until Page Contains Element ${HOVER_SIGNAL}
Wait Until Keyword Succeeds 4x 0.1s Page Should Contain Element ${HOVER_BOX}

Trigger Via Modifier Key Press
Expand Down
2 changes: 1 addition & 1 deletion atest/07_Configuration.robot
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Settings Should Change Editor Diagnostics
Set Editor Content {"language_servers": {"${server}": {"serverSettings": ${settings}}}} ${CSS USER SETTINGS}
Wait Until Page Contains No errors found
Capture Page Screenshot 02-default-diagnostics-and-unsaved-settings.png
Click Element css:button[title\='Save User Settings']
Click Element css:button[title^\='Save User Settings']
Click Element ${JLAB XP CLOSE SETTINGS}
Drag and Drop By Offset ${tab} 0 100
Lab Command ${save command}
Expand Down
2 changes: 1 addition & 1 deletion atest/Keywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ Configure JupyterLab Plugin
Open in Advanced Settings ${plugin id}
Set Editor Content ${settings json} ${CSS USER SETTINGS}
Wait Until Page Contains No errors found
Click Element css:button[title\='Save User Settings']
Click Element css:button[title^\='Save User Settings']
Wait Until Page Contains No errors found
Click Element ${JLAB XP CLOSE SETTINGS}

Expand Down
11 changes: 10 additions & 1 deletion packages/jupyterlab-lsp/src/adapters/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,16 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
return;
}

if (state === 'completed') {
// TODO: remove workaround no later than with 3.2 release of JupyterLab
// workaround for https://github.com/jupyterlab/jupyterlab/issues/10721
// while already reverted in https://github.com/jupyterlab/jupyterlab/pull/10741,
// it was not released yet and many users will continue to run 3.1.0 and 3.1.1
// so lets workaround it for now
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const completedManually = state === 'completed manually';

if (state === 'completed' || completedManually) {
// note: must only be send to the appropriate connections as
// some servers (Julia) break if they receive save notification
// for a document that was not opened before, see:
Expand Down
35 changes: 29 additions & 6 deletions packages/jupyterlab-lsp/src/features/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ interface IResponseData {
ce_editor: CodeEditor.IEditor;
}

/**
* Check whether mouse is close to given element (within a specified number of pixels)
* @param what target element
* @param who mouse event determining position and target
* @param cushion number of pixels on each side defining "closeness" boundary
*/
function isCloseTo(what: HTMLElement, who: MouseEvent, cushion = 50): boolean {
const target = who.type === 'mouseleave' ? who.relatedTarget : who.target;

if (what === target || what.contains(target as HTMLElement)) {
return true;
}
const whatRect = what.getBoundingClientRect();
return !(
who.x < whatRect.left - cushion ||
who.x > whatRect.right + cushion ||
who.y < whatRect.top - cushion ||
who.y > whatRect.bottom + cushion
);
}

class ResponseCache {
protected _data: Array<IResponseData>;
get data() {
Expand Down Expand Up @@ -79,9 +100,11 @@ function to_markup(
content: string | lsProtocol.MarkedString
): lsProtocol.MarkupContent {
if (typeof content === 'string') {
// coerce to MarkedString object
// coerce deprecated MarkedString to an MarkupContent; if given as a string it is markdown too,
// quote: "It is either a markdown string or a code-block that provides a language and a code snippet."
// (https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#markedString)
return {
kind: 'plaintext',
kind: 'markdown',
value: content
};
} else {
Expand Down Expand Up @@ -158,7 +181,7 @@ export class HoverCM extends CodeMirrorIntegration {
this.updateUnderlineAndTooltip(event)
.then(keep_tooltip => {
if (!keep_tooltip) {
this.maybeHideTooltip(event.target);
this.maybeHideTooltip(event);
}
})
.catch(this.console.warn);
Expand Down Expand Up @@ -213,13 +236,13 @@ export class HoverCM extends CodeMirrorIntegration {

protected onMouseLeave = (event: MouseEvent) => {
this.remove_range_highlight();
this.maybeHideTooltip(event.relatedTarget);
this.maybeHideTooltip(event);
};

protected maybeHideTooltip(mouse_target: EventTarget) {
protected maybeHideTooltip(mouseEvent: MouseEvent) {
if (
typeof this.tooltip !== 'undefined' &&
mouse_target !== this.tooltip.node
!isCloseTo(this.tooltip.node, mouseEvent)
) {
this.tooltip.dispose();
}
Expand Down

0 comments on commit 84782eb

Please sign in to comment.