Heath Raftery
Heath Raftery

Reputation: 4189

Exclude files from Eclipse Indexing that are included in the build

This question provides good answers to the question of excluding files from indexing that are also excluded from a build. An open question remains: how does one prevent files that are part of the build from populating the code-completion or code-insight functions?

My use-case is a TrueSTUDIO (was System Workbench, was bare Eclipse) project which includes some modules from another project. They are wrapped in safe-to-use stubs and wrappers and should never be called directly. The external modules cannot be edited because they must stay in sync with the other project, so their filenames and other symbols clash confusingly with the current project's. When using code completion to include a header or complete a function name, the filenames and function names of the modules that are not to be used directly appear in the completion lists.

I wish to continue to include the modules in my builds, but not have any of their contents appear in the code-complete/insight features.

I see in Project Properties -> C/C++ General -> Indexer there are options to configure the indexer to use a different build configuration. This is promising, but will probably quickly lead to a indexer that is sorely out of sync with the primary build configuration.

Any advice on a practical method?

Upvotes: 5

Views: 1504

Answers (1)

Jakub
Jakub

Reputation: 156

The only way I found to exclude files from Eclipse indexing is using the abovementioned Indexer-specific build configuration. In my case, it helped with the annoying problem of indexer freezing on .cu (NVidia CUDA) files. This is how it works:

  1. Prepare a new (Indexer-specific) build configuration.
  2. Exclude unwanted source files from this configuration using the Source Location exclude filter.
  3. Let Indexer use this particular build configuration.

Eclipse configuration is a bit tricky with Indexer, so this is a step-by-step guide (as for Eclipse 2021-09):

  1. Preparing a new build configuration:

    • Project->Build Configurations->Manage->New:
      • Give it a name, e.g., "4indexer".
      • Select "Copy settings from" with your preferred configuration. In my case, "Debug" worked just fine.
  2. Excluding unwanted source files:

    • Project->Properties->Paths and Symbols->Source Location:
      • Select "4indexer" as the configuration to be managed on the top of the properties window.
      • Apply an exclusion pattern of your choice. In my case, I added "*.cu" at the end of the "Source Folder Exclusion Patterns" list by clicking Add... button and typing *.cu in the "Add Exclusion Pattern" text field.
  3. Reconfiguring Indexer:

    • Window->Preferences->C/C++->Indexer:
      • Allow any Indexer to work with a project-specific build configuration (it was tricky to figure it out): check the "Use the build configuration specified in the project's indexer settings" radio button.
    • Project->Properties->C/C++ General->Indexer:
      • Check the "Enable project specific settings".
      • Select the new build configuration for your project Indexer: check the "Use a fixed build configuration" and select "4indexer" from the drop-down list below.
      • I also unchecked the "Index source files not included in the build", but I'm not sure if it is necessary.

Sometimes Indexer is trying to reindex a project as you try to reconfigure it, freezing Eclipse. So, I turned it on and off and restarted Eclipse a few times.

Upvotes: 2

Related Questions