cancel
Showing results for 
Search instead for 
Did you mean: 

In STM32CubeIDE, why isn't my file syntax highlighted when opened from Project Explorer?

PaulK101
Visitor

So if I open a .cpp file by double clicking in Project Explorer, the syntax is not highlighted:

PaulK101_0-1753802235167.png

But if I have an error, clicking on the file error opens up the file like this (from Problems Tab):

PaulK101_1-1753802308508.png

Both files also open up in the tabs next to each other (as if it doesn't know the file is already open).  

Anyone know if there is a fix or how do I open a .cpp file and have it highlighted?

Thanks

6 REPLIES 6
TDK
Super User

It has to be part of a project in order for the IDE to know what words are functions vs variables vs enums vs defines. Especially with macros, C++ syntax is absurdly complicated. It needs the larger context.

For example, to know that GPIO_PIN_SET is an enum vs GPIO_PIN_6 as a define. The file alone doesn't provide that context.

If you feel a post has answered your question, please click "Accept as Solution".

I just posted a small part of the code, I can't post the entire thing due to NDA, but it is part of a TouchGFX project that was created by TouchGFX Designer.  Should it not already have all that info when the project was created?  

It seems to know when the project loads up, but not when I open a file from Project Explorer.

TDK
Super User

If you open a file, it only has the context of that file. If you open a project that contains that file, then open the file within the project, it will have the full context, as you saw.

Oh, I misunderstood Project Explorer vs Windows Explorer.

Yeah, it should have the context. Probably something specific to your workspace and how you're opening it.

If you feel a post has answered your question, please click "Accept as Solution".

I see that makes sense.  Thank you

I'm just double clicking it from with the STM32CubeIDE Explorer tab.  Tried right clicking and tried all those options also.

Ok, I figured it out.  The files show up in 2 places in Project Explorer.  It is appears in both the project folder and the TouchGFX folder.   However to get the syntax to work, I had to open it up under the Project folder (Application->User->gui), NOT the TouchGFX folder.  Both locations in the tree resolve to the same file, but the one I click determines how it is handled.