Skip to content

Commit

Permalink
Update CodeMirror and lezer packages (#15987)
Browse files Browse the repository at this point in the history
* Update CodeMirror and lazer packages

* Fix failing test after upgrade of `@codemirror/state` to 6.3.2+

as that version requires that `allowMultipleSelections` extension
is enabled to set multiple cursors; it is enabled by default in
JupyterLab but was previously filtered out in tests setup.
This commit adds it to the include list of extensions to use in tests.

* Fix incorrect typing of `getCoordinateForPosition` and `ICoordinate`

The cast from CodeMirror's `Rect` to `ICoordinate` was incorrect and was
masking the fact that the former did not have `x`, `y`, `width`, `height`,
nor `toJSON()`, along with the fact that CodeMirror could also return
`null`. This lead to type safety violations and bad failure in a test.

* Bump `@codemirror/view` to 6.26.0, `@codemirror/autocomplete` to 6.15.0

* Fix test missing non-null assertion after typing update

* Satisfy integrity check by... sorting lockfile?

* Fix search match color on selection

* Update snapshot as CodeMirror dimensions changed
  • Loading branch information
krassowski committed Mar 16, 2024
1 parent 3946e3f commit 9eea31b
Show file tree
Hide file tree
Showing 22 changed files with 228 additions and 186 deletions.
15 changes: 15 additions & 0 deletions docs/source/extension/extension_migration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
Extension Migration Guide
================================================


JupyterLab 4.1 to 4.2
---------------------

API updates
^^^^^^^^^^^

- The ``CodeEditor.ICoordinate`` interface was corrected to not include ``toJSON()``, ``x``, ``y``,
``width`` and ``height``; these properties were never set by methods returning ``ICoordinate``
and they were never used by methods accepting it.
- ``CodeEditor.getCoordinateForPosition`` return type was corrected to clarify that it can return
``null``; previously ``null`` could be returned despite the return type indicating it would always
return a non-null ``ICoordinate`` value.


JupyterLab 4.0 to 4.1
---------------------

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/cells/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@codemirror/state": "^6.2.0",
"@codemirror/view": "^6.9.6",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.26.0",
"@jupyter/ydoc": "^2.0.1",
"@jupyterlab/apputils": "^4.3.0-alpha.1",
"@jupyterlab/attachments": "^4.2.0-alpha.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/codeeditor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@codemirror/state": "^6.2.0",
"@codemirror/state": "^6.4.1",
"@jupyter/ydoc": "^2.0.1",
"@jupyterlab/apputils": "^4.3.0-alpha.1",
"@jupyterlab/coreutils": "^6.2.0-alpha.1",
Expand Down
5 changes: 3 additions & 2 deletions packages/codeeditor/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export namespace CodeEditor {
/**
* An interface describing editor state coordinates.
*/
export interface ICoordinate extends DOMRectReadOnly {}
export interface ICoordinate
extends Pick<DOMRectReadOnly, 'left' | 'right' | 'top' | 'bottom'> {}

/**
* A range.
Expand Down Expand Up @@ -462,7 +463,7 @@ export namespace CodeEditor {
*
* @returns The coordinates of the position.
*/
getCoordinateForPosition(position: IPosition): ICoordinate;
getCoordinateForPosition(position: IPosition): ICoordinate | null;

/**
* Get the cursor position given window coordinates.
Expand Down
10 changes: 3 additions & 7 deletions packages/codeeditor/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,12 @@ export class CodeEditorWrapper extends Widget {
if (data === undefined) {
return;
}
const coordinate = {
const coordinate: CodeEditor.ICoordinate = {
top: event.y,
bottom: event.y,
left: event.x,
right: event.x,
x: event.x,
y: event.y,
width: 0,
height: 0
} as CodeEditor.ICoordinate;
right: event.x
};
const position = this.editor.getPositionForCoordinate(coordinate);
if (position === null) {
return;
Expand Down
6 changes: 3 additions & 3 deletions packages/codemirror-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@codemirror/lang-markdown": "^6.1.1",
"@codemirror/language": "^6.6.0",
"@codemirror/legacy-modes": "^6.3.2",
"@codemirror/lang-markdown": "^6.2.4",
"@codemirror/language": "^6.10.1",
"@codemirror/legacy-modes": "^6.3.3",
"@jupyter/ydoc": "^2.0.1",
"@jupyterlab/application": "^4.2.0-alpha.1",
"@jupyterlab/codeeditor": "^4.2.0-alpha.1",
Expand Down
42 changes: 21 additions & 21 deletions packages/codemirror/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,45 +38,45 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@codemirror/autocomplete": "^6.5.1",
"@codemirror/commands": "^6.2.3",
"@codemirror/autocomplete": "^6.15.0",
"@codemirror/commands": "^6.3.3",
"@codemirror/lang-cpp": "^6.0.2",
"@codemirror/lang-css": "^6.1.1",
"@codemirror/lang-html": "^6.4.3",
"@codemirror/lang-css": "^6.2.1",
"@codemirror/lang-html": "^6.4.8",
"@codemirror/lang-java": "^6.0.1",
"@codemirror/lang-javascript": "^6.1.7",
"@codemirror/lang-javascript": "^6.2.2",
"@codemirror/lang-json": "^6.0.1",
"@codemirror/lang-markdown": "^6.1.1",
"@codemirror/lang-markdown": "^6.2.4",
"@codemirror/lang-php": "^6.0.1",
"@codemirror/lang-python": "^6.1.3",
"@codemirror/lang-python": "^6.1.4",
"@codemirror/lang-rust": "^6.0.1",
"@codemirror/lang-sql": "^6.4.1",
"@codemirror/lang-wast": "^6.0.1",
"@codemirror/lang-xml": "^6.0.2",
"@codemirror/language": "^6.6.0",
"@codemirror/legacy-modes": "^6.3.2",
"@codemirror/search": "^6.3.0",
"@codemirror/state": "^6.2.0",
"@codemirror/view": "^6.9.6",
"@codemirror/lang-sql": "^6.6.1",
"@codemirror/lang-wast": "^6.0.2",
"@codemirror/lang-xml": "^6.1.0",
"@codemirror/language": "^6.10.1",
"@codemirror/legacy-modes": "^6.3.3",
"@codemirror/search": "^6.5.6",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.26.0",
"@jupyter/ydoc": "^2.0.1",
"@jupyterlab/codeeditor": "^4.2.0-alpha.1",
"@jupyterlab/coreutils": "^6.2.0-alpha.1",
"@jupyterlab/documentsearch": "^4.2.0-alpha.1",
"@jupyterlab/nbformat": "^4.2.0-alpha.1",
"@jupyterlab/translation": "^4.2.0-alpha.1",
"@lezer/common": "^1.0.2",
"@lezer/generator": "^1.2.2",
"@lezer/highlight": "^1.1.4",
"@lezer/markdown": "^1.0.2",
"@lezer/common": "^1.2.1",
"@lezer/generator": "^1.7.0",
"@lezer/highlight": "^1.2.0",
"@lezer/markdown": "^1.2.0",
"@lumino/coreutils": "^2.1.2",
"@lumino/disposable": "^2.1.2",
"@lumino/signaling": "^2.1.2",
"yjs": "^13.5.40"
},
"devDependencies": {
"@jupyterlab/testing": "^4.2.0-alpha.1",
"@lezer/generator": "^1.2.2",
"@lezer/lr": "^1.3.3",
"@lezer/generator": "^1.7.0",
"@lezer/lr": "^1.4.0",
"@types/jest": "^29.2.0",
"jest": "^29.2.0",
"rimraf": "~5.0.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/codemirror/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ export class CodeMirrorEditor implements CodeEditor.IEditor {
*/
getCoordinateForPosition(
position: CodeEditor.IPosition
): CodeEditor.ICoordinate {
): CodeEditor.ICoordinate | null {
const offset = this.getOffsetAt(position);
const rect = this.editor.coordsAtPos(offset);
return rect as CodeEditor.ICoordinate;
return rect;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/codemirror/style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@
}

.jp-current-match > .cm-searching::selection,
.jp-current-match > .cm-searching span::selection,
.cm-searching > .jp-current-match::selection,
.jp-current-match > .cm-searching span::selection {
.cm-searching > .jp-current-match span::selection {
background-color: var(--jp-search-selected-match-background-color);
color: var(--jp-search-selected-match-color);
}
Expand Down
9 changes: 8 additions & 1 deletion packages/codemirror/test/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ describe('CodeMirrorEditor', () => {
languages = new EditorLanguageRegistry();
extensionsRegistry = new EditorExtensionRegistry();
EditorExtensionRegistry.getDefaultExtensions()
.filter(ext => ['lineNumbers', 'lineWrap', 'readOnly'].includes(ext.name))
.filter(ext =>
[
'lineNumbers',
'lineWrap',
'readOnly',
'allowMultipleSelections'
].includes(ext.name)
)
.forEach(ext => {
extensionsRegistry.addExtension(ext);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/completer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@codemirror/state": "^6.2.0",
"@codemirror/view": "^6.9.6",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.26.0",
"@jupyter/ydoc": "^2.0.1",
"@jupyterlab/apputils": "^4.3.0-alpha.1",
"@jupyterlab/codeeditor": "^4.2.0-alpha.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/completer/src/testutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { CodeMirrorEditor, ybinding } from '@jupyterlab/codemirror';
import { YFile } from '@jupyter/ydoc';

export function createEditorWidget(): CodeEditorWrapper {
const model = new CodeEditor.Model({ sharedModel: new YFile() });
const sharedModel = new YFile();
const model = new CodeEditor.Model({ sharedModel });
const factory = (options: CodeEditor.IOptions) => {
const m = options.model.sharedModel as any;
options.extensions = [
...(options.extensions ?? []),
ybinding({ ytext: m.ysource })
ybinding({ ytext: sharedModel.ysource })
];
return new CodeMirrorEditor(options);
};
Expand Down
6 changes: 5 additions & 1 deletion packages/completer/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,11 @@ export class Completer extends Widget {

const start = model.cursor.start;
const position = editor.getPositionAt(start) as CodeEditor.IPosition;
const anchor = editor.getCoordinateForPosition(position) as DOMRect;
const anchor = editor.getCoordinateForPosition(position);

if (!anchor) {
return;
}

const style = window.getComputedStyle(node);
const borderLeft = parseInt(style.borderLeftWidth!, 10) || 0;
Expand Down
4 changes: 2 additions & 2 deletions packages/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@codemirror/state": "^6.2.0",
"@codemirror/view": "^6.9.6",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.26.0",
"@jupyter/ydoc": "^2.0.1",
"@jupyterlab/apputils": "^4.3.0-alpha.1",
"@jupyterlab/cells": "^4.2.0-alpha.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/debugger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@codemirror/state": "^6.2.0",
"@codemirror/view": "^6.9.6",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.26.0",
"@jupyter/ydoc": "^2.0.1",
"@jupyterlab/application": "^4.2.0-alpha.1",
"@jupyterlab/apputils": "^4.3.0-alpha.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/fileeditor-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@codemirror/commands": "^6.2.3",
"@codemirror/search": "^6.3.0",
"@codemirror/commands": "^6.3.3",
"@codemirror/search": "^6.5.6",
"@jupyterlab/application": "^4.2.0-alpha.1",
"@jupyterlab/apputils": "^4.3.0-alpha.1",
"@jupyterlab/codeeditor": "^4.2.0-alpha.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/json-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@jupyterlab/rendermime-interfaces": "^3.10.0-alpha.1",
"@jupyterlab/translation": "^4.2.0-alpha.1",
"@jupyterlab/ui-components": "^4.2.0-alpha.1",
"@lezer/highlight": "^1.1.4",
"@lezer/highlight": "^1.2.0",
"@lumino/coreutils": "^2.1.2",
"@lumino/messaging": "^2.0.1",
"@lumino/widgets": "^2.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/metapackage/test/completer/widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ describe('completer/widget', () => {
Widget.attach(panel, document.body);

const position = code.editor.getPositionAt(text.length)!;
const coords = code.editor.getCoordinateForPosition(position);
const coords = code.editor.getCoordinateForPosition(position)!;

editor.setCursorPosition(position);

Expand Down
5 changes: 5 additions & 0 deletions packages/tooltip/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ export class Tooltip extends Widget {
const editor = this._editor;

const anchor = editor.getCoordinateForPosition(position);

if (!anchor) {
return;
}

const style = window.getComputedStyle(this.node);
const paddingLeft = parseInt(style.paddingLeft!, 10) || 0;

Expand Down
8 changes: 7 additions & 1 deletion packages/ui-components/src/hoverbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export namespace HoverBox {
* coordinate position, which can be retrieved via calling the
* `getCoordinateForPosition` method.
*/
anchor: DOMRect;
anchor: IAnchor;

/**
* The node that hosts the anchor.
Expand Down Expand Up @@ -123,6 +123,12 @@ export namespace HoverBox {
};
}

/**
* An interface describing anchor coordinates.
*/
export interface IAnchor
extends Pick<DOMRect, 'left' | 'right' | 'top' | 'bottom'> {}

/**
* Set the visible dimensions of a hovering box anchored to an editor cursor.
*
Expand Down

0 comments on commit 9eea31b

Please sign in to comment.