FR: Add explicit includes to JUCE modules

Forgive me if this has already been discussed or is common knowledge, but I just wanted to share a tip for dealing with these issues in Visual Studio. I’m still mostly using VS2019, but I believe this should work in 2022 as well.

First, the disclaimer is that sometimes VS just ends up in a weird state with source files in terms of red squiggles, and the technique I’m about to share isn’t 100% foolproof, but it does work for me most of the time.

What I’ve noticed is that when the source code I have open is not being parsed by VS correctly and has tons of red squiggles everywhere, I just have to open the .h and .cpp for the module that the source files belong to. This works for custom user modules as well.

It seems like once source files are opened in a tab, VS starts to parse them in the background on demand and attempts to follow includes and such until it has parsed all related code. But, the problem seems to be that if you just open a JUCE source file that is defined in a module somewhere, because most includes are not defined in that file itself, but rather the module .h/.cpp VS can’t properly follow the include tree. However, if you open the module source .h/.cpp, it can now follow includes, parse them, and when you return to your source file, usually within a few seconds, the squiggles disappear and everything is as it should be.

It’s a little annoying to have to periodically do this, but it’s really not a huge pain to be able to get the source and highlighting into the correct state.

So as an example, if I have a user module (or JUCE module), named my_module, I might have a folder that looks like this (directories denoted by [ ]):

[my_module]
    - my_module.h
    - my_module.cpp
    - my_module.mm
    - [source]
        - my_class.h
        - my_class.cpp

(my_class.h and my_class.cpp should be included in my_module.h and my_module.cpp or this won’t work)

Let’s assume I open my_class.h or my_class.cpp for editing in VS and they are full of red squiggles and not parsed correctly. I can go over to the Solution Explorer in VS, find the shared code project, expand it, expand JUCE Modules, locate the my_module folder, expand it, and then open my_module.h and my_module.cpp for editing in their own tabs - this will start VS parsing the include tree for those module files. Now, switch back to my_class.cpp and my_class.h and with perhaps a little delay (usually a few seconds for me), the squiggles will disappear and the files will be in the correct state. The delay can be longer the more files defined in the module that need to be traversed first.

This is probably common knowledge, but I just wanted to share in the off chance others aren’t aware of the technique. For me it makes a huge difference when coding in Visual Studio, especially working on my own modules.

3 Likes
  • Regarding VS I think we would all see this, however most if us aren’t using that as our main IDE. When we do we tend to turn off errors in intellisense. However, as far I understand, the issue has been addressed in the latest preview version

  • Regarding VS Code no one is using this as their main IDE, but to me this seems the one for which we will most likely need to make the change for

  • Regarding CLion a number of developers are using this as their main IDE however, they just aren’t experiencing the same level of issues you describe. I’m not sure if this is due to running it on particularly well kitted devices, a particular version of CLion, some CLion settings (we discussed this at the time, there was nothing obvious that jumped out to us - maybe something regarding the amount of memory it’s allowed to use?), or something else?

  • Regarding Xcode this is used by some of us as our primary IDE however Xcode has problems regardless of the includes, if it’s being particularly stubborn I find quitting and reopening Xcode resolves the issue

4 Likes

Out of curiosity, what is the most popular IDE JUCE devs are using?

My own experience: VS Code makes a decent enough IDE but it’s a disaster with JUCE modules. Everything is red underscored and Intellisense is completely shafted. This is almost the only thing that prompted me to move to…

CLion. The IDE I’m using now. It can find it’s way around the source code but it’s grinding on indexing almost all of the time. And that’s after throwing 16GB at it (my machine is 32GB).

1 Like

The new beta for CLion Nova (which uses another language model) is much faster and smoother, so try that. It still has bugs, but generally is much nicer resources wise than the ‘classic’ CLion engine.

3 Likes

It seems to be really flakey, but using the vscode command

>C/C++: Select IntelliSense Configuration...

and choosing the option to use the compile_commands.json generated by CMake (requiring the CMAKE_EXPORT_COMPILE_COMMANDS option to be set to true), rather than the CMake extension’s configuration itself sometimes works.

When I say sometimes:

  • It doesn’t seem to work at all for JUCE source files - only my own modules.
  • If you go through the steps with a .cpp file open in the editor, you’ll still see errors. If you then open the top-level header file for the module that .cpp file belongs to you should see no errors in that header, and when you switch back to the .cpp all the errors should go away.
  • The intellisense configuration command doesn’t always show the compile_commands.json option for whatever reason. I usually have to close and reopen vscode and reconfigure CMake a whole bunch of times before it finally shows up.

This isn’t really a solution - there definitely seems to be a problem with how the CMake extension and the C/C++ extension interact - but it may help give some clues as to what the issue is.

2 Likes

Bump. Would be great if some work is put towards explicit includes in JUCE 8. Incrementally adding them would also be appreciated.

4 Likes

I have the same issue using Neovim + clangd. It seems like @eyalamir’s suggested fix would fix this for anyone running an LSP (and perhaps other IDEs).

2 Likes

Bumping again in 2025… it’s time to get this fixed.

6 Likes

It is absolutely insane to me that asking JUCE to adopt standard best practices used in every major C++ codebase, and that should be familiar to any seasoned C++ developer, resulted in a multi-year back-and-forth like this…

12 Likes

Another vote for fixing this. It’s a major workflow issue for those of us that are experienced, and a struggle for a lot of new devs trying to learn the APIs.

4 Likes

I would like to see this fixed :slightly_smiling_face:

1 Like

Maybe I missed it. Is this on the JUCE8 roadmap? I use CMake and VSC on Windows, Mac, Linux, and RPi. While I like the consistency of using one IDE across platforms, it is painful. Is there a step by step workaround? Thanks.

2 Likes

Yeah, I’d like to start using Juce, but I’m using VSCode and all the code having red squiggles in holding me back. I hope it gets fixed soon.

Add the juce library paths to your configuration: C++ extension settings reference

Using CMake, you shouldn’t see any issues with vscode failing to find paths.

Maybe for Projucer users, there could be a vscode “exporter” that can set up the necessary paths, etc. and maybe even add launch configs and whatnot for easy debugging?

1 Like

Yeah I’m also having troubles with red squiggles and auto completion not working, this is pretty hindering as I’m a total newbie in JUCE and would love the ability to be able to see auto completion and what not at the beginning too.

Try the demo of Visual Assist from WholeTomato, it’s very good replacement for Intellisense, and I’ve used every version of it for 25 years!
It also has very nice dark mode code colouring, if you want it!


Try it for free: Features in Visual Assist - Whole Tomato Software

1 Like

As someone who is writing their first serious module, I wanted to present another thing to consider here. I was about to copy the JUCE way of doing things, thinking it was an example of best practices. Now reading all of this, I’m trying to find my way through this to write something the right way. If this is indeed going against industry standard best practices, you may be dragging the quality of work down in the industry. I get that it’s not here to be an educational resource, and you do what you need to in order to make your tooling work, but just remember there are a lot of people using JUCE to learn, so you may want to make sure you are leading by example.

Also, bump!

1 Like

It’s been two years already, how time flies. I guess this was not something which would be done “in a few hours” after all… But has anyone given this a serious shot? Is there a working JUCE fork with explicit includes out there somewhere?

You can spawn an agent and do it all in few prompts. It’s the willingness to do it, not the time.

1 Like