This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Enforce rules around "initialize" request, and create ClangdServer lazily.
ClosedPublic

Authored by sammccall on Oct 18 2018, 6:47 AM.

Details

Summary

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.

Event Timeline

sammccall created this revision.Oct 18 2018, 6:47 AM
ioeric accepted this revision.Oct 18 2018, 6:57 AM

Looks good!

This revision is now accepted and ready to land.Oct 18 2018, 6:57 AM
This revision was automatically updated to reflect the committed changes.