Tips for getting the Eclipse Code Analyzer to not complain
Posted: Thu Aug 18, 2022 12:28 am
I've been using Eclipse since its early days for all my Java, Javascript, C/C++ and Python projects and, like many of you, have been frustrated by Eclipse's inconsistent and sometimes nonsensical Code Analyzer results for files and projects that compile and run just fine. Lately I've been getting flags in source files for issues in different source files. It was so bad earlier this week that I finally had enough and spent an entire day trying to chase down exactly what was causing the Code Analyzer and Indexer to go nuts and I think I now have a working recipe I can share...
These are the things I had to do to get things consistently working. Most of them are solely to make the Indexer and Code Analyzer less confused.
The project I'm working on at the moment has some of my own components, some components from the ESP-IDF examples, external components like lvgl and managed components like the json_generator. I'm now going on 3 days without any issues so I'm keeping my fingers crossed.
I'm sure I missed something but if I think of anything else, I'll update this post.
Good luck!!
- Open your existing Eclipse instance and export your preferences to a safe place.
- I'd suggest taking the opportunity to download and the latest production ESP-IDF (v4.4.2 as of today) but this isn't critical. I actually use the v5.0 development version but it has breaking changes from the v4.x versions so don't jump to it if you're not already using it.
- Download and install the latest Eclipse CDT (2022-06 as of today). Make sure you install it to a location other than your existing installation. This isn't required but it gives you the best chance of success and allows you to keep your current install in case you run into trouble.
- When asked, create a new workspace for the same reasons.
- Install the latest version of the ESP-IDF Eclipse Plugin (2.6.0 as of today)
- From the Espressif menu, run ESP-IDF Install Tools. Don't skip this step even if you're already installed the ESP-IDF from the command line.
- Do NOT install any other plugins at this time and don't import the preferences you exported earlier yet.
- Create a new directory into which you'll copy existing projects for import.
- Copy, don't move or link to, one of your troublesome projects into the new directory. If you're on a Linux distro, rsync is your friend...
- $ rsync -vaHAXx /home/me/my_projects/my_project/. /home/me/my_new_projects/my_project/
- In the new project directory, make sure you can build the project from the command line.
- In the the new project directory, delete the .settings, .project and .cproject directory and files. This will give the project a clean start when you import it into Eclipse. Speaking of which...
- Back in the new Eclipse instance, do an Import, Existing IDF Project.
These are the things I had to do to get things consistently working. Most of them are solely to make the Indexer and Code Analyzer less confused.
- Make sure all C++ header files under your control have the 'hpp' suffix instead of 'h'. Yes, I know it shouldn't matter but it seems to matter to Eclipse.
- Make sure you have no source or header file name duplicates. I had a setup.h file in my main component and a setup.h file in one of my components which seemed to confuse things.
- Do NOT rely on header files in one component to supply declarations for things it doesn't own to other components or the main component. I have an ESP_Common_Component component that has a bunch of useful stuff in it so I added system includes like stdint.h, esp_log.h, esp_err.h, etc. to it's public header file so I didn't have to specify those includes in every other component. Big, big mistake. Directly adding the system Includes into every component and the main project cleared up a ton of issues.
- Don't do a full indexer rebuild unless you absolutely have to. It doesn't know how to rebuild everything from scratch. If you do run it, you'll see more issues than you already had. To get rid of them, just do a build again. The other index options seem to work fine. Speaking of which...
- If you right click on a source file in the project explorer, you'll find an index option called Create Parser Log File. I'll spit out everything it found and, more importantly, everything it wasn't able to resolve. You can use that as guide to search for more issues.
The project I'm working on at the moment has some of my own components, some components from the ESP-IDF examples, external components like lvgl and managed components like the json_generator. I'm now going on 3 days without any issues so I'm keeping my fingers crossed.
I'm sure I missed something but if I think of anything else, I'll update this post.
Good luck!!