Skip to content

Comments

ST6RI-766 Update to JupyterLab version 4.x in the Jupyter deployment#696

Merged
seidewitz merged 21 commits intomasterfrom
ST6RI-766
Nov 1, 2025
Merged

ST6RI-766 Update to JupyterLab version 4.x in the Jupyter deployment#696
seidewitz merged 21 commits intomasterfrom
ST6RI-766

Conversation

@TheKorpos
Copy link
Contributor

@TheKorpos TheKorpos commented Oct 2, 2025

This PR includes dependency and code updates for the org.omg.sysml.jupyter.jupyterlab labextension to support Jupyter 4.x. Older versions are no longer supported.

This PR doesn't change how the extension is packaged. Installing it into Jupyter is still possible with jupyter labextension install (which is deprecated but still works in 4.x).

Dependency updates

  • updated dependencies in package.json
    • "@jupyterlab/application": "3.x" -> "4.x"
    • "typescript": "<4.4.0" -> "~5.8.3"
    • "@jupyterlab/codemirror": "^0.0.98" -> ">=4.0"
  • added new dependency
    • "@codemirror/legacy-modes": "^6.3.2"
  • updated compiler options
    • es2018 -> es2023

Code changes

Previously, the syntax highlight was registered by adding a new "mode" to Codemirror. This is no longer an option. Instead, the language has to be registered via IEditorLanguageRegistry by the front-end plugin. Luckily, the underlying parser is still present and can be registered in "legacy" mode, so most of the configuration can be easily ported. However, a new foldService had to be implemented to support code folding between braces ({ ... }).

org.omg.sysml.jupyter.jupyterlab/src/main/

  • plugin.ts – updated the implementation of the front-end plugin
    • language registry is used to register the sysml language
    • editor extension registry is used to register the sysml-fold-extension
  • mode.ts – created a clike parser to replace the CodeMirror mode
    • reused (most of) the configuration from older code
  • fold.ts – implemented sysmlFoldServiceSelection to support code folding

tool-support/syntax-highlighting/jupyter/

  • xtext_grammar_converter.py – removed support for keyword highlighting in classic Jupyter Notebook, Jupyter Lab should always be used instead
  • jupyter/mode_template.js – updated the template for mode.js used by the xtext_grammar_converter

@TheKorpos TheKorpos requested a review from seidewitz October 2, 2025 09:45
@seidewitz seidewitz added this to the 2025-10 milestone Oct 2, 2025
@seidewitz seidewitz self-assigned this Oct 2, 2025
Copy link
Member

@seidewitz seidewitz left a comment

Choose a reason for hiding this comment

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

I noticed that the new extension does not support folding of code between braces. That is, the old mode definition included:

modeProps: {
    fold: ['brace'],
}

but I don't see anything similar in the new sysmlparser definition. If there is no way to do this in the new approach, that is a serious degradation of functionality that I know is commonly used by users.

@seidewitz
Copy link
Member

seidewitz commented Oct 2, 2025

Also, the file org.omg.sysml.jupyter.kernel/src/main/resources/sysml/kernel.js still sets up a CodeMirror mode for classic Jupyter Notebook. Will this still work? Do we even need to support classic Jupyter Notebook anymore?

@TheKorpos
Copy link
Contributor Author

Also, the file org.omg.sysml.jupyter.kernel/src/main/resources/sysml/kernel.js still sets up a CodeMirror mode for classic Jupyter Notebook. Will this still work? Do we even need to support classic Jupyter Notebook anymore?

No, this shouldn't work. I always go for jupyter lab. I'm not sure if there is a high demand for classic Notebook.

@TheKorpos
Copy link
Contributor Author

TheKorpos commented Oct 3, 2025

I noticed that the new extension does not support folding of code between braces. That is, the old mode definition included:

modeProps: {
    fold: ['brace'],
}

but I don't see anything similar in the new sysmlparser definition. If there is no way to do this in the new approach, that is a serious degradation of functionality that I know is commonly used by users.

I've tried adding code folding as an extension in the frontend plugin but I couldn't get it working unfortunately. I couldn't really find any option either that would indicate some easy turn-on.

import {codeFolding, foldGutter} from '@codemirror/language' I tried using these. These seem to create the extensions for the folding. I tried to register these with IEditorExtensionRegistry but it didn't work...

@himi
Copy link
Member

himi commented Oct 3, 2025

I think we need to use foldService for CodeMirror V6.

@seidewitz
Copy link
Member

Also, the file org.omg.sysml.jupyter.kernel/src/main/resources/sysml/kernel.js still sets up a CodeMirror mode for classic Jupyter Notebook. Will this still work? Do we even need to support classic Jupyter Notebook anymore?

No, this shouldn't work. I always go for jupyter lab. I'm not sure if there is a high demand for classic Notebook.

If it is not going to work anyway, we should take it out of the build.

@seidewitz
Copy link
Member

seidewitz commented Oct 3, 2025

I think we need to use foldService for CodeMirror V6.

The problem is that the v6 foldService doesn't work for legacy language support, because it requires real parsing of the language text. As far as I could determine, it is possible to get legacy code folding to work, but one needs to write a routine to determine the scope of the folding (e.g., based on { ... } delimiters). Surprisingly, I couldn't find anything in CodeMirror or otherwise publicly available to do this. I actually got what looked like a pretty good code suggestion from AI (even though using AI for code is against my usual principles!), so I might try seeing if that can work.

In any case, if we can't find a way to get code folding incorporated fairly quickly, I am going to defer this PR to the next sprint. I don't want to deploy it without code folding.

@himi
Copy link
Member

himi commented Oct 6, 2025

