internal/lsp/protocol: handle cancellation delivery

$/cancelRequest is handled out of band in the Request flow, but was
allowed to continue down the Deliver chain. There's no sense in letting
downstream Handlers see it and try to reply like it was a normal
request.

Fixes golang/go#36662.

Change-Id: I8471ac0fdd4f2a08acd87d6e4b83c1f077eb8600
Reviewed-on: https://go-review.googlesource.com/c/tools/+/215738
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/internal/lsp/protocol/protocol.go b/internal/lsp/protocol/protocol.go
index c30e57f..9f950a3 100644
--- a/internal/lsp/protocol/protocol.go
+++ b/internal/lsp/protocol/protocol.go
@@ -64,6 +64,11 @@
 	return true
 }
 
+func (canceller) Deliver(ctx context.Context, r *jsonrpc2.Request, delivered bool) bool {
+	// Hide cancellations from downstream handlers.
+	return r.Method == "$/cancelRequest"
+}
+
 func NewClient(ctx context.Context, stream jsonrpc2.Stream, client Client) (context.Context, *jsonrpc2.Conn, Server) {
 	ctx = WithClient(ctx, client)
 	conn := jsonrpc2.NewConn(stream)