[PATCH] D53398: [clangd] Enforce rules around "initialize" request, and create ClangdServer lazily.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 18 06:48:46 PDT 2018


sammccall created this revision.
sammccall added a reviewer: ioeric.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.

LSP is a slightly awkward map to C++ object lifetimes: the initialize request
is part of the protocol and provides information that doesn't change over the
lifetime of the server.

Until now, we handled this by initializing ClangdServer and ClangdLSPServer
right away, and making anything that can be set in the "initialize" request
mutable.
With this patch, we create ClangdLSPServer immediately, but defer creating
ClangdServer until "initialize". This opens the door to passing the relevant
initialize params in the constructor and storing them immutably.
(That change isn't actually done in this patch).

To make this safe, we have the MessageDispatcher enforce that the "initialize"
method is called before any other (as required by LSP). That way each method
handler can assume Server is initialized, as today.

As usual, while implementing this I found places where our test cases violated
the protocol.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53398

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  test/clangd/exit-with-shutdown.test
  test/clangd/exit-without-shutdown.test
  test/clangd/initialize-sequence.test

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53398.170079.patch
Type: text/x-patch
Size: 7095 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181018/93aebc97/attachment.bin>


More information about the cfe-commits mailing list