Page MenuHomePhabricator

Add support for Scribunto, JavaScript, CSS, JSON and Vue to CodeMirror 6
Closed, ResolvedPublic

Description

Background

Historically, on the WMF cluster, MediaWiki-extensions-CodeMirror has only been used to highlight wikitext. It however can perfectly also do numerous other languages. While we already have CodeEditor, I'd like to add support for languages that have corresponding content models on the WMF cluster. At first, this is for 3rd party benefit (no need for an extra extension). Longer-term, we may propose to replace CodeEditor entirely in favor of CodeMirror on the WMF cluster.

Checklist

These should take effect only if:

  • $wgCodeMirrorV6 is set, or the "Improved Syntax Highlighting" beta feature is enabled
  • $wgCodeMirrorEnabledModes includes the applicable modes
  • $wgCodeEditorEnabledModes (in CodeEditor) is not set for the applicable mode

Effectively this means Beta users will get CodeMirror instead of Ace/CodeEditor. This gives us time to collect feedback and ensure CodeMirror is a suitable replacement.

  • Add Lua support, loaded on pages with the Scribunto content model
    • Add a linter using Luacheck
  • Add JavaScript support, loaded on pages with the javascript content model
    • Add a linter using ESLint
  • Add CSS support for pages with the css content model
  • Add JSON support for pages with the json content model
  • Add Vue support for pages with the vue content model
  • Performance/optimization review: Reduce RL module count, load workers and other large files via $wgExtensionAssetsPath, etc.
  • Deploy to Beta cluster

Further down the road:

Replacing CodeEditor

This is an idea being toyed with. This is not a formal proposal (yet). Here's a quick list of pros/cons:

