|
47 | 47 | #include "Trace.h"
|
48 | 48 | #include "index/CanonicalIncludes.h"
|
49 | 49 | #include "clang/Frontend/CompilerInvocation.h"
|
| 50 | +#include "llvm/ADT/Optional.h" |
50 | 51 | #include "llvm/ADT/ScopeExit.h"
|
51 | 52 | #include "llvm/Support/Errc.h"
|
52 | 53 | #include "llvm/Support/Path.h"
|
@@ -179,6 +180,7 @@ class ASTWorker {
|
179 | 180 | bool blockUntilIdle(Deadline Timeout) const;
|
180 | 181 |
|
181 | 182 | std::shared_ptr<const PreambleData> getPossiblyStalePreamble() const;
|
| 183 | + |
182 | 184 | /// Obtain a preamble reflecting all updates so far. Threadsafe.
|
183 | 185 | /// It may be delivered immediately, or later on the worker thread.
|
184 | 186 | void getCurrentPreamble(
|
@@ -242,7 +244,6 @@ class ASTWorker {
|
242 | 244 | /// Whether the diagnostics for the current FileInputs were reported to the
|
243 | 245 | /// users before.
|
244 | 246 | bool DiagsWereReported = false;
|
245 |
| - /// Size of the last AST |
246 | 247 | /// Guards members used by both TUScheduler and the worker thread.
|
247 | 248 | mutable std::mutex Mutex;
|
248 | 249 | std::shared_ptr<const PreambleData> LastBuiltPreamble; /* GUARDED_BY(Mutex) */
|
@@ -858,9 +859,9 @@ void TUScheduler::runWithAST(
|
858 | 859 | It->second->Worker->runWithAST(Name, std::move(Action));
|
859 | 860 | }
|
860 | 861 |
|
861 |
| -void TUScheduler::runWithPreamble( |
862 |
| - llvm::StringRef Name, PathRef File, PreambleConsistency Consistency, |
863 |
| - llvm::unique_function<void(llvm::Expected<InputsAndPreamble>)> Action) { |
| 862 | +void TUScheduler::runWithPreamble(llvm::StringRef Name, PathRef File, |
| 863 | + PreambleConsistency Consistency, |
| 864 | + Callback<InputsAndPreamble> Action) { |
864 | 865 | auto It = Files.find(File);
|
865 | 866 | if (It == Files.end()) {
|
866 | 867 | Action(llvm::make_error<LSPError>(
|
@@ -893,19 +894,21 @@ void TUScheduler::runWithPreamble(
|
893 | 894 | }
|
894 | 895 |
|
895 | 896 | std::shared_ptr<const ASTWorker> Worker = It->second->Worker.lock();
|
896 |
| - auto Task = [Worker, this](std::string Name, std::string File, |
897 |
| - std::string Contents, |
898 |
| - tooling::CompileCommand Command, Context Ctx, |
899 |
| - decltype(ConsistentPreamble) ConsistentPreamble, |
900 |
| - decltype(Action) Action) mutable { |
| 897 | + auto Task = [Worker, Consistency, |
| 898 | + this](std::string Name, std::string File, std::string Contents, |
| 899 | + tooling::CompileCommand Command, Context Ctx, |
| 900 | + decltype(ConsistentPreamble) ConsistentPreamble, |
| 901 | + decltype(Action) Action) mutable { |
901 | 902 | std::shared_ptr<const PreambleData> Preamble;
|
902 | 903 | if (ConsistentPreamble.valid()) {
|
903 | 904 | Preamble = ConsistentPreamble.get();
|
904 | 905 | } else {
|
905 |
| - // We don't want to be running preamble actions before the preamble was |
906 |
| - // built for the first time. This avoids extra work of processing the |
907 |
| - // preamble headers in parallel multiple times. |
908 |
| - Worker->waitForFirstPreamble(); |
| 906 | + if (Consistency != PreambleConsistency::StaleOrAbsent) { |
| 907 | + // Wait until the preamble is built for the first time, if preamble is |
| 908 | + // required. This avoids extra work of processing the preamble headers |
| 909 | + // in parallel multiple times. |
| 910 | + Worker->waitForFirstPreamble(); |
| 911 | + } |
909 | 912 | Preamble = Worker->getPossiblyStalePreamble();
|
910 | 913 | }
|
911 | 914 |
|
|
0 commit comments