diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -75,8 +75,6 @@ const CanonicalIncludes &CanonIncludes) override { if (FIndex) FIndex->updatePreamble(Path, Version, Ctx, std::move(PP), CanonIncludes); - if (ServerCallbacks) - ServerCallbacks->onSemanticsMaybeChanged(Path); } void onMainAST(PathRef Path, ParsedAST &AST, PublishFn Publish) override { @@ -105,6 +103,11 @@ ServerCallbacks->onFileUpdated(File, Status); } + void onPreamblePublished(PathRef File) override { + if (ServerCallbacks) + ServerCallbacks->onSemanticsMaybeChanged(File); + } + private: FileIndex *FIndex; ClangdServer::Callbacks *ServerCallbacks; diff --git a/clang-tools-extra/clangd/TUScheduler.h b/clang-tools-extra/clangd/TUScheduler.h --- a/clang-tools-extra/clangd/TUScheduler.h +++ b/clang-tools-extra/clangd/TUScheduler.h @@ -169,6 +169,11 @@ /// Called whenever the TU status is updated. virtual void onFileUpdated(PathRef File, const TUStatus &Status) {} + + /// Preamble for the TU have changed. This might imply new semantics (e.g. + /// different highlightings). Any actions on the file are guranteed to see new + /// preamble after the callback. + virtual void onPreamblePublished(PathRef File) {} }; /// Handles running tasks for ClangdServer and managing the resources (e.g., diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -909,6 +909,7 @@ ASTPeer.updatePreamble(std::move(Req.CI), std::move(Req.Inputs), LatestBuild, std::move(Req.CIDiags), std::move(Req.WantDiags)); + Callbacks.onPreamblePublished(FileName); }); if (!LatestBuild || Inputs.ForceRebuild) {