Sound great, thanks!
One interesting case in Chromium might be generated jni headers. I would be interested what the heuristic finds for these files:
src/out/Android/gen/chrome/browser/jni_headers/chrome/jni/BrowsingDataBridge_jni.h
Indeed, it doesn’t do well here, but still compiles fine - this seems to be the case when the exact flags used don’t matter much as long as the general project setup is right. Probably quite common in generated files - I guess these tend to have relatively few predictable dependencies, and might prefer unwieldy fully-qualified include paths where a human would add a -I entry. This one includes <jni.h> and “…/…/…/…/…/…/…/…/base/android/jni_generator/jni_generator_helper.h”.
The heuristic fares poorly here because the filename is unique, the last few path components (chrome, jni, jni_headers) are unhelpful in locating related cc files, and the “nearby in the tree” logic doesn’t handle the separate root for genfiles well.
The right file turns out to be e.g. “chrome/browser/android/browsing_data/browsing_data_bridge.cc”. The only useful hints here are chrome/browser (not very specific) and BrowsingDataBridge if we used fuzzy word matching to account for case differences. I’m inclined not to try to solve this case without more data.
The only diagnostics produced are a bunch of “internal linkage… but not defined” where the header forward declares static functions whose implementations are meant to be provided by the including CC file.
This is an artifact of assuming the .h file is standalone, and it seems like a form of non-modularity, but this is a minor issue we can deal with in a few ways and unrelated to the choice of flags.
Relevant logs are:
Chose /usr/local/google/home/sammccall/src/chromium/src/out/Android/gen/chrome/browser/android/proto/client_discourse_context.pb.cc as proxy for /usr/local/google/home/sammccall/src/chromium/src/out/Android/gen/chrome/browser/jni_headers/chrome/jni/BrowsingDataBridge_jni.h
Rebuilding file /usr/local/google/home/sammccall/src/chromium/src/out/Android/gen/chrome/browser/jni_headers/chrome/jni/BrowsingDataBridge_jni.h with command [/usr/local/google/home/sammccall/src/chromium/src/out/Android] …/…/third_party/llvm-build/Release+Asserts/bin/clang++ -x c++ -MMD -MF obj/chrome/browser/client_discourse_context_proto/client_discourse_context.pb.o.d -D V8_DEPRECATION_WARNINGS -D NO_TCMALLOC -D SAFE_BROWSING_DB_REMOTE -D CHROMIUM_BUILD -D FIELDTRIAL_TESTING_ENABLED -D ANDROID -D HAVE_SYS_UIO_H -D ANDROID_NDK_VERSION_ROLL=r16_1 -D CR_CLANG_REVISION=“328575-1” -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D COMPONENT_BUILD -D __GNU_SOURCE=1 -D CHROMIUM_CXX_TWEAK_INLINES -D _DEBUG -D DYNAMIC_ANNOTATIONS_ENABLED=1 -D WTF_USE_DYNAMIC_ANNOTATIONS=1 -D GOOGLE_PROTOBUF_NO_RTTI -D GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER -D HAVE_PTHREAD -D PROTOBUF_USE_DLLS -I …/… -I gen -I …/…/third_party/protobuf/src -I gen/protoc_out -I …/…/third_party/protobuf/src -fno-strict-aliasing --param ssp-buffer-size=4 -fstack-protector -Wno-builtin-macro-redefined -D DATE= -D TIME= -D TIMESTAMP= -funwind-tables -fPIC -pipe -fcolor-diagnostics -no-canonical-prefixes -ffunction-sections -fno-short-enums --target=arm-linux-androideabi -isystem …/…/third_party/android_ndk/sysroot/usr/include/arm-linux-androideabi -D ANDROID_API=16 -D NDK_FPABI= -D HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC=1 -march=armv7-a -mfloat-abi=softfp -mtune=generic-armv7-a -mfpu=neon -mthumb -Wall -Werror -Wextra -Wimplicit-fallthrough -Wthread-safety -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-unneeded-internal-declaration -Wno-inconsistent-missing-override -Wno-undefined-var-template -Wno-nonportable-include-path -Wno-address-of-packed-member -Wno-unused-lambda-capture -Wno-user-defined-warnings -Wno-enum-compare-switch -Wno-null-pointer-arithmetic -Wno-ignored-pragma-optimize -Oz -fno-ident -fdata-sections -ffunction-sections -fomit-frame-pointer -gdwarf-3 -g2 -ggnu-pubnames -fvisibility=hidden -Xclang -load -Xclang …/…/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-ipc -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Wno-undefined-bool-conversion -Wno-tautological-undefined-compare -std=gnu++14 -fno-exceptions -fno-rtti -isystem …/…/third_party/android_ndk/sources/cxx-stl/llvm-libc++/include -isystem …/…/third_party/android_ndk/sources/cxx-stl/llvm-libc++abi/include -isystem …/…/third_party/android_ndk/sources/android/support/include --sysroot=…/…/third_party/android_ndk/sysroot -fvisibility-inlines-hidden -c /usr/local/google/home/sammccall/src/chromium/src/out/Android/gen/chrome/browser/jni_headers/chrome/jni/BrowsingDataBridge_jni.h -resource-dir=/usr/local/google/home/sammccall/llvmbuild/bin/…/lib/clang/7.0.0
(Yes, the -M flags should really be filtered)
the implementation is in:
src/chrome/browser/android/browsing_data/browsing_data_bridge.cc
I don’t think that will get matched.
I don’t really care if code completion works in generated files but at least there shouldn’t be incorrect error messages in vscode. Is it possible to exclude a folder from being analyzed by clangd?
Not currently, it’ll look at anything with a supported extension.
It’s not obvious to me how to manage either heuristically or via configuration in a way that’s easy to use, so unless people have ideas I’d punt on this and try to improve the results instead.