Extension talk:CodeEditor

About this board

False positive syntax error

3
Anerisys (talkcontribs)

The syntax check indicates "Warning: Too many errors. (81% scanned)" on the following code. When removing one "test1();", no error is reported anymore.

// syntax check demo: false positive error
function test1(){ return true }

function test2(){
test1();test1();test1();test1();test1();test1();test1();test1();test1();test1();
test1();test1();test1();test1();test1();test1();test1();test1();test1();test1();
test1();test1();test1();test1();test1();test1();test1();test1();test1();test1();
test1();test1();test1();test1();test1();test1();test1();test1();test1();test1();
test1();test1();test1();test1();test1();test1();test1();test1();test1();test1();
test1();test1();test1();test1();test1();test1();test1();test1();test1();test1();
test1();test1();test1();test1();test1();test1();test1();test1();test1();test1();
test1();test1();test1();test1();test1();test1();test1();test1();test1();test1();
test1();test1();test1();test1();test1();test1();test1();test1();test1();test1();
test1();test1();test1();test1();test1();test1();test1();test1();test1();
}
Jdforrester (WMF) (talkcontribs)

Yes, jshint is pretty poor. T250315 is a proposal to replace it with eslint which has much better behaviour in general, and might (?) fix your problem here, but some people are concerned that switching will change which "false positives" (and new true positives) are flagged. Your input would be welcome if you think this would fix it or otherwise be a good move.

Anerisys (talkcontribs)

I tested it again and the error appears to have been repaired. No syntax error is reported, even if I add multiple times as many test1(); as before. Thanks much!

Reply to "False positive syntax error"

"unset" causes a warning in the CSS editor

1
Summary by Anerisys

Looks like the reason for this is browser compatibility.

Anerisys (talkcontribs)

For example, width: unset; and border: unset; cause a warning that reads "Expected … but found 'unset' ".

It is no major issue, since it does not refuse saving it, but the false error still needs to be removed at some point.

How to enable Lua syntax checks?

8
Xxmarijnw (talkcontribs)

On mediawiki.org, invalid Lua code is highlighted using a red squiggle. This does not seem to be enabled by default, and I can't figure out how to enable it on my wiki. How do I enable syntax checks for Lua code?

Sokote zaman (talkcontribs)
Xxmarijnw (talkcontribs)

That is not helpful. I obviously have Scribunto installed and working, but I do not get any syntax checks. Entering invalid Lua code reports no errors in the CodeEditor window.

Sokote zaman (talkcontribs)

Installing lua alone is not enough. You must also configure its engine. Both methods come in the Extension installation guide

Xxmarijnw (talkcontribs)

My Scribunto installation works, and I have configured LuaSandbox. Invoking modules works fine, but error reporting in the CodeEditor does not.

Sokote zaman (talkcontribs)

Can you find a page called Scribunto Can you create a page called Module:HelloWorld?

Xxmarijnw (talkcontribs)

I have already made and used a number of modules. They work fine.

Sokote zaman (talkcontribs)
Reply to "How to enable Lua syntax checks?"
Nicolas senechal (talkcontribs)

Hello, I don't know why but my codeEditor disappeared from visualEditor and wikiEditor, maybe because I put other extensions. So here is my list of extensions (from localSettings).

wfLoadExtension( 'AdvancedSearch' );

wfLoadExtension( 'ApprovedRevs' );

wfLoadExtension( 'BetaFeatures' );

wfLoadExtension( 'CirrusSearch' );

wfLoadExtension( 'CodeEditor' );

$wgDefaultUserOptions['usebetatoolbar'] = 1;

$wgScribuntoUseCodeEditor = false;

wfLoadExtension( 'CodeMirror' );

wfLoadExtension( 'DeleteBatch' );

wfLoadExtension( 'Echo' );

wfLoadExtension( 'Elastica' );

wfLoadExtension( 'Gadgets' );

wfLoadExtension( 'Highlightjs_Integration-master' );

wfLoadExtension( 'mediawiki-extensions-Cargo-3.0' );

wfLoadExtension( 'MultimediaViewer' );

wfLoadExtension( 'SandboxLink' );

wfLoadExtension( 'Scribunto' );

wfLoadExtension( 'TemplateData' );

wfLoadExtension( 'TemplateSandbox' );

wfLoadExtension( 'TemplateStyles' );

wfLoadExtension( 'TemplateWizard' );

wfLoadExtension( 'VisualEditor' );

wfLoadExtension( 'WikiEditor' );

Any help are appreciated.

TheDJ (talkcontribs)
Nicolas senechal (talkcontribs)

It's weird I don't have any error, but I have some last testing that I did. It's just like it's not displayed.

185.148.164.137 (talkcontribs)

I try with the minimum configuration so it can't be the configuration and I look again errors I don't have an error, I don't know how to fix it...

Any help is appreciated.


Nicolas Senechal

Nicolas senechal (talkcontribs)

I check with another php version, with the same configuration it don't work...


very strange because when I start it work so I realy don't know...

Reply to "Code editor and visualEditor"

Documentation Update & additional Namespaces

2
DesignerThan (talkcontribs)

Hello,

maybe someone with knowledge of this extension can update the Documentation? As I had to find out, the config Variables have no effect anymore. That would be great. Also it would be nice to have an option, to add additional namespaces where the extension should work i. e. Templates ...

DesignerThan (talkcontribs)

I got it working in the Template Namespace. The problem was, that the content model was on "wikitext". That is changeable over the Pageinformation link in the tools. There the content model needs to be changed to "Sanitized CSS", this option is only available if the Extension is activated.

Reply to "Documentation Update & additional Namespaces"

How to get the code editor on regular pages?

