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;
89 llvm::json::Object serverCaps{
96 {
"definitionProvider",
true},
97 {
"referencesProvider",
true},
98 {
"documentLinkProvider",
100 {
"resolveProvider",
false},
102 {
"hoverProvider",
true},
105 llvm::json::Object result{
106 {{
"serverInfo", llvm::json::Object{{
"name",
"tblgen-lsp-server"},
107 {
"version",
"0.0.1"}}},
108 {
"capabilities", std::move(serverCaps)}}};
109 reply(std::move(result));
113 shutdownRequestReceived =
true;
127 publishDiagnostics(diagParams);
130 std::optional<int64_t> version =
148 publishDiagnostics(diagParams);
155 Callback<std::vector<Location>> reply) {
156 std::vector<Location> locations;
158 reply(std::move(locations));
162 Callback<std::vector<Location>> reply) {
163 std::vector<Location> locations;
165 reply(std::move(locations));
172 Callback<std::vector<DocumentLink>> reply) {
173 std::vector<DocumentLink> links;
175 reply(std::move(links));
182 Callback<std::optional<Hover>> reply) {
192 LSPServer lspServer(server, transport);
196 messageHandler.
method(
"initialize", &lspServer, &LSPServer::onInitialize);
198 &LSPServer::onInitialized);
199 messageHandler.
method(
"shutdown", &lspServer, &LSPServer::onShutdown);
202 messageHandler.
notification(
"textDocument/didOpen", &lspServer,
203 &LSPServer::onDocumentDidOpen);
204 messageHandler.
notification(
"textDocument/didClose", &lspServer,
205 &LSPServer::onDocumentDidClose);
206 messageHandler.
notification(
"textDocument/didChange", &lspServer,
207 &LSPServer::onDocumentDidChange);
210 messageHandler.
method(
"textDocument/definition", &lspServer,
211 &LSPServer::onGoToDefinition);
212 messageHandler.
method(
"textDocument/references", &lspServer,
213 &LSPServer::onReference);
216 messageHandler.
method(
"textDocument/documentLink", &lspServer,
217 &LSPServer::onDocumentLink);
220 messageHandler.
method(
"textDocument/hover", &lspServer, &LSPServer::onHover);
223 lspServer.publishDiagnostics =
225 "textDocument/publishDiagnostics");
228 if (llvm::Error error = transport.
run(messageHandler)) {
230 llvm::consumeError(std::move(error));
233 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.