Syntax highlighting only for C and CPP questions problem

Syntax highlighting only for C and CPP questions problem

by Adnan Delic -
Number of replies: 7

Hi,

I have a problem only with c and cpp questions in code runner. There is no syntax highlighting only for them. I made a test for Pascal, Java, Python and everything is OK.

I also try to use code snippet suggestion for some keyword with CTRL + space, but that also doesn't work. If I put cursor on white space and hit CTRL + space it only suggest previously declared variables in the written code (img1).

I don't think the problem is in the theme I use for Moodle, because the problem mentioned doesn't occur in other programming languages. I will attach some pictures.

Tested also on production site with same problem.

The program compiles without any background issues and provides answers about which test cases it meets and which doesn't.

Second image is inspect element of page where c-question is loaded. 

Thanks in advance.

Moodle 3.4.9 (Build: 20190513)
Coderunner 3.7.5+

Attachment img1.png
Attachment img2.png
In reply to Adnan Delic

Re: Syntax highlighting only for C and CPP questions problem

by Richard Lobb -

Hi Adnan, thanks for the nice clear bug report.

This appears to be a bug in the Moodle javascript minimiser. The same fault is present on this site (coderunner.org.nz) running Moodle 3.6 but is not present on my Moodle 3.7 and Moodle 3.8 sites.

If you're unable to upgrade your Moodle version, the following workaround hack might work. It seems to have fixed the problem on this site, but it has had minimal testing and I've no idea whether it's a general fix.

Line 448 of the file ace/mode-c_cpp.js in the CodeRunner folder (e.g. /var/www/html/moodle/question/type/coderunner) is currently

    this.lineCommentStart = "//";

I changed that line to the equivalent

    this.lineCommentStart = "/" + "/";

As a Moodle admin, I then used the "Purge all caches" facility and the bug seems to have disappeared!

I don't claim to understand the Moodle JavaScript minimiser -- it's a nightmare consisting of a massive set of regular expressions. Why it should fail on that particular line and not on apparently identical lines in the Java, CSharp and JavaScript mode files, I've no idea.

You might want to try simply purging the caches first, before editing the file; it didn't work for me, but ... who knows?

In reply to Richard Lobb

Re: Syntax highlighting only for C and CPP questions problem

by Adnan Delic -
Thank you Richard so so much.

Modifying the code as you said ACE works perfectly well with c and cpp question type.

Before I post a question on the forum I tried a lot of things related to this problem:

- to apply a custom css for the current theme mentioned in the post on the link https://coderunner.org.nz/mod/forum/discuss.php?d=27,

- also try to change default theme for Moodle but nothing happens.

-From this link: https://github.com/ajaxorg/ace-builds test all ace-builds for ace:

- src
- src-min
- src-noconflict
- src-min-noconflict

Every time I did some changes I always perform clear theme cache and purge all cache, but without success. 

Once again, thanks Richard.

Attachment img1.PNG
In reply to Adnan Delic

Re: Syntax highlighting only for C and CPP questions problem

by Giuliana Barberis -
Hi,
I have the same problem as Adnan but I'm having it with the syntax highlighting for Python (also the indentation doesn't work).
I will attach some pictures.

This problem is not very serious as the program works correctly, but my students asked me why they can't have these features automatically (highlighting and indentation).
So I ask if there is anythng that I can do to fix the problem.

Thanks in advance.

Moodle 4.1.5+ (Build: 20230826)
Coderunner 5.1.1 (2022110900)
In reply to Giuliana Barberis

Re: Syntax highlighting only for C and CPP questions problem

by Richard Lobb -
It looks like Ace isn't in Python mode. If you type Ctrl + ',' (Ctrl + comma) you should bring up the Ace control menu:

Screen shot of Ace menu

What mode is it in?

I'm guessing it won't be Python, so my next questions are then:
  1. Are you using the built-in Python3 question type or a custom question type?
  2. Does syntax colouring etc work with other built-in question types, e.g. C_program, Java_program?
  3. If you click the Customise check box for the question in the authoring form, then open the Advanced Customisation panel, what values do you see for Sandbox language (should be python3) and Ace language (should be empty, so that the Ace uses the sandbox language)?
In reply to Richard Lobb

Re: Syntax highlighting only for C and CPP questions problem

by Giuliana Barberis -
hi Richard thank you very much,
I try to answer your questions:
I use the built-in Python3 question type.
I use also Sql language and there isn't any highlight. To try other languages I tried also with Cpp and there isn't any highlight too.
I tried creating a new question where I checked the customise box and I correctly found language = python3 and Ace language empty.
But I don't understand how can I verify if my Moodle has Ace in Python mode, how do I make appear the window you showed me above?
I'm sorry for my confusion .. but thank you
In reply to Giuliana Barberis

Re: Syntax highlighting only for C and CPP questions problem

by Richard Lobb -
Hi Giuliana

If you're editing code within an Ace window and type the comma key while holding down Ctrl, you should get the menu I've shown above. Is that not working for you? Perhaps try doing that in the demo page on this website to see if it behaves differently from your site as confirmation?

If syntax highlighting isn't working with multiple languages, I think Ace is somewhat broken on your system. Has it ever worked properly in the past? I assume it also doesn't work within the question authoring form (e.g. the sample answer field)?

Ace is packaged into CodeRunner, complete with around 175 different language modes. The full set of modes should be displayed in the mode dropdown in the Ace menu, if you're able to bring that up.

My current guess is that Ace is failing to fetch the mode scripts. If that's the case, you should see an error in the JavaScript console. To check for this, use the Chrome browser, open the Developer Tools page (e.g. type Shift+Ctrl+I) and select the Console tab. Then load a CodeRunner question. What do you see in the Console tab? You might also try selecting the Network tab and reloading. Are there any 404s in there?

I'm struggling to think of a likely cause for this issue, but three vague possibilities are:
  1. The CodeRunner install is corrupted. Updating to the latest version might be worth a try.
  2. The file access permissions are wrongly set within the ace folder of the CodeRunner plugin. 
  3. There's some extra security plugin on your Moodle site that is disallowing the loading of the mode files.

In reply to Richard Lobb

Re: Syntax highlighting only for C and CPP questions problem

by Giuliana Barberis -
Hi Richard,
you are right, Ace is failing to fetch the mode scripts. Here is the printscreen of the javascript console when I try to press ctrl+comma (I updated CodeRunner to the latest version e after this I made this printscreen)
ace error

Until last June I had moodle 3.11 and everything worked correctly, in the Summer I update to Moodle 4.1.5 and I reinstalled the latest version of CodeRunner.
But hear this! Now is everything ok!!
The problem was related to the slash arguments
I had 'Use slash arguments' disabled, I enabled it from Administration > Site administration > Server > Environment and all is gone right.
Thank you for your availability and extreme kindness.