27 : server(server), transport(transport) {}
48 Callback<std::vector<Location>> reply);
50 Callback<std::vector<Location>> reply);
56 Callback<std::vector<DocumentLink>> reply);
62 Callback<std::optional<Hover>> reply);
77 bool shutdownRequestReceived =
false;
88 llvm::json::Object serverCaps{
95 {
"definitionProvider",
true},
96 {
"referencesProvider",
true},
97 {
"documentLinkProvider",
99 {
"resolveProvider",
false},
101 {
"hoverProvider",
true},
104 llvm::json::Object result{
105 {{
"serverInfo", llvm::json::Object{{
"name",
"tblgen-lsp-server"},
106 {
"version",
"0.0.1"}}},
107 {
"capabilities", std::move(serverCaps)}}};
108 reply(std::move(result));
112 shutdownRequestReceived =
true;
127 publishDiagnostics(diagParams);
130 std::optional<int64_t> version =
148 publishDiagnostics(diagParams);
156 Callback<std::vector<Location>> reply) {
157 std::vector<Location> locations;
159 reply(std::move(locations));
163 Callback<std::vector<Location>> reply) {
164 std::vector<Location> locations;
166 reply(std::move(locations));
174 Callback<std::vector<DocumentLink>> reply) {
175 std::vector<DocumentLink> links;
177 reply(std::move(links));
185 Callback<std::optional<Hover>> reply) {
195 LSPServer lspServer(server, transport);
199 messageHandler.
method(
"initialize", &lspServer, &LSPServer::onInitialize);
201 &LSPServer::onInitialized);
202 messageHandler.
method(
"shutdown", &lspServer, &LSPServer::onShutdown);
205 messageHandler.
notification(
"textDocument/didOpen", &lspServer,
206 &LSPServer::onDocumentDidOpen);
207 messageHandler.
notification(
"textDocument/didClose", &lspServer,
208 &LSPServer::onDocumentDidClose);
209 messageHandler.
notification(
"textDocument/didChange", &lspServer,
210 &LSPServer::onDocumentDidChange);
213 messageHandler.
method(
"textDocument/definition", &lspServer,
214 &LSPServer::onGoToDefinition);
215 messageHandler.
method(
"textDocument/references", &lspServer,
216 &LSPServer::onReference);
219 messageHandler.
method(
"textDocument/documentLink", &lspServer,
220 &LSPServer::onDocumentLink);
223 messageHandler.
method(
"textDocument/hover", &lspServer, &LSPServer::onHover);
226 lspServer.publishDiagnostics =
228 "textDocument/publishDiagnostics");
231 if (llvm::Error error = transport.
run(messageHandler)) {
233 llvm::consumeError(std::move(error));
236 return success(lspServer.shutdownRequestReceived);
A transport class that performs the JSON-RPC communication with the LSP client.
llvm::Error run(MessageHandler &handler)
Start executing the JSON-RPC transport.
static void error(const char *fmt, Ts &&...vals)
A handler used to process the incoming transport messages.
void notification(llvm::StringLiteral method, ThisT *thisPtr, void(ThisT::*handler)(const Param &))
void method(llvm::StringLiteral method, ThisT *thisPtr, void(ThisT::*handler)(const Param &, Callback< Result >))
OutgoingNotification< T > outgoingNotification(llvm::StringLiteral method)
Create an OutgoingNotification object used for the given method.
This class implements all of the TableGen related functionality necessary for a language server.
llvm::unique_function< void(const T &)> OutgoingNotification
An OutgoingNotification<T> is a function used for outgoing notifications send to the client.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
@ Incremental
Documents are synced by sending the full content on open.
llvm::LogicalResult runTableGenLSPServer(TableGenServer &server, JSONTransport &transport)
Run the main loop of the LSP server using the given TableGen server and transport.
Include the generated interface declarations.
VersionedTextDocumentIdentifier textDocument
The document that changed.
std::vector< TextDocumentContentChangeEvent > contentChanges
The actual content changes.
TextDocumentIdentifier textDocument
The document that was closed.
TextDocumentItem textDocument
The document that was opened.
Parameters for the document link request.
TextDocumentIdentifier textDocument
The document to provide document links for.
URIForFile uri
The text document's URI.
int64_t version
The version number of this document.
std::string text
The content of the opened text document.
URIForFile uri
The text document's URI.
TextDocumentIdentifier textDocument
The text document.
Position position
The position inside the text document.
int64_t version
The version number of this document.
URIForFile uri
The text document's URI.