summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/ClangdServer.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-11-22 15:39:54 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-11-22 15:39:54 +0000
commitc76394bc4b74b3104654ade5c0e87afcba13d6cd (patch)
tree16a9c40c0a1c30d571265298427ba091edd42cbe /clang-tools-extra/clangd/ClangdServer.cpp
parentc0ac4bb17cb88956a0e12eedfbfc237ec532249b (diff)
downloadbcm5719-llvm-c76394bc4b74b3104654ade5c0e87afcba13d6cd.tar.gz
bcm5719-llvm-c76394bc4b74b3104654ade5c0e87afcba13d6cd.zip
[clangd] Cleanup: make diagnostics callbacks from TUScheduler non-racy
Summary: Previously, removeDoc followed by an addDoc to TUScheduler resulted in racy diagnostic responses, i.e. the old dianostics could be delivered to the client after the new ones by TUScheduler. To workaround this, we tracked a version number in ClangdServer and discarded stale diagnostics. After this commit, the TUScheduler will stop delivering diagnostics for removed files and the workaround in ClangdServer is not required anymore. Reviewers: sammccall Reviewed By: sammccall Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, jfb, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54829 llvm-svn: 347468
Diffstat (limited to 'clang-tools-extra/clangd/ClangdServer.cpp')
-rw-r--r--clang-tools-extra/clangd/ClangdServer.cpp26
1 files changed, 3 insertions, 23 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 8d925d7cdca..03ebcc60a27 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -133,19 +133,17 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
void ClangdServer::addDocument(PathRef File, StringRef Contents,
WantDiagnostics WantDiags) {
- DocVersion Version = ++InternalVersion[File];
ParseInputs Inputs = {getCompileCommand(File), FSProvider.getFileSystem(),
Contents.str()};
-
Path FileStr = File.str();
WorkScheduler.update(File, std::move(Inputs), WantDiags,
- [this, FileStr, Version](std::vector<Diag> Diags) {
- consumeDiagnostics(FileStr, Version, std::move(Diags));
+ [this, FileStr](std::vector<Diag> Diags) {
+ DiagConsumer.onDiagnosticsReady(FileStr,
+ std::move(Diags));
});
}
void ClangdServer::removeDocument(PathRef File) {
- ++InternalVersion[File];
WorkScheduler.remove(File);
}
@@ -444,24 +442,6 @@ void ClangdServer::findHover(PathRef File, Position Pos,
WorkScheduler.runWithAST("Hover", File, Bind(Action, std::move(CB)));
}
-void ClangdServer::consumeDiagnostics(PathRef File, DocVersion Version,
- std::vector<Diag> Diags) {
- // We need to serialize access to resulting diagnostics to avoid calling
- // `onDiagnosticsReady` in the wrong order.
- std::lock_guard<std::mutex> DiagsLock(DiagnosticsMutex);
- DocVersion &LastReportedDiagsVersion = ReportedDiagnosticVersions[File];
-
- // FIXME(ibiryukov): get rid of '<' comparison here. In the current
- // implementation diagnostics will not be reported after version counters'
- // overflow. This should not happen in practice, since DocVersion is a
- // 64-bit unsigned integer.
- if (Version < LastReportedDiagsVersion)
- return;
- LastReportedDiagsVersion = Version;
-
- DiagConsumer.onDiagnosticsReady(File, std::move(Diags));
-}
-
tooling::CompileCommand ClangdServer::getCompileCommand(PathRef File) {
trace::Span Span("GetCompileCommand");
Optional<tooling::CompileCommand> C = CDB.getCompileCommand(File);
OpenPOWER on IntegriCloud