2
Summary by Kghbln

Works as expected: "Provides a syntax-highlighting code editor for site & user JS, CSS and Lua pages" // No code editor on regular wiki pages, i.e. wiki pages with the "wikitext" content model.

Kghbln (talkcontribs)

I have the following configuration:

wfLoadExtension( 'CodeEditor' );
wfLoadExtension( 'WikiEditor' );
$wgDefaultUserOptions['usebetatoolbar'] = 1;

I get the code editor on pages with a content model out of the box if it is e.g. "json", "css" etc. How do I get this code editor on pages with the content model "wikitext"?

From the very basic docu I understand that I should get some extra button for the wiki editor however I cannot find it.

Not sure what to do. A hint is appreciated. Thanks.

I am on MW 1.31.x

Kghbln (talkcontribs)

Ok, I guess I can self answer: "Provides a syntax-highlighting code editor for site & user JS, CSS and Lua pages".

Rail01 (talkcontribs)

Hey!

I recently found out that Ace editor has settings menu available under ctrl + , keyboard shortcut where users can switch between editor themes available by default and other options, but none of these is then preserved neither as a preference or at least in browser storage.

Can this be changed? Or at least can you tell me whether it's possible to alter these settings using JavaScript?

Thank you.


Small update: I managed how to alter some Ace session settings with codeEditor.config hook, but this isn't really a solution. Session instance only handles some basic settings such as tab size and whether to wrap text what is useful but doesn't replace actual extension's support for Ace settings manager.

Second update: I figured it out

Reply to "Settings preservation"

Change CodeEditor font to monospaced

2
3Qvery (talkcontribs)

How to change CodeEditor font?

I expect monospaced font. However, CodeEditor showed me proportional font (normal sans-serif font). But WikiEditor showed me is monospaced font. In setting, it is also monospaced font.

The worst thing is that, if I click some place at CodeEditor, the cursor indicator (the vertical bar) will show on the exactly monospaced font place. So that, if I use mouse to select some text, it showed to me and actually it selected are not same. I have to change back to WikiEditor to edit some text, but it is not available to input the tab in WikiEditor. So it is not convenient.

Thanks!

Whatamidoing (WMF) (talkcontribs)
Reply to "Change CodeEditor font to monospaced"

How to set the content of the textbox?

9
He7d3r (talkcontribs)

If I go to https://en.wikipedia.org/wiki/Special:MyPage/common.js?action=edit and type $('#wpTextbox1').val('NEWCODE') in the console:

  • The code is replaced by "NEWCODE" if CodeEditor is disabled
  • Nothing happens if CodeEditor is enabled

What should be used to set the content of the textbox if CodeEditor is enabled? I know from en:Special:Diff/617061684 that we can get the contents by using

  • $( '#wpTextbox1' ).data( 'wikiEditor-context' ).$textarea.textSelection( 'getContents' ) or
  • $( '#wpTextbox1' ).textSelection( 'getContents' )

But I have no idea what to use to set the content...

Mxn (talkcontribs)
var editor = $(".ace_editor");
editor[0].env.document.setValue("// This is awesome!");
editor[0].env.editor.selectAll();
TheDJ (talkcontribs)

This would allow you to use the Surface of the ace editor directly yes. It is the interface that our textSelection plugin ought to be talking to really....

He7d3r (talkcontribs)
TheDJ (talkcontribs)

Yeah, the textSelection plugin basically abstracts away browser differences when it comes to dealing with text areas. The CodeEditor plugin uses a totally different text surface. You should see #wpTextbox1 here more as the form value, then a input field in the case of CodeEditor. It has a basic implementation of textSelection API, which allows it to 'communicate' it's value trough the text area object, but it uses a totally different text surface to draw the value.

The textSelection plugin is not fully implemented however (neither for textareas nor for CodeEditor). Notably the 'setContents' method is missing, which would be used for what you describe. But ou can select and then insert characters in the selection (encapsulateSelection allows this).

Some links: https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/resources%2Fsrc%2Fjquery%2Fjquery.textSelection.js#L58 https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FCodeEditor.git/c9499815539390beff23527dc968465c30d4ec92/modules%2Fjquery.codeEditor.js#L522

We ought to improve this at some point. The textSelection plugin is a remnant of the iframe wikicode highlighting experiment of the 2010 WikiEditor that got cancelled, so it hasn't seen too much action since then. It's currently only used for special character insertion.

He7d3r (talkcontribs)

For future reference: the setContents function was implemented in gerrit:149529.

However I didn't figure out how to use it as a solution for the initial problem. None of these work if CodeEditor is enabled:

  • $( '#wpTextbox1' ).textSelection( 'setContents', 'TESTING' )
  • $( '#wpTextbox1' ).data( 'wikiEditor-context' ).$textarea.textSelection( 'setContents', 'TESTING' )
Reply to "How to set the content of the textbox?"
Beyond doubt (talkcontribs)

CodeEditor supports lua on pages in the "Module" namespace.

however, many times you'd like to test your module on a subpage of your user page before publishing it, like you often do with templates and articles. The Extension TemplateSandbox already support testing modules with names from the form "User:myusername/Module:modulename", but when you try to edit a page in that name, you have to do it with the regular wiki editor.

That problem does not exist with js and css pages because they are being identified by their extension, not their namespace.

I think that code editor should be available in modules that are subpages of a user page.

I have also opened a ticket in https://phabricator.wikimedia.org/T217508

Thanks.

Beyond doubt (talkcontribs)

I have suggested a code change in scribunto extension in the foregoing phabricator ticket.

It worked to me, I believe it should enter to the extension code.

Reply to "CodeEditor on lua subpages"
Return to "CodeEditor" page.