This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Allow all LSP methods to signal cancellation via $/cancelRequest
ClosedPublic

Authored by sammccall on Sep 12 2018, 2:11 PM.

Details

Summary

The cancelable scopes are managed by JSONRPCDispatcher so that all Handlers
run in cancelable contexts.
(Previously ClangdServer did this, for code completion only).

Cancellation request processing is therefore also in JSONRPCDispatcher.
(Previously it was in ClangdLSPServer).

This doesn't actually make any new commands *respect* cancellation - they'd
need to check isCancelled() and bail out. But it opens the door to doing
this incrementally, and putting such logic in common machinery like TUScheduler.

I also rewrote the ClangdServer class/threading comments because I wanted to
add to it and I got carried away.

Event Timeline

sammccall created this revision.Sep 12 2018, 2:11 PM

Wonder if we can still keep the onCancelRequest registry within ProtocolHandler's scope, so that it is clear that we implement it. Other than that seems fascinating, thanks!

clangd/JSONRPCDispatcher.cpp
246

Maybe we can say something about this method is actually being invoked in a sync manner and the reason why we have mutex below is due to context destruction of the thread we might spawn later on. Because it bugged me at first look not having this line under mutex as well, then I noticed actually this was still a sync function.

248

maybe limit the Lock's scope just to put element into map.

sammccall updated this revision to Diff 165253.Sep 13 2018, 4:57 AM
sammccall marked 2 inline comments as done.

rebase and address comments

sammccall updated this revision to Diff 165255.Sep 13 2018, 5:14 AM

Update ClangdLSPServer comment, document cancelRequest further.

Wonder if we can still keep the onCancelRequest registry within ProtocolHandler's scope, so that it is clear that we implement it. Other than that seems fascinating, thanks!

Hmm, I'm not sure how to do that while keeping things simple. I've updated the documentation on ClangdLSPServer and JSONRPCDispatcher to try to clarify instead. PTAL

clangd/JSONRPCDispatcher.cpp
246

Ah. Renamed this variable, commented the access, renamed the mutex to make it clear it's only for the map.
(The mutex itself has a comment about the fact that the *cleanups* are what happen off-thread)

kadircet accepted this revision.Sep 13 2018, 5:39 AM

LGTM, thanks!

This revision is now accepted and ready to land.Sep 13 2018, 5:39 AM
This revision was automatically updated to reflect the committed changes.