15 #include "llvm/ADT/FunctionExtras.h"
16 #include "llvm/ADT/StringMap.h"
19 #define DEBUG_TYPE "pdll-lsp-server"
31 : server(server), transport(transport) {}
52 Callback<std::vector<Location>> reply);
54 Callback<std::vector<Location>> reply);
60 Callback<std::vector<DocumentLink>> reply);
66 Callback<std::optional<Hover>> reply);
72 Callback<std::vector<DocumentSymbol>> reply);
90 Callback<std::vector<InlayHint>> reply);
96 Callback<std::optional<PDLLViewOutputResult>> reply);
111 bool shutdownRequestReceived =
false;
122 llvm::json::Object serverCaps{
129 {
"completionProvider",
131 {
"allCommitCharacters",
132 {
"\t",
"(",
")",
"[",
"]",
"{",
"}",
"<",
">",
133 ":",
";",
",",
"+",
"-",
"/",
"*",
"%",
"^",
134 "&",
"#",
"?",
".",
"=",
"\"",
"'",
"|"}},
135 {
"resolveProvider",
false},
136 {
"triggerCharacters",
137 {
".",
">",
"(",
"{",
",",
"<",
":",
"[",
" ",
"\"",
"/"}},
139 {
"signatureHelpProvider",
141 {
"triggerCharacters", {
"(",
","}},
143 {
"definitionProvider",
true},
144 {
"referencesProvider",
true},
145 {
"documentLinkProvider",
147 {
"resolveProvider",
false},
149 {
"hoverProvider",
true},
150 {
"documentSymbolProvider",
true},
151 {
"inlayHintProvider",
true},
154 llvm::json::Object result{
155 {{
"serverInfo", llvm::json::Object{{
"name",
"mlir-pdll-lsp-server"},
156 {
"version",
"0.0.1"}}},
157 {
"capabilities", std::move(serverCaps)}}};
158 reply(std::move(result));
162 shutdownRequestReceived =
true;
177 publishDiagnostics(diagParams);
180 std::optional<int64_t> version =
198 publishDiagnostics(diagParams);
206 Callback<std::vector<Location>> reply) {
207 std::vector<Location> locations;
209 reply(std::move(locations));
213 Callback<std::vector<Location>> reply) {
214 std::vector<Location> locations;
216 reply(std::move(locations));
224 Callback<std::vector<DocumentLink>> reply) {
225 std::vector<DocumentLink> links;
227 reply(std::move(links));
235 Callback<std::optional<Hover>> reply) {
244 Callback<std::vector<DocumentSymbol>> reply) {
245 std::vector<DocumentSymbol> symbols;
247 reply(std::move(symbols));
273 Callback<std::vector<InlayHint>> reply) {
274 std::vector<InlayHint> hints;
276 reply(std::move(hints));
283 void LSPServer::onPDLLViewOutput(
285 Callback<std::optional<PDLLViewOutputResult>> reply) {
286 reply(server.getPDLLViewOutput(params.
uri, params.
kind));
295 LSPServer lspServer(server, transport);
299 messageHandler.
method(
"initialize", &lspServer, &LSPServer::onInitialize);
301 &LSPServer::onInitialized);
302 messageHandler.
method(
"shutdown", &lspServer, &LSPServer::onShutdown);
305 messageHandler.
notification(
"textDocument/didOpen", &lspServer,
306 &LSPServer::onDocumentDidOpen);
307 messageHandler.
notification(
"textDocument/didClose", &lspServer,
308 &LSPServer::onDocumentDidClose);
309 messageHandler.
notification(
"textDocument/didChange", &lspServer,
310 &LSPServer::onDocumentDidChange);
313 messageHandler.
method(
"textDocument/definition", &lspServer,
314 &LSPServer::onGoToDefinition);
315 messageHandler.
method(
"textDocument/references", &lspServer,
316 &LSPServer::onReference);
319 messageHandler.
method(
"textDocument/documentLink", &lspServer,
320 &LSPServer::onDocumentLink);
323 messageHandler.
method(
"textDocument/hover", &lspServer, &LSPServer::onHover);
326 messageHandler.
method(
"textDocument/documentSymbol", &lspServer,
327 &LSPServer::onDocumentSymbol);
330 messageHandler.
method(
"textDocument/completion", &lspServer,
331 &LSPServer::onCompletion);
334 messageHandler.
method(
"textDocument/signatureHelp", &lspServer,
335 &LSPServer::onSignatureHelp);
338 messageHandler.
method(
"textDocument/inlayHint", &lspServer,
339 &LSPServer::onInlayHint);
342 messageHandler.
method(
"pdll/viewOutput", &lspServer,
343 &LSPServer::onPDLLViewOutput);
346 lspServer.publishDiagnostics =
348 "textDocument/publishDiagnostics");
351 if (llvm::Error error = transport.
run(messageHandler)) {
353 llvm::consumeError(std::move(error));
356 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 PDLL 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>.
llvm::LogicalResult runPdllLSPServer(PDLLServer &server, JSONTransport &transport)
Run the main loop of the LSP server using the given PDLL server and transport.
@ Incremental
Documents are synced by sending the full content on open.
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.
TextDocumentIdentifier textDocument
A parameter literal used in inlay hint requests.
Range range
The visible document range for which inlay hints should be computed.
TextDocumentIdentifier textDocument
The text document.
Represents the parameters used when viewing the output of a PDLL file.
URIForFile uri
The URI of the document to view the output of.
PDLLViewOutputKind kind
The kind of output to generate.
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.