-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Use tokens to extend CodeMirror editors #13639
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
Use tokens to extend CodeMirror editors #13639
Conversation
|
Thanks for making a pull request to jupyterlab! |
afae538 to
fd42b46
Compare
| ); | ||
| } | ||
| }); | ||
|
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 

- the CodeMirror UI settings shows validation error for me (I would love to double check this on binder but #14033)
- 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)
smartIndentdoes 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 

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.
3f7ad77 to
709ff0f
Compare
|
bot please update snapshots |
|
Documentation snapshots updated. |
|
Galata snapshots updated. |
6e90653 to
4c2b63d
Compare
|
Is this ready to merge? bot please update playwright snapshots |
|
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. I tried this on binder. It might be related to notebook-extension/schema/tracker.json. It seems the settings have been deleted from there? |
|
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: |
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
994be63 to
76c845f
Compare
|
bot please update snapshots |
|
Galata snapshots updated. |
|
Kicking the CI |
|
@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 |



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 fortext/plainis 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.defaultContentFactoryand 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
Languagefortext/plainthat 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,styleSelectedTextandselectionPointer.Add extensions to support
cursorBlinkRate,rulers,showTrailingSpaces,scrollPastEnd.lineWrapis now a simple boolean andwordWrapColumnis 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
@codemirrorand@lezerpackagesMain 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)