Pros

  • User preferences are consistent across all editors (T261118)
  • User experience is more consistent across all editors
  • JavaScript integrations from extensions, gadgets, etc. work the same for all editors (even the 2017 editor, to a degree)
  • Maintenance is simpler as everything is under one roof
  • Users can opt to have syntax highlighting without WikiEditor (i.e. the toolbar), if they so desire
  • Better autocompletion
  • Better linting tools (T373711#10350551)
  • Dark mode support
  • Fully localized

Cons

  • Complete feature parity is unlikely, but we should be able to port over whatever users consider the most important features
  • Fixes something that isn't broken
  • If something in CodeMirror breaks, it may effect editing in all content models (counterpoint to the "pro" above of being able to fix everything at once)

Details

Other Assignee
Bhsd
Related Changes in Gerrit:
SubjectRepoBranchLines +/-
mediawiki/extensions/CodeMirrormaster+130 -24
mediawiki/extensions/CodeMirrormaster+14 -13
mediawiki/extensions/CodeMirrormaster+19 -13
operations/mediawiki-configmaster+2 -0
operations/mediawiki-configmaster+33 -35
mediawiki/extensions/CodeMirrormaster+1 K -36
mediawiki/extensions/CodeMirrormaster+1 K -7 K
mediawiki/extensions/CodeMirrormaster+872 -117
operations/mediawiki-configmaster+39 -4
mediawiki/extensions/JsonConfigmaster+13 -11
mediawiki/extensions/Scribuntomaster+6 -1
mediawiki/extensions/TemplateStylesmaster+6 -1
mediawiki/extensions/Gadgetsmaster+8 -1
mediawiki/extensions/UploadWizardmaster+6 -1
mediawiki/extensions/CodeEditormaster+40 -6
mediawiki/extensions/Gadgetsmaster+73 -2
mediawiki/extensions/UploadWizardmaster+72 -3
mediawiki/extensions/JsonConfigmaster+63 -1
mediawiki/extensions/TemplateStylesmaster+38 -1
integration/configmaster+2 -0
integration/configmaster+1 -0
integration/configmaster+1 -0
mediawiki/extensions/CodeMirrormaster+2 -1
mediawiki/extensions/CodeMirrormaster+848 -21
mediawiki/extensions/Scribuntomaster+67 -0
integration/configmaster+1 -0
mediawiki/extensions/CodeMirrormaster+514 -7 K
mediawiki/extensions/CodeMirrormaster+882 -2
mediawiki/extensions/CodeMirrormaster+966 -11
mediawiki/extensions/CodeEditorwmf/1.44.0-wmf.28+1 -1
mediawiki/extensions/CodeEditormaster+1 -1
mediawiki/extensions/CodeMirrormaster+2 K -18
mediawiki/extensions/CodeMirrormaster+22 -0
mediawiki/extensions/CodeMirrormaster+201 -0
mediawiki/extensions/CodeEditormaster+45 -4
mediawiki/extensions/CodeMirrormaster+26 -44
mediawiki/extensions/CodeMirrormaster+613 -100
integration/configmaster+3 -0
mediawiki/extensions/CodeMirrormaster+167 -27
mediawiki/extensions/CodeMirrormaster+28 -0
mediawiki/extensions/CodeMirrormaster+17 -2
mediawiki/extensions/CodeMirrormaster+42 -20
mediawiki/extensions/CodeMirrormaster+335 -175
Show related patches Customize query in gerrit

Related Objects

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

With CodeMirror, there is now a lot of red waves under word that are not recognised by the browser
Would it be possible to tell browsers not to show these waves inside CodeMirror with Vue, JS, CSS ans Lua contentmodels?

I've filed T412848 and submitted a patch. As an alternative, we could add a preference for spellchecking, if there's any demand for it? Otherwise we'll just hard-code it to disable spellcheck for non-wikitext.

Also, double-clicking at the start or end of a bracket pair (...), [...], or {...} should highlight all the text between the brackets, like it does with CodeEditor.

Neat! I did not realize this existed. I believe we should be able to do this easily enough in CodeMirror. I've filed T412849.

Some UI/UX suggestions, based on comparing with CodeEditor:

CodeMirrorCodeEditor
Screenshot 2025-12-17 at 12.20.02 AM.png (920×850 px, 112 KB)
Screenshot 2025-12-17 at 12.20.42 AM.png (1×892 px, 123 KB)
  • CodeMirror is missing the indentation grid lines which are present in CodeEditor.
  • In the gutter, CodeMirror puts the linter icons to the right of line numbers, creating a lot of empty space when there are no warnings (as in screenshot). CodeEditor puts them to the left of line numbers, which feels more natural.
  • The caret in CodeMirror is thin and sometimes almost invisible. CodeEditor's thick caret seems better.
  • CodeEditor always highlights the active line. In CodeMirror, it is behind advanced preferences and off by default. I think it should be on by default for code.
MusikAnimal changed the status of subtask T412886: Enable active line feature by default in non-wikitext from Open to In Progress.
CodeMirrorCodeEditor
Screenshot 2025-12-17 at 12.20.02 AM.png (920×850 px, 112 KB)
Screenshot 2025-12-17 at 12.20.42 AM.png (1×892 px, 123 KB)

T310833 strikes again! As noted above, the screenshots are not visible :(

CodeMirror is missing the indentation grid lines which are present in CodeEditor.

I've filed T412883: Offer indentation grid lines in CodeMirror. This is not easy per-se as grid lines aren't offered in CM6, but there are various community solutions out there.

It might also be worth noting that the "highlight whitespace" feature might suffice as an alternative, if the code is indented with tabs and not spaces.

In the gutter, CodeMirror puts the linter icons to the right of line numbers, creating a lot of empty space when there are no warnings (as in screenshot). CodeEditor puts them to the left of line numbers, which feels more natural.

T412884: Move linter icons to the left of line numbers

The caret in CodeMirror is thin and sometimes almost invisible. CodeEditor's thick caret seems better.

T412885: Make the CodeMirror caret a bit thicker for readibility

CodeEditor always highlights the active line. In CodeMirror, it is behind advanced preferences and off by default. I think it should be on by default for code.

T412886: Enable active line feature by default in non-wikitext

r1218368 did not include Vue. Was that intentional?

r1218368 did not include Vue. Was that intentional?

No! Though it does remind me we still don't have linting there :/ Neither does CodeEditor, though, so I'll go ahead and enable it.

Change #1219250 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[operations/mediawiki-config@master] Use CodeMirror instead of CodeEditor for beta feature users + vue mode

https://gerrit.wikimedia.org/r/1219250

Change #1219250 merged by jenkins-bot:

[operations/mediawiki-config@master] Use CodeMirror instead of CodeEditor for beta feature users + vue mode

https://gerrit.wikimedia.org/r/1219250

Mentioned in SAL (#wikimedia-operations) [2025-12-18T02:47:01Z] <musikanimal@deploy2002> Started scap sync-world: Backport for [[gerrit:1219250|Use CodeMirror instead of CodeEditor for beta feature users + vue mode (T373711)]]

Mentioned in SAL (#wikimedia-operations) [2025-12-18T02:49:16Z] <musikanimal@deploy2002> musikanimal: Backport for [[gerrit:1219250|Use CodeMirror instead of CodeEditor for beta feature users + vue mode (T373711)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2025-12-18T02:54:15Z] <musikanimal@deploy2002> Finished scap sync-world: Backport for [[gerrit:1219250|Use CodeMirror instead of CodeEditor for beta feature users + vue mode (T373711)]] (duration: 07m 15s)

@SD0001 I can't see the screenshots:

Me too, these two screenshots are restricted.

@MusikAnimal, after our conversation before, let's say that I'm open to try. When it will start working on Beta I'll turn it on and just see how it's going, maybe it will be fine, who knows. I even tried today, thought it's already on, but looks like not yet, CodeMirror already replaced ACE there, but does not work. You can ping me here after the experiment will start, if you're interested.

T310833 strikes again! As noted above, the screenshots are not visible :(

oops, fixed it.

Thanks for creating the subtasks and resolving most of them so quickly!

The caret in CodeMirror is thin and sometimes almost invisible. CodeEditor's thick caret seems better.

This is especially so when the cursor is next to a matching bracket. Adding .cm-cursor { border-left-width: 2px !important; } to my CSS solved it, but I wonder if it can be upstreamed.

Adding .cm-cursor { border-left-width: 2px !important; } to my CSS solved it, but I wonder if it can be upstreamed.

That is T412885. I would backport it but I understand there are no deploys until January 5. I'll be out on sabbatical until March 1, but the fix is there and will ride the first deployment train of 2026.

Same goes for any other changes at this point. I can ask Release Engineering, but I assume we won't be permitted to deploy anything until early January. You will be able to check for improvements on the Beta Cluster in the meantime, however.

Keep the feedback coming! I will be working on CodeMirror for the next week until my computer is shut off on January 1. (But after that you still have Bhsd, SD0001 and whoever else to keep things tidy :)

CodeMirror should turn links in CSS/JavaScript comments (e.g. /* [[link]] */) into clickable links like it does for such links in wikitext, and like already happens when viewing the page, not editing it (i.e. viewing the page directly, showing preview, or viewing an old revision).

@MusikAnimal, after our conversation before, let's say that I'm open to try. When it will start working on Beta I'll turn it on and just see how it's going, maybe it will be fine, who knows. I even tried today, thought it's already on, but looks like not yet, CodeMirror already replaced ACE there, but does not work. You can ping me here after the experiment will start, if you're interested.

Is there something new about when you're turning on the linters? Thank you.

One difference I notice between CodeEditor and CodeMirror when it comes to CSS and JavaScript is that, when you're writing code that's indented (i.e. within one or multiple block statements/functions), if you click "enter" twice to create a blank line between one piece of code and another, CodeMirror gets rid of the tabs from that line, whereas CodeEditor leaves them. I personally don't mind this change, and in my experience dropping the tabs is indeed more typical behavior for CSS/JS editors, but I just wanted to make a note of it.

@MusikAnimal, after our conversation before, let's say that I'm open to try. When it will start working on Beta I'll turn it on and just see how it's going, maybe it will be fine, who knows. I even tried today, thought it's already on, but looks like not yet, CodeMirror already replaced ACE there, but does not work. You can ping me here after the experiment will start, if you're interested.

Is there something new about when you're turning on the linters? Thank you.

Somebody, please? Because last time I checked the linters do not work, do not find programming languages errors, it's just text editor. Thank you.

Somebody, please? Because last time I checked the linters do not work, do not find programming languages errors, it's just text editor. Thank you.

The JavaScript/CSS/JSON/Lua linters work well for me. Have you enabled the "Improved Syntax Highlighting" beta feature?

Somebody, please? Because last time I checked the linters do not work, do not find programming languages errors, it's just text editor. Thank you.

The JavaScript/CSS/JSON/Lua linters work well for me. Have you enabled the "Improved Syntax Highlighting" beta feature?

Thank you for the answer. It was already enabled. Weird. I tried the simplest error, a double field in JSON, like

...
"name": "...",
"name": "...",
...

and didn't get any error.

Thank you for the answer. It was already enabled. Weird. I tried the simplest error, a double field in JSON, like

...
"name": "...",
"name": "...",
...

and didn't get any error.

Unfortunately, we (and official CodeMirror) have only implemented a very basic JSON linter using JSON.parse(). JSON objects with duplicate keys are still valid JSON, so no syntax error will be reported.

I see. I hope, at least all the linters will be ready until the ACE removing, to avoid regression. Thanks again.

I see. I hope, at least all the linters will be ready until the ACE removing, to avoid regression. Thanks again.

Ace editor seems to use a deprecated JSON parser which does not recognize some real syntax problems, such as {"Numbers cannot have leading zeroes": 013}.

Well, if the replacement linter will recognize not just all as before, but more, it's even better. Until then, I hope people will have a choice which editor to use.

A choice is not needed. Forward and onward. We can't hold back for every single thing. If it's good enough for Firefox, Google Chrome and Visual Studio Code, then it's good enough for us, even if it is not completely the same as before.

On the other side, there is a choice now, between ACE and wikieditor, with the "<>" button. And you can simply add the CodeMirror to this wikieditor. So people could continue to enjoy both worlds.

I have created task T413880. I will try to port a latest version of json_parse.js used in Ace.

I have created task T413880. I will try to port a latest version of json_parse.js used in Ace.

Thanks a lot! As a very heavy Mediawiki JSON user, really appreciate it.

I noticed that bracket matching is incorrect inside regex: escaped brackets are matched with unescaped brackets. I do not know if it should be corrected or if bracket matching should be disabled inside regex.

Capture d'écran 2026-01-25 144525.png (69×334 px, 4 KB)

I do not know if it should be corrected or if bracket matching should be disabled inside regex.

Unless we create and nest a regex sublanguage, brackets in regex are just like plain text, so it is unlikely to be corrected. However, I will try to disable it inside regex.

I've told you elsewhere that Regex should be its own content-model, but you're like "yeah, nah, it's gonna be replaced soon," - but that was years ago, and it still hasn't been replaced!

I've told you elsewhere that Regex should be its own content-model, but you're like "yeah, nah, it's gonna be replaced soon," - but that was years ago, and it still hasn't been replaced!

Please feel free to create a task.

... that task is irrelevant to rouge's issue anyway. (T392330)

... that task is irrelevant to rouge's issue anyway. (T392330)

It's totally relevant. If you parse it as Regex as something not Regex - !Regex, then it'll throw all sorts of errors. If you parse Regex as Regex, then it'll work.

Change #1237630 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/CodeMirror@master] CodeMirror: only sync editor font preference for Wikitext

https://gerrit.wikimedia.org/r/1237630

Change #1237630 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirror: only sync editor font preference for Wikitext

https://gerrit.wikimedia.org/r/1237630

Change #1238357 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/CodeMirror@master] CodeMirror: add `mw-editfont-monospace` class to non-Wikitext

https://gerrit.wikimedia.org/r/1238357

Change #1238357 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] CodeMirror: add `mw-editfont-monospace` class to non-Wikitext

https://gerrit.wikimedia.org/r/1238357

MusikAnimal moved this task from Improvement to Done on the MediaWiki-extensions-CodeMirror board.

Declaring this resolved given CodeMirror now supports all languages/content models mentioned.

For actually replacing CodeEditor for all users on the WMF cluster, see T419332: Replacing CodeEditor with CodeMirror by MW 1.46. Please chime in there and/or create subtasks if you can think of any blockers.

Change #1252605 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/CodeMirror@master] bracketMatching: ignore JavaScript RegExp literal

https://gerrit.wikimedia.org/r/1252605

Change #1252605 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] bracketMatching: ignore JavaScript RegExp literal

https://gerrit.wikimedia.org/r/1252605