16 #define DEBUG_TYPE "mlir-lsp-server"
27 LSPServer(
MLIRServer &server) : server(server) {}
48 Callback<std::vector<Location>> reply);
50 Callback<std::vector<Location>> reply);
56 Callback<std::optional<Hover>> reply);
62 Callback<std::vector<DocumentSymbol>> reply);
96 bool shutdownRequestReceived =
false;
107 llvm::json::Object serverCaps{
114 {
"completionProvider",
116 {
"allCommitCharacters",
124 {
"resolveProvider",
false},
125 {
"triggerCharacters",
126 {
".",
"%",
"^",
"!",
"#",
"(",
",",
"<",
":",
"[",
" ",
"\"",
"/"}},
128 {
"definitionProvider",
true},
129 {
"referencesProvider",
true},
130 {
"hoverProvider",
true},
134 {
"documentSymbolProvider",
141 serverCaps[
"codeActionProvider"] =
143 ? llvm::json::Object{{
"codeActionKinds",
146 : llvm::json::Value(
true);
148 llvm::json::Object result{
150 llvm::json::Object{{
"name",
"mlir-lsp-server"}, {
"version",
"0.0.0"}}},
151 {
"capabilities", std::move(serverCaps)}}};
152 reply(std::move(result));
156 shutdownRequestReceived =
true;
169 diagParams.diagnostics);
172 publishDiagnostics(diagParams);
175 std::optional<int64_t> version =
193 server.addOrUpdateDocument(
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::optional<Hover>> reply) {
233 Callback<std::vector<DocumentSymbol>> reply) {
234 std::vector<DocumentSymbol> symbols;
236 reply(std::move(symbols));
260 return llvm::any_of(only, [&](StringRef base) {
261 return kind.consume_front(base) &&
262 (
kind.empty() ||
kind.starts_with(
"."));
267 std::vector<CodeAction> actions;
270 reply(std::move(actions));
277 void LSPServer::onConvertFromBytecode(
280 reply(server.convertFromBytecode(params.
uri));
285 reply(server.convertToBytecode(params.
uri));
294 LSPServer lspServer(server);
298 messageHandler.
method(
"initialize", &lspServer, &LSPServer::onInitialize);
300 &LSPServer::onInitialized);
301 messageHandler.
method(
"shutdown", &lspServer, &LSPServer::onShutdown);
304 messageHandler.
notification(
"textDocument/didOpen", &lspServer,
305 &LSPServer::onDocumentDidOpen);
306 messageHandler.
notification(
"textDocument/didClose", &lspServer,
307 &LSPServer::onDocumentDidClose);
308 messageHandler.
notification(
"textDocument/didChange", &lspServer,
309 &LSPServer::onDocumentDidChange);
312 messageHandler.
method(
"textDocument/definition", &lspServer,
313 &LSPServer::onGoToDefinition);
314 messageHandler.
method(
"textDocument/references", &lspServer,
315 &LSPServer::onReference);
318 messageHandler.
method(
"textDocument/hover", &lspServer, &LSPServer::onHover);
321 messageHandler.
method(
"textDocument/documentSymbol", &lspServer,
322 &LSPServer::onDocumentSymbol);
325 messageHandler.
method(
"textDocument/completion", &lspServer,
326 &LSPServer::onCompletion);
329 messageHandler.
method(
"textDocument/codeAction", &lspServer,
330 &LSPServer::onCodeAction);
333 messageHandler.
method(
"mlir/convertFromBytecode", &lspServer,
334 &LSPServer::onConvertFromBytecode);
335 messageHandler.
method(
"mlir/convertToBytecode", &lspServer,
336 &LSPServer::onConvertToBytecode);
339 lspServer.publishDiagnostics =
341 "textDocument/publishDiagnostics");
344 LogicalResult result = success();
345 if (llvm::Error error = transport.
run(messageHandler)) {
347 llvm::consumeError(std::move(error));
350 result = success(lspServer.shutdownRequestReceived);
union mlir::linalg::@1244::ArityGroupAndKind::Kind kind
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)
This class implements all of the MLIR related functionality necessary for a language server.
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.
URI in "file" scheme for a file.
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>.
@ Full
Documents are synced by always sending the full content of the document.
llvm::LogicalResult runMlirLSPServer(MLIRServer &server, JSONTransport &transport)
Run the main loop of the LSP server using the given MLIR server and transport.
Include the generated interface declarations.
bool codeActionStructure
Client supports CodeAction return value for textDocument/codeAction.
bool hierarchicalDocumentSymbol
Client supports hierarchical document symbols.
std::vector< std::string > only
Requested kind of actions to return.
TextDocumentIdentifier textDocument
The document in which the command was invoked.
Range range
The range for which the command was invoked.
CodeActionContext context
Context carrying additional information.
static const llvm::StringLiteral kRefactor
static const llvm::StringLiteral kInfo
static const llvm::StringLiteral kQuickFix
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.
TextDocumentIdentifier textDocument
ClientCapabilities capabilities
The capabilities provided by the client (editor or tool).
This class represents the parameters used when converting between MLIR's bytecode and textual format.
URIForFile uri
The input file containing the bytecode or textual format.
Position start
The range's start position.
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.