Skip to content

Commit 1b80f86

Browse files
cli: Add flag for showing Clang diagnostics (#160)
1 parent 82618aa commit 1b80f86

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

indexer/CliOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct CliOptions {
2929
std::string temporaryOutputDir;
3030
std::string indexOutputPath;
3131
std::string statsFilePath;
32+
bool showClangDiagnostics;
3233

3334
std::chrono::seconds receiveTimeout;
3435
uint32_t numWorkers;

indexer/Driver.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct DriverOptions {
118118
AbsolutePath compdbPath;
119119
AbsolutePath indexOutputPath;
120120
AbsolutePath statsFilePath;
121+
bool showClangDiagnostics;
121122
size_t numWorkers;
122123
std::chrono::seconds receiveTimeout;
123124
bool deterministic;
@@ -134,8 +135,9 @@ struct DriverOptions {
134135
explicit DriverOptions(std::string driverId, const CliOptions &cliOpts)
135136
: workerExecutablePath(),
136137
projectRootPath(AbsolutePath("/"), RootKind::Project), compdbPath(),
137-
indexOutputPath(), statsFilePath(), numWorkers(cliOpts.numWorkers),
138-
receiveTimeout(cliOpts.receiveTimeout),
138+
indexOutputPath(), statsFilePath(),
139+
showClangDiagnostics(cliOpts.showClangDiagnostics),
140+
numWorkers(cliOpts.numWorkers), receiveTimeout(cliOpts.receiveTimeout),
139141
deterministic(cliOpts.deterministic),
140142
preprocessorRecordHistoryFilterRegex(
141143
cliOpts.preprocessorRecordHistoryFilterRegex),
@@ -229,6 +231,9 @@ struct DriverOptions {
229231
if (!this->statsFilePath.asStringRef().empty()) {
230232
args.push_back("--measure-statistics");
231233
}
234+
if (this->showClangDiagnostics) {
235+
args.push_back("--show-clang-diagnostics");
236+
}
232237
if (!this->preprocessorRecordHistoryFilterRegex.empty()) {
233238
args.push_back(fmt::format("--preprocessor-record-history-filter={}",
234239
this->preprocessorRecordHistoryFilterRegex));

indexer/Worker.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,13 +1056,10 @@ class IndexerFrontendActionFactory
10561056
}
10571057
};
10581058

1059-
class IndexerDiagnosticConsumer : public clang::DiagnosticConsumer {
1059+
class SuppressDiagnosticConsumer : public clang::DiagnosticConsumer {
10601060
public:
10611061
void HandleDiagnostic(clang::DiagnosticsEngine::Level,
1062-
const clang::Diagnostic &) override {
1063-
// Just dropping all diagnostics on the floor for now.
1064-
// FIXME(def: surface-diagnostics)
1065-
}
1062+
const clang::Diagnostic &) override {}
10661063
};
10671064

10681065
} // namespace
@@ -1094,6 +1091,7 @@ WorkerOptions WorkerOptions::fromCliOptions(const CliOptions &cliOptions) {
10941091
compdbPath,
10951092
indexOutputPath,
10961093
statsFilePath,
1094+
cliOptions.showClangDiagnostics,
10971095
cliOptions.logLevel,
10981096
cliOptions.deterministic,
10991097
cliOptions.measureStatistics,
@@ -1199,13 +1197,15 @@ void Worker::processTranslationUnit(SemanticAnalysisJobDetails &&job,
11991197
std::move(args), &frontendActionFactory, fileManager.get(),
12001198
std::make_shared<clang::PCHContainerOperations>());
12011199

1202-
IndexerDiagnosticConsumer diagnosticConsumer;
1203-
invocation.setDiagnosticConsumer(&diagnosticConsumer);
1200+
SuppressDiagnosticConsumer suppressDiagnostics;
1201+
if (!this->options.showClangDiagnostics) {
1202+
invocation.setDiagnosticConsumer(&suppressDiagnostics);
1203+
}
12041204

12051205
{
12061206
LogTimerRAII timer(fmt::format("invocation for {}", job.command.Filename));
12071207
bool ranSuccessfully = invocation.run();
1208-
(void)ranSuccessfully; // FIXME(ref: surface-diagnostics)
1208+
(void)ranSuccessfully;
12091209
}
12101210
}
12111211

indexer/Worker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ struct WorkerOptions {
5959
StdPath indexOutputPath; // only valid if mode == Compdb
6060
StdPath statsFilePath; // only valid if mode == Compdb
6161

62+
bool showClangDiagnostics;
63+
6264
spdlog::level::level_enum logLevel;
6365
bool deterministic;
6466
bool measureStatistics;

indexer/main.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ static scip_clang::CliOptions parseArguments(int argc, char *argv[]) {
4848
"Store temporary files under a specific directory instead of using system APIs."
4949
"If set, this directory will not be deleted after indexing is complete.",
5050
cxxopts::value<std::string>(cliOptions.temporaryOutputDir));
51+
parser.add_options("")(
52+
"show-clang-diagnostics",
53+
"Show Clang diagnostics triggered when running semantic analysis."
54+
" Useful for debugging issues related to missing headers.",
55+
cxxopts::value<bool>(cliOptions.showClangDiagnostics));
5156
parser.add_options("")("h,help", "Show help text", cxxopts::value<bool>());
5257
// TODO(def: add-version): Add a --version flag
5358
parser.add_options("Advanced")(

0 commit comments

Comments
 (0)