Skip to content

Conversation

@fcollonval
Copy link
Member

@fcollonval fcollonval commented Dec 21, 2022

References

Follow-up of #12861 (review)
Fixes #13362
Fixes #12886
Fixes #9124
Fixes #13206
Fixes #13162
Fixes #13199
Fixes #14011
Fixes #10486

Code changes

CodeMirror 6 can conform to the Token based approach of JupyterLab instead of using globals. The new tokens are:

  • @jupyterlab/codemirror:IEditorExtensionRegistry: Provide the CodeMirror editor extensions - default extensions are provided in a static method and loaded in the plugin providing the token.
  • @jupyterlab/codemirror:IEditorLanguageRegistry: Provide the languages for the editors - default languages are provided in a static method and loaded in the plugin providing the token. This allows to override the plugin with much less language for small application for example. A single default language for text/plain is provided.
  • @jupyterlab/codemirror:IEditorThemeRegistry: Provide the theme for the editors - default themes are provided in a static method and loaded in the plugin providing the token. This allows to override the plugin with less themes if required. A single default theme based on jupyter theme CSS variable is provided.

InputArea.defaultContentFactory and all its extensions (for Cell and Notebook) have been removed. The editor factory requires tokens. Hence we cannot provide a global default. This is similar to the evolution of the sanitizer.

TextModelFactory.preferredLanguage(path: string) is now a no-op (return '' for any path) as the languages are not available globally and as kernel language for text model makes no sense without more context.

Create a new Language for text/plain that parses nothing. This allows for a better retro-compatibility as well as a default display without syntax highlighting that is confusing for now on master (see for instance the console header).

Mode editor has been renamed to language to align with CodeMirror 6 naming and to clarify the meaning.

Drop configuration not supported in CodeMirror 6 - electricChars, coverGutterNextToScrollbar, scrollbarStyle, styleSelectedText and selectionPointer.
Add extensions to support cursorBlinkRate, rulers, showTrailingSpaces, scrollPastEnd.
lineWrap is now a simple boolean and wordWrapColumn is removed.

All configurable listed in #12812 are handled (= restored, changed or removed).

Improve code highlight style to be closer to 3.x.

The ipython CodeMirror language is for now identical to the Python language (as highlighting the ? is a minor feature compare to having code folding).

Upgrade all @codemirror and @lezer packages

Main point missing from #12812 is LaTeX highlighting in Markdown cell.

User-facing changes

None

Backwards-incompatible changes

Break API for CodeMirror Mode (compare to 3.x)

@jupyterlab-probot
Copy link

Thanks for making a pull request to jupyterlab!
To try out this branch on binder, follow this link: Binder

);
}
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not removing the file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say we should bring LaTeX highlighting back for ipythongfm mode, as this is feature parity with Notebook v6 and Lab < 4.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I think it deserves a dedicated PR, syntax highlighting for CM6 is very different from CM5 and requires a complete rewriting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the file as it may be useful when working to restore syntax highlighting for CM6.

Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing 🚀