We can use foldService with @codemirror/legacy-modes/mode but I do not know how we enable CodeMirror 6 extensions in legacy JupyterLab extensions. (As I said, I already switched to new JupyterLab, Python Wheel-based extension) Anyway, it would not be a simple task.

@seidewitz
Copy link
Member

I am going to remove this PR from the release. We figure out code folding on the next sprint.

@seidewitz seidewitz marked this pull request as draft October 8, 2025 17:55
@seidewitz seidewitz modified the milestones: 2025-09, 2025-10 Oct 24, 2025
@himi
Copy link
Member

himi commented Oct 25, 2025

@seidewitz, I made ST6RI-766-1 branch and could successfully make the fold service work. Can I change the source branch to it?

@seidewitz
Copy link
Member

@seidewitz, I made ST6RI-766-1 branch and could successfully make the fold service work. Can I change the source branch to it?

I was able to get your fold service working. However, while it seems to handle braces in comments and strings correctly, its doesn't properly handle braces in unrestricted names. E.g.:

part p {
    attribute '}';
}

@himi
Copy link
Member

himi commented Oct 25, 2025

Opps. mode.ts define it as 'variable'. I will fix it.

@himi
Copy link
Member

himi commented Oct 25, 2025

I fixed to skip variableNames as well. Could you please check it?

himi and others added 4 commits October 25, 2025 17:54
* fold.ts: Added.  Provide foldService extension via
  sysmlFoldServiceSelection()
* plugin.ts: Register sysmlFoldExtension.
nodes, corresponding to quoted names, as well.
@seidewitz seidewitz marked this pull request as ready for review October 25, 2025 22:02
@seidewitz
Copy link
Member

@himi
Looks good! I merged branch ST6RI-766-1 into ST6RI-766 and changed this PR to a ready status again.

@TheKorpos
Would you be able to review Hisashi's update?

@TheKorpos
Copy link
Contributor Author

@himi Thank you for finishing this up!

The code looks good and seems to work as intended.

I also caught a mistake I made in the packaging that caused some infinite inclusion of the output directory. I managed to get a 50GB tgz as a result... I fixed the issue by re-adding the 'files' field, that I had removed, to the package.json.

@seidewitz
Copy link
Member

One last kind of related thing. In Jupyter 2, when you typed an open brace {, it also included the closed brace }, which were then split when you hit return. Starting with the Jupyter 3 deployment, it no longer worked this way, so that you had to explicitly type a close brace } after entering the nested lines. It seems to be this way with the fold service in Jupyter 4.

Is it possible to restore the old functionality in which braces were automatically inserted in matched pairs?

- Also removed support for highlighting in classic Jupyter Notebook
(i.e., not Jupyter Lab).
@himi
Copy link
Member

himi commented Oct 27, 2025

It seems to be closeBrackets extension of autocomplete and it would be nothing to do with foldServce Does Auto Close Brackets in Settings menu work for you?

@seidewitz
Copy link
Member

It seems to be closeBrackets extension of autocomplete and it would be nothing to do with foldServce Does Auto Close Brackets in Settings menu work for you?

Ah, that does it! I hadn't even noticed that setting. I guess it had been set by default in our old installation.

Thanks!

@seidewitz
Copy link
Member

@himi
I just noticed a strange behavior.

If I create a new notebook and enter something into the first cell, code folding does not seem to be active. If I go on to the second cell, then code folding works in that and subsequent cells. If I save the notebook, close it, and reopen it, then the first cell now has code folding.

Can you reproduce this behavior?

@seidewitz
Copy link
Member

seidewitz commented Oct 27, 2025

It seems to be closeBrackets extension of autocomplete and it would be nothing to do with foldServce Does Auto Close Brackets in Settings menu work for you?

Ah, that does it! I hadn't even noticed that setting. I guess it had been set by default in our old installation.

Thanks!

The problem seems to be that JupyterHub does not preserve the setting of the Auto Close Bracket across stopping and starting of a user's virtual server. In the old JupyterHub deployment on jupyter.openmbee.org, that option was set by default and was always reset on when the virtual server as restarted. On the new JupyterHub deployment on systemsmodeling.com, the option is not set by default and is always reset off when the virtual server as restarted.

I don't know how to change that.

@himi
Copy link
Member

himi commented Oct 28, 2025

could reproduce the issue that the extension added by createConditionalExtension() is not enabled only in the first cell prepared in newly created notebooks. I'm suspecting it is because that factory is not properly evaluated for such cells because by reading the code, that factory is evaluated when new cells are created. I'm guessing it is an issue of JupyterLab.

I found one solution by using createImmutableExtensions() instead of createConditionalExtension(). But we will not be able to configure the editor extensions with settings. Is it ok for you?

It seems I'm missing something. I will investigate more.

himi added 2 commits October 27, 2025 23:52
* fold.ts: Apply foldService to 'plain/text' as well and check the
  language to make sure it is 'sysml'.
@himi
Copy link
Member

himi commented Oct 28, 2025

I found the first cell in newly created notebooks is initialized as 'text/plain' and it won't enable foldService. So I enabled foldSerivce to 'text/plain' as well and check if the language is sysml also in the foldService. For this purpose, I named the language as sysml instead of clike in mode.ts

@TheKorpos
Copy link
Contributor Author

There is a template for mode.ts. That should be updated as well in case mode.ts requires changes.

@himi
Copy link
Member

himi commented Oct 28, 2025

@TheKorpos, thanks. I updated mode.ts and mode_template.ts.

@seidewitz
Copy link
Member

OK, folding works in the first cell now. Thanks!

But that does seem harder than it should be...

@seidewitz seidewitz merged commit f7def18 into master Nov 1, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants