15 #include "llvm/ADT/FunctionExtras.h"
16 #include "llvm/ADT/StringMap.h"
29 : server(server), transport(transport) {}
50 Callback<std::vector<Location>> reply);
52 Callback<std::vector<Location>> reply);
58 Callback<std::vector<DocumentLink>> reply);
64 Callback<std::optional<Hover>> reply);
79 bool shutdownRequestReceived =
false;
90 llvm::json::Object serverCaps{
97 {
"definitionProvider",
true},
98 {
"referencesProvider",
true},
99 {
"documentLinkProvider",
101 {
"resolveProvider",
false},
103 {
"hoverProvider",
true},
106 llvm::json::Object result{
107 {{
"serverInfo", llvm::json::Object{{
"name",
"tblgen-lsp-server"},
108 {
"version",
"0.0.1"}}},
109 {
"capabilities", std::move(serverCaps)}}};
110 reply(std::move(result));
114 shutdownRequestReceived =
true;
129 publishDiagnostics(diagParams);
132 std::optional<int64_t> version =
150 publishDiagnostics(diagParams);
158 Callback<std::vector<Location>> reply) {
159 std::vector<Location> locations;
161 reply(std::move(locations));
165 Callback<std::vector<Location>> reply) {
166 std::vector<Location> locations;
168 reply(std::move(locations));
176 Callback<std::vector<DocumentLink>> reply) {
177 std::vector<DocumentLink> links;
179 reply(std::move(links));
187 Callback<std::optional<Hover>> reply) {
197 LSPServer lspServer(server, transport);
201 messageHandler.
method(
"initialize", &lspServer, &LSPServer::onInitialize);
203 &LSPServer::onInitialized);
204 messageHandler.
method(
"shutdown", &lspServer, &LSPServer::onShutdown);
207 messageHandler.
notification(
"textDocument/didOpen", &lspServer,
208 &LSPServer::onDocumentDidOpen);
209 messageHandler.
notification(
"textDocument/didClose", &lspServer,
210 &LSPServer::onDocumentDidClose);
211 messageHandler.
notification(
"textDocument/didChange", &lspServer,
212 &LSPServer::onDocumentDidChange);
215 messageHandler.
method(
"textDocument/definition", &lspServer,
216 &LSPServer::onGoToDefinition);
217 messageHandler.
method(
"textDocument/references", &lspServer,
218 &LSPServer::onReference);
221 messageHandler.
method(
"textDocument/documentLink", &lspServer,
222 &LSPServer::onDocumentLink);
225 messageHandler.
method(
"textDocument/hover", &lspServer, &LSPServer::onHover);
228 lspServer.publishDiagnostics =
230 "textDocument/publishDiagnostics");
233 if (llvm::Error error = transport.
run(messageHandler)) {
235 llvm::consumeError(std::move(error));
238 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.