[clangd] Cancel certain operations if the file changes before we start.
authorSam McCall <sam.mccall@gmail.com>
Wed, 4 Mar 2020 13:04:17 +0000 (14:04 +0100)
committerSam McCall <sam.mccall@gmail.com>
Wed, 4 Mar 2020 23:10:07 +0000 (00:10 +0100)
commitc627b120eb8b7add3f9cf893721335c367d9f037
treea82d170c8e9fe3b9ffc66a834a7a465278646302
parenteadea7868f5b7542ee6bdcd9a975697a0c919ffc
[clangd] Cancel certain operations if the file changes before we start.

Summary:
Otherwise they can force us to build lots of snapshots that we don't need.
Particularly, try to do this for operations that are frequently
generated by editors without explicit user interaction, and where
editing the file makes the result less useful. (Code action
enumeration is a good example).

https://github.com/clangd/clangd/issues/298

This doesn't return the "right" LSP error code (ContentModified) to the client,
we need to teach the cancellation API to distinguish between different causes.

Reviewers: kadircet

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, jfb, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75602
clang-tools-extra/clangd/Cancellation.cpp
clang-tools-extra/clangd/Cancellation.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/JSONTransport.cpp
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/TUScheduler.h
clang-tools-extra/clangd/unittests/CancellationTests.cpp
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp