Howto: Grey-out any code excluded by pre-processor directives?

Would anyone know if there's a setting to tell the IDE to grey-out any lines in a file that are excluded by pre-processor directives such as #if and #ifdef ?

I'm not aware of this capability. (it's more involved that it seems - requires to run part of the compile process)

Indeed - clearly needs to run the pre-processor (including digging through all the #includes). But it is an IDE, so it's not beyond possible. Downside could be the lag.

yeah almost every new character entered would require to relaunch the preprocessing

also the symbol can be passed at compile time .... (e.g. gcc's -D ).

Well... it could cache any #defines if finds in #includes (but caching adds its own headaches of course). Or (more robustly) it could be a process that's run/updated on-demand only.

Edit: Hmmm.. -D and other environment variables. Hadn't thought of that one!

discussions on vscode about this

seems they offered a way to deactivate this.. may be not as useful as they thought

Yeah, I saw that post while I was digging around for any mention of the feature in Arduino IDE. It does highlight the problem that, even if a feature like this works 99.9% of the time, there'll still be times it doesn't work. And that means a bug. Which is distracting for the IDE's developers. And having bugs - even in 'experimental' features - is never a good look for a package.

OTOH... the fact that the IDE itself would find it difficult to correctly grey-out excluded lines demonstrates how hard it is to work out what code is included and what code isn't. Which indicates just how very useful it would be to the user, if it could be made to work.

Yes, I have used IDEs that perform far more complex checking than this. For example using IntelliJ IDE for coding in Scala. And it is very laggy.

Fortunately, the lag never stops you from working. Keystrokes and mouse clicks are not lost. But it can be many seconds before the IDE realizes you may have made an error or there is something it needs to warn you about. That lag can be annoying. Worse still, it can immediately highlight something you typed as an error, and then several seconds later figures out it was not a problem after all!

But despite the lagginess, its a great feature to have!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.