Given a simple mistake like
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("\"); // note: " is escaped, so this won't compile
}
This is rendered in Arduino IDE 2.0.3 as
Syntax highlighting in Arduino IDE 2.0
and the problem is hard to spot.
The Jetbrains IDEs have special highlighting for escaped characters like
Special highlighting of escape characters
which makes the problem more obvious because the two quotation marks have different color.
Any chance that this can be configured in the new Arduino IDE 2.0.3 as well?
Because it was asked in the comments: no, the syntax highlighting does not highlight the escaped character when the string is complete. The backslash and quotation mark are both still green.
1 Answer 1
Any chance that this can be configured in the new Arduino IDE 2.0.3 as well?
Yes. You'll need to enable the Arduino language features provided by the language server. They're disabled by default.
- Press F1,
- Type
Preferences: Open Settings (JSON)
, - Press Enter,
- The
settings.json
file opens.
Add the following to the JSON and save it if you do not have auto-save enabled:
{
"arduino.language.realTimeDiagnostics": true
}
My settings.json
with the Arduino language features enabled.
Select a board. You can ignore the port selection if you like. The language feature should start, and you will see the error in the editor.
More details on the Advanced Settings are here.
-
Thanks. Undoubtedly, this is very helpful. The color of the escaped character is still the same, though.Thomas Weller– Thomas Weller2022年12月30日 11:43:53 +00:00Commented Dec 30, 2022 at 11:43
-
In the JetBrains IDE, you wrote
Serial.println("\");
and in the Arduino IDESerial.println("\"); // note: " is escaped, so this won't compile
. Can you please update your question about the syntax coloring in JetBrains with the longer example? Thanks! I compared the built-in C++ extension in VS Code with Arduino IDE, and they behave the same. The compiler error seems valid: Expected expressionclang(expected_expression)
. I do not think you will be able to tweak the syntax highlighting in Arduino IDE.dankeboy36– dankeboy362022年12月30日 12:24:51 +00:00Commented Dec 30, 2022 at 12:24 -
My VSCode has syntax highlighting in strings: i.sstatic.net/Tq9iS.png Haven't used it for a long time, but IMHO I only use it for Typescript, not C++, so I don't think I have any C++ specific extensions installed and it even asks me whether I want to install some..Thomas Weller– Thomas Weller2022年12月30日 12:48:48 +00:00Commented Dec 30, 2022 at 12:48
-
1I did another check and can confirm a bug in the Arduino IDE that does not highlight the regex matches. If there are no compiler errors, VS Code correctly highlights
\d
in the"\d+"
string. Arduino IDE 2.0.3 fails to do it.dankeboy36– dankeboy362022年12月30日 13:27:44 +00:00Commented Dec 30, 2022 at 13:27 -
1One more update. The regex syntax coloring works in the Arduino IDE with both the
Light (Theia)
andDark (Theia)
themes, not with the Arduino ones. Steps to reproduce. Your sketch:void setup() {} void loop() { Serial.println("\d"); }
.\d
is not highlighted. Open settings withCtrl
/⌘
+,
. Select one of the Theia themes from the dropdown, and close the dialog withOK
.\d
is highlighted. If I select any of the Arduino themes, it does not work. This is a theme bug.dankeboy36– dankeboy362022年12月30日 17:33:22 +00:00Commented Dec 30, 2022 at 17:33
"\"
is not a string as it does not have a closing quotation mark.\"
is an escaped character in a string."\"
is an escape"
without closing"
, you might get the correct syntax highlight if you do"\""
.