From bd31af3d283b3a24c557ead4f6693020aafa1cac Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Wed, 2 Nov 2022 22:18:45 +0800 Subject: [PATCH] feat: Add flag for debugging recorded file paths. --- core/GlobalState.cc | 5 +++++ core/GlobalState.h | 1 + main/options/options.cc | 2 ++ main/options/options.h | 1 + main/options/test/options_test.cc | 1 + main/realmain.cc | 1 + 6 files changed, 11 insertions(+) diff --git a/core/GlobalState.cc b/core/GlobalState.cc index 5faf05bbb..d45bf29c8 100644 --- a/core/GlobalState.cc +++ b/core/GlobalState.cc @@ -1658,6 +1658,9 @@ FileRef GlobalState::enterFile(const shared_ptr &file) { } } }) + if (this->logRecordedFilepaths) { + this->errorQueue->logger.debug("recording file with path: {}", file->path()); + } files.emplace_back(file); auto ret = FileRef(filesUsed() - 1); @@ -1961,6 +1964,7 @@ unique_ptr GlobalState::deepCopy(bool keepId) const { result->silenceErrors = this->silenceErrors; result->unsilenceErrors = this->unsilenceErrors; + result->logRecordedFilepaths = this->logRecordedFilepaths; result->autocorrect = this->autocorrect; result->ensureCleanStrings = this->ensureCleanStrings; result->runningUnderAutogen = this->runningUnderAutogen; @@ -2059,6 +2063,7 @@ unique_ptr GlobalState::copyForIndex() const { result->fileRefByPath = this->fileRefByPath; result->silenceErrors = this->silenceErrors; result->unsilenceErrors = this->unsilenceErrors; + result->logRecordedFilepaths = this->logRecordedFilepaths; result->autocorrect = this->autocorrect; result->ensureCleanStrings = this->ensureCleanStrings; result->runningUnderAutogen = this->runningUnderAutogen; diff --git a/core/GlobalState.h b/core/GlobalState.h index bf4da3d77..27597aae9 100644 --- a/core/GlobalState.h +++ b/core/GlobalState.h @@ -227,6 +227,7 @@ class GlobalState final { int globalStateId; bool silenceErrors = false; bool unsilenceErrors = false; + bool logRecordedFilepaths = false; bool autocorrect = false; // We have a lot of internal names of form `` that's chosen with `<` and `>` as you can't make diff --git a/main/options/options.cc b/main/options/options.cc index 345ba2edc..23270befe 100644 --- a/main/options/options.cc +++ b/main/options/options.cc @@ -442,6 +442,7 @@ buildOptions(const vector>(), "type"); options.add_options("dev")("trace-lexer", "Emit the lexer's token stream in a debug format"); options.add_options("dev")("trace-parser", "Enable bison's parser trace functionality"); + options.add_options("dev")("log-recorded-filepaths", "Emit paths recorded for different files"); options.add_options("dev")("autogen-subclasses-parent", "Parent classes for which generate a list of subclasses. " "This option must be used in conjunction with -p autogen-subclasses", @@ -817,6 +818,7 @@ void readOptions(Options &opts, logger->error("You can't pass both `{}` and `{}`", "--unquiet", "--quiet"); throw EarlyReturnWithCode(1); } + opts.logRecordedFilepaths = raw["log-recorded-filepaths"].as(); opts.autocorrect = raw["autocorrect"].as(); opts.inlineInput = raw["e"].as(); if (opts.autocorrect && opts.silenceErrors && !opts.unsilenceErrors) { diff --git a/main/options/options.h b/main/options/options.h index bf90e97eb..aa0a508d0 100644 --- a/main/options/options.h +++ b/main/options/options.h @@ -158,6 +158,7 @@ struct Options { std::optional suggestUnsafe = std::nullopt; bool silenceErrors = false; bool unsilenceErrors = false; + bool logRecordedFilepaths = false; bool silenceDevMessage = false; bool suggestSig = false; bool suppressNonCriticalErrors = false; diff --git a/main/options/test/options_test.cc b/main/options/test/options_test.cc index 0c1eabe5d..a861eba07 100644 --- a/main/options/test/options_test.cc +++ b/main/options/test/options_test.cc @@ -26,6 +26,7 @@ TEST_CASE("DefaultConstructorMatchesReadOptions") { CHECK_EQ(empty.suggestTyped, opts.suggestTyped); CHECK_EQ(empty.silenceErrors, opts.silenceErrors); CHECK_EQ(empty.unsilenceErrors, opts.unsilenceErrors); + CHECK_EQ(empty.logRecordedFilepaths, opts.logRecordedFilepaths); CHECK_EQ(empty.silenceDevMessage, opts.silenceDevMessage); CHECK_EQ(empty.suggestSig, opts.suggestSig); CHECK_EQ(empty.suppressNonCriticalErrors, opts.suppressNonCriticalErrors); diff --git a/main/realmain.cc b/main/realmain.cc index 6de0b84f1..5ea48aaaa 100644 --- a/main/realmain.cc +++ b/main/realmain.cc @@ -492,6 +492,7 @@ int realmain(int argc, char *argv[]) { gs->silenceErrors = true; } gs->unsilenceErrors = opts.unsilenceErrors; + gs->logRecordedFilepaths = opts.logRecordedFilepaths; if (opts.autocorrect) { gs->autocorrect = true; }