intellij icon indicating copy to clipboard operation
intellij copied to clipboard

Header Search Paths Broken

Open cpsauer opened this issue 5 years ago • 4 comments

Summary: Plugin seems to provide no header search paths to the editor, breaking #include and autocomplete for C++.

Symptoms:

  • All headers #included via non-relative paths are underlined in red ("file not found") in the editor. CMD+click, file details on hover, and build all still work; the file is in the right place and included correctly. Relative paths work fine, since they don't depend on header search paths
  • Not being able to find headers breaks autocomplete for types #included through them.

Suspected Causes The plugin seems to be failing to set any "Header Search paths".

Running "Show Compiler Info" (via Help->Find Action) shows an empty list of "Header Search paths" for all files examined. "Compiler switches" contains isystem/iquote flags for all the correct directories, but that doesn't seem to be enough.

I think I can see where the switches--but not the search paths--are set in BlazeCWorkspace.java.

Platform details that shouldn't matter, but I'll include for completeness: Latest released Android Studio, 4.1.1. Using a working version of the plugin, patched as in #2265 Latest macOS, 11.1. Latest Bazel, 3.7.2 Build setup is Android Library that depends on cc_libraries.

Related to, but not the same as #330, since the switches are not null.

Thanks! Chris (ex-Googler)

P.S. If, in the meantime, anyone knows a workaround for overriding the header search paths and adding them, I'd love to hear it. This is the last major bug we don't have a workaround for.

cpsauer avatar Jan 08 '21 05:01 cpsauer

Okay, figured out the real issue with the plugin causing this problem. (I'd written myself a cross-platform Bazel<->VSCode plugin using clangd, and my newfound knowledge about code completion internals let me back out the issue.)

The problem is this plugin wraps clang in a shell script without properly configuring the code-completion system to understand the wrapping. Then, clangd, which Android Studio (and Jetbrains stuff more generally) uses for C-language-family autocomplete, can't introspect that compiler driver well enough to provide autocomplete.

You can make things work by just disabling the wrapper. Fastest way is to just set the compiler to cppExecutable in the following line. I patched my plugin with that change and everything works correctly. https://github.com/bazelbuild/intellij/blob/3938f3015174e128562abeefdde06ab969aefb40/cpp/src/com/google/idea/blaze/cpp/BlazeConfigurationToolchainResolver.java#L272

If the blaze_compiler.sh wrapper is important and shouldn't be bypassed, passing the wrapped compiler shell script to to JetBrains's bundled clangd via the --query-driver flag should also do the trick. Not sure if there's a way to do that in the plugin API...I definitely didn't see one in the Android Studio settings GUI.

cpsauer avatar Feb 03 '21 08:02 cpsauer

Update: Because I needed this change--and some others--to make the the plugin run, I made a temporary fork.

While we're waiting for an official response, check it out if you want this workaround (and others). https://github.com/hedronvision/bazelbuild-intellij

cpsauer avatar Feb 04 '21 03:02 cpsauer

@cpsauer Thank you so much for the fork! It's working great. Fixes so many of the issues I had with the original plugin.

physxP avatar Aug 08 '22 06:08 physxP

Glad to hear it! You're very welcome, @physxP!

cpsauer avatar Aug 08 '22 07:08 cpsauer