bazelbuild / intellij

IntelliJ plugin for Bazel projects
https://ij.bazel.build/
Apache License 2.0
764 stars 304 forks source link

Header Search Paths Broken #2285

Open cpsauer opened 3 years ago

cpsauer commented 3 years ago

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

Symptoms:

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 commented 3 years ago

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 commented 3 years ago

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

physxP commented 2 years ago

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

cpsauer commented 2 years ago

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