diff --git a/clang-tools-extra/clangd/indexer/IndexerMain.cpp b/clang-tools-extra/clangd/indexer/IndexerMain.cpp --- a/clang-tools-extra/clangd/indexer/IndexerMain.cpp +++ b/clang-tools-extra/clangd/indexer/IndexerMain.cpp @@ -38,6 +38,16 @@ "binary RIFF format")), llvm::cl::init(IndexFileFormat::RIFF)); +static llvm::cl::list QueryDriverGlobs{ + "query-driver", + llvm::cl::desc( + "Comma separated list of globs for white-listing gcc-compatible " + "drivers that are safe to execute. Drivers matching any of these globs " + "will be used to extract system includes. e.g. " + "/usr/bin/**/clang-*,/path/to/repo/**/g++-*"), + llvm::cl::CommaSeparated, +}; + class IndexActionFactory : public tooling::FrontendActionFactory { public: IndexActionFactory(IndexFileIn &Result) : Result(Result) {} @@ -144,12 +154,16 @@ // Collect symbols found in each translation unit, merging as we go. clang::clangd::IndexFileIn Data; + auto Mangler = std::make_shared( + clang::clangd::CommandMangler::detect()); + Mangler->SystemIncludeExtractor = clang::clangd::getSystemIncludeExtractor( + static_cast>( + clang::clangd::QueryDriverGlobs)); auto Err = Executor->get()->execute( std::make_unique(Data), clang::tooling::ArgumentsAdjuster( - [Mangler = std::make_shared( - clang::clangd::CommandMangler::detect())]( - const std::vector &Args, llvm::StringRef File) { + [Mangler = std::move(Mangler)](const std::vector &Args, + llvm::StringRef File) { clang::tooling::CompileCommand Cmd; Cmd.CommandLine = Args; Mangler->operator()(Cmd, File);