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;
121 llvm::json::Object serverCaps{
128 {
"completionProvider",
130 {
"allCommitCharacters",
131 {
"\t",
"(",
")",
"[",
"]",
"{",
"}",
"<",
">",
132 ":",
";",
",",
"+",
"-",
"/",
"*",
"%",
"^",
133 "&",
"#",
"?",
".",
"=",
"\"",
"'",
"|"}},
134 {
"resolveProvider",
false},
135 {
"triggerCharacters",
136 {
".",
">",
"(",
"{",
",",
"<",
":",
"[",
" ",
"\"",
"/"}},
138 {
"signatureHelpProvider",
140 {
"triggerCharacters", {
"(",
","}},
142 {
"definitionProvider",
true},
143 {
"referencesProvider",
true},
144 {
"documentLinkProvider",
146 {
"resolveProvider",
false},
148 {
"hoverProvider",
true},
149 {
"documentSymbolProvider",
true},
150 {
"inlayHintProvider",
true},
153 llvm::json::Object result{
154 {{
"serverInfo", llvm::json::Object{{
"name",
"mlir-pdll-lsp-server"},
155 {
"version",
"0.0.1"}}},
156 {
"capabilities", std::move(serverCaps)}}};
157 reply(std::move(result));
161 shutdownRequestReceived =
true;
175 publishDiagnostics(diagParams);
178 std::optional<int64_t> version =
196 publishDiagnostics(diagParams);
203 Callback<std::vector<Location>> reply) {
204 std::vector<Location> locations;
206 reply(std::move(locations));
210 Callback<std::vector<Location>> reply) {
211 std::vector<Location> locations;
213 reply(std::move(locations));
220 Callback<std::vector<DocumentLink>> reply) {
221 std::vector<DocumentLink> links;
223 reply(std::move(links));
230 Callback<std::optional<Hover>> reply) {
238 Callback<std::vector<DocumentSymbol>> reply) {
239 std::vector<DocumentSymbol> symbols;
241 reply(std::move(symbols));
264 Callback<std::vector<InlayHint>> reply) {
265 std::vector<InlayHint> hints;
267 reply(std::move(hints));
273 void LSPServer::onPDLLViewOutput(
275 Callback<std::optional<PDLLViewOutputResult>> reply) {
276 reply(server.getPDLLViewOutput(params.
uri, params.
kind));
285 LSPServer lspServer(server, transport);
289 messageHandler.
method(
"initialize", &lspServer, &LSPServer::onInitialize);
291 &LSPServer::onInitialized);
292 messageHandler.
method(
"shutdown", &lspServer, &LSPServer::onShutdown);
295 messageHandler.
notification(
"textDocument/didOpen", &lspServer,
296 &LSPServer::onDocumentDidOpen);
297 messageHandler.
notification(
"textDocument/didClose", &lspServer,
298 &LSPServer::onDocumentDidClose);
299 messageHandler.
notification(
"textDocument/didChange", &lspServer,
300 &LSPServer::onDocumentDidChange);
303 messageHandler.
method(
"textDocument/definition", &lspServer,
304 &LSPServer::onGoToDefinition);
305 messageHandler.
method(
"textDocument/references", &lspServer,
306 &LSPServer::onReference);
309 messageHandler.
method(
"textDocument/documentLink", &lspServer,
310 &LSPServer::onDocumentLink);
313 messageHandler.
method(
"textDocument/hover", &lspServer, &LSPServer::onHover);
316 messageHandler.
method(
"textDocument/documentSymbol", &lspServer,
317 &LSPServer::onDocumentSymbol);
320 messageHandler.
method(
"textDocument/completion", &lspServer,
321 &LSPServer::onCompletion);
324 messageHandler.
method(
"textDocument/signatureHelp", &lspServer,
325 &LSPServer::onSignatureHelp);
328 messageHandler.
method(
"textDocument/inlayHint", &lspServer,
329 &LSPServer::onInlayHint);
332 messageHandler.
method(
"pdll/viewOutput", &lspServer,
333 &LSPServer::onPDLLViewOutput);
336 lspServer.publishDiagnostics =
338 "textDocument/publishDiagnostics");
341 if (llvm::Error error = transport.
run(messageHandler)) {
343 llvm::consumeError(std::move(error));
346 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.