I was trying to make byte a highlighted (blue) keyword in my sketches. So, I tried File>Preferences, but that takes me to this page. Where can I change byte to highlight??
. Thanks. AAHi @AlexA. Arduino IDE 1.x used a syntax highlighting system where arbitrary keywords could be defined by the boards platform authors, and by library authors:
https://arduino.github.io/arduino-cli/latest/library-specification/#keywords
https://arduino.github.io/arduino-cli/latest/platform-specification/#keywordstxt
You can see the definition of the boolean and byte keywords here:
The good thing about the Arduino IDE 1.x keywords system is that it makes the syntax highlighting system accessible to the library and boards platform authors and also adapts the highlighting to the platforms and libraries each user had installed.
However, the IDE 1.x system is incredibly crude. All occurrences of all keywords of all installed libraries are highlighted, regardless of whether the occurrence was actually a use of the object from that library. This means that you could end up with quite a strange sprinkling of coloration across your sketch after you accumulate a significant number of libraries.
The IDE 1.x keywords system was also not used very effectively. The library developers really struggle to get the tab separated data format of the file correct so that it will actually be recognized by Arduino IDE 1.x. Some library authors define keywords inconsistently, forgetting to add new keywords while adding new API components. Some library authors don't bother adding keywords at all.
So you end up with some things in Arduino IDE 1.x being highlighted that shouldn't be and also some things not being highlighted that should be.
Arduino IDE 2.x does not have any support for the keywords system of Arduino IDE 1.x. It instead it uses the "cpp" C++ extension that was originally developed for the incredibly popular VS Code editor/IDE:
This extension provides the IDE with a general understanding of the C++ syntax. byte is a custom type defined by the Arduino core API, not a standard type, so this is why it is not highlighted in Arduino IDE 2.x.
The short answer is that you can't.
The long answer is that it is probably possible, but it would be difficult to do. It is possible to add additional capabilities and modify Arduino IDE 2.x through VS Code extensions. The extensions system is very powerful so it is likely that you could to extend the syntax highlighting system via a custom VS Code extension.
There is information about how the syntax highlighting system works here:
A ton of information is available about writing VS Code extensions (thousands of these extensions have been created by the open source community). If you want to learn how to install extensions in Arduino IDE, the instructions are here:
https://github.com/arduino/arduino-ide/blob/main/docs/advanced-usage.md#3rd-party-themes
(themes are just a specific type of extension, so the theme installation instructions are also applicable to any extension).
byte is an alias for the more official uint8_t: "unsigned 8-bit integer type". That is highlighted, so you could use it instead in your own sketches.
Excellent, that worked!! Thanks a lot.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