Highlighting some integration-level issues from local testing:

  • I can no longer navigate cells with the cursor (using up and down keys), whereas it works on 4.0.0a34 (and tip of the master branch)
    4.0.0a34 this PR
    navigation-before navigation-after
  • the CodeMirror UI settings shows validation error for me (I would love to double check this on binder but #14033)
    Screenshot from 2023-02-18 13-09-29
    • it is still an improvement compared to the state of things on master (#14011; I edited the description of the PR to link this PR to that issue)
  • smartIndent does not have a label
  • the CodeMirror JSON settings shows "missing schema description"; this is a regression compared to 4.0.0a34 but I am not sure if this works on tip of master branch (again would need a check in a clean environment, #14033):
    4.0.0a34 this PR
    Screenshot from 2023-02-18 13-29-48 Screenshot from 2023-02-18 13-10-09

If you believe that some of the above should be tackled as a follow-up I am happy to approve once these were extracted to separate issues (please ping me for review). Ideally we would add galata tests for the things flagged above.

@fcollonval fcollonval force-pushed the ft/extensible-codemirror-6 branch 2 times, most recently from 3f7ad77 to 709ff0f Compare February 21, 2023 14:52
@fcollonval
Copy link
Member Author

bot please update snapshots

@github-actions
Copy link
Contributor

Documentation snapshots updated.

@github-actions
Copy link
Contributor

Galata snapshots updated.

@fcollonval fcollonval force-pushed the ft/extensible-codemirror-6 branch from 6e90653 to 4c2b63d Compare February 22, 2023 11:17
@krassowski
Copy link
Member

Is this ready to merge?

bot please update playwright snapshots

@schmidi314
Copy link
Contributor

I'm very much looking forward to this merge. But I just noticed that there are some strange defaults set in the code cell settings: Indentation unit is 2 spaces and line numbers are switched on. I'm fine with the line numbers (though it might unnecessarily break user experience) but two-spaces indentation for python is weird.

image

I tried this on binder. It might be related to notebook-extension/schema/tracker.json. It seems the settings have been deleted from there?

@krassowski
Copy link
Member

Good catch, thank you @schmidi314. I would add two observations that can be moved to a separate issue and addressed in a follow up PR:

  1. When switching between tab sizing options the "Default:" shown below appears random:
    default
  2. The "Default:" often gets lost for some reason but it does not happen for other groups of settings I tested:
    Peek 2023-02-25 23-09

Implementation of the new token interfaces

First refactoring of codemirror pkg

Don't get languagePreference in `TextModelFactory`

Remove `Mode` usage

Fix integrity

default content factory is not possible

Extract default extensions to use extensible API

More refactoring

Remove not applicable configuration in CM6

Fix build

Fix tests

Fix handling of language

Update codemirror

Use default python LanguageSupport for `ipython`
Activate more features than using the legacy stream parser

Fix codemirror tests

Fix integrity

Automatic application of license header

Add note in migration guide

Improve CodeMirror default theme

Build dynamically the editor themes menu

Simplify API for extension based on DynamicSetting
See https://github.com/ChromeDevTools/devtools-frontend/blob/e813f07e6a47b39c04c64a409dd08be294432490/front_end/ui/components/text_editor/config.ts#L35

Add cursor blinking rate

Restore custom paste event and D&D on md and raw cells

Add rulers

Rename handler to registry to align with other JLab API

Automatic application of license header

Fix registry rename

Translate default elements

CodeMirror settings

Use the custom settings editor for all editors

Bump minimal codemirror packages

Fix integrity

More fix following rebase

Use displayName for syntax status

Progress towards better configuration

Improve setting editor

Rename EditorLanguageRegistry.parse to highlight

Set up configuration for console

Refactor file editor feature in fileeditor-extension

Automatic application of license header

Fix following rebase

Change default for markdown cell settings

Restore keymap as extension

Move translation to extension factory

Clean binding API

Introduce a extensions registry

Editor binding as immutable extension

Rename `Configuration` in `EditorExtensionRegistry`

Drop themes from factory

Language source of truth is model.mimeType not an option

Restore custom styling

Drop word wrap column

Fix keymap

Remove `CodeEditor.addKeydownHandler`

Explicitly introduce CodeMirror in CodeEditor

Allow providing configuration in `InputArea`
Incidentally allow it in `CodeEditorWrapper` and `CodeEditorViewer`

First self review

Fix syntax status item

Fix indentation status widget

Fix CM unit tests

One more self review

Add test for EditorExtension Registry

Add test for `ExtensionsHandler`

Fix unit tests

Update migration notes

Fix unused

Fix following rebase

Fix the example

Fix integrity check

Fix console tests

Fix examples

Fix missing label

Fix default settings for cells

Fix python * operator

[skip ci] Fix yarn.lock

Update Playwright Snapshots

Update Playwright Snapshots

Fix overflow for raw settings editor

Fix file editor and menus

Fix galata tests

Remove CM keymap from documentation

Update Playwright Snapshots

Update Playwright Snapshots

Fix toggle editor theme

Fix PR following upgrade to rjsf v5

Fix integrity

More update of the migration guide

Fix integrity

Rename `Cell.setEditorConfig` to `Cell.updateEditorConfig`

Improve typing

Easier selector

Fix settings bugs

Fix edge requested

Internalize Yjs binding

Remove unused `documentType`

Fix unit tests

Update Playwright Snapshots

Update snapshots

Improve test robustness

Lint code
@fcollonval fcollonval force-pushed the ft/extensible-codemirror-6 branch from 994be63 to 76c845f Compare February 27, 2023 08:02
@fcollonval
Copy link
Member Author

bot please update snapshots

@github-actions
Copy link
Contributor

Galata snapshots updated.

@fcollonval
Copy link
Member Author

Kicking the CI

@fcollonval
Copy link
Member Author

@schmidi314 and @krassowski thanks for the comments - as we are reaching API freezing day, I'll merge this as is. And I opened #14097 as follow-up from your comments

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.