MLIR  20.0.0git
MlirPdllLspServerMain.cpp
Go to the documentation of this file.
1 //===- MlirPdllLspServerMain.cpp - MLIR PDLL Language Server main ---------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "LSPServer.h"
11 #include "PDLLServer.h"
14 #include "llvm/Support/CommandLine.h"
15 #include "llvm/Support/Program.h"
16 
17 using namespace mlir;
18 using namespace mlir::lsp;
19 
20 LogicalResult mlir::MlirPdllLspServerMain(int argc, char **argv) {
21  llvm::cl::opt<JSONStreamStyle> inputStyle{
22  "input-style",
23  llvm::cl::desc("Input JSON stream encoding"),
24  llvm::cl::values(clEnumValN(JSONStreamStyle::Standard, "standard",
25  "usual LSP protocol"),
26  clEnumValN(JSONStreamStyle::Delimited, "delimited",
27  "messages delimited by `// -----` lines, "
28  "with // comment support")),
29  llvm::cl::init(JSONStreamStyle::Standard),
30  llvm::cl::Hidden,
31  };
32  llvm::cl::opt<bool> litTest{
33  "lit-test",
34  llvm::cl::desc(
35  "Abbreviation for -input-style=delimited -pretty -log=verbose. "
36  "Intended to simplify lit tests"),
37  llvm::cl::init(false),
38  };
39  llvm::cl::opt<Logger::Level> logLevel{
40  "log",
41  llvm::cl::desc("Verbosity of log messages written to stderr"),
42  llvm::cl::values(
43  clEnumValN(Logger::Level::Error, "error", "Error messages only"),
44  clEnumValN(Logger::Level::Info, "info",
45  "High level execution tracing"),
46  clEnumValN(Logger::Level::Debug, "verbose", "Low level details")),
47  llvm::cl::init(Logger::Level::Info),
48  };
49  llvm::cl::opt<bool> prettyPrint{
50  "pretty",
51  llvm::cl::desc("Pretty-print JSON output"),
52  llvm::cl::init(false),
53  };
54  llvm::cl::list<std::string> extraIncludeDirs(
55  "pdll-extra-dir", llvm::cl::desc("Extra directory of include files"),
56  llvm::cl::value_desc("directory"), llvm::cl::Prefix);
57  llvm::cl::list<std::string> compilationDatabases(
58  "pdll-compilation-database",
59  llvm::cl::desc("Compilation YAML databases containing additional "
60  "compilation information for .pdll files"));
61 
62  llvm::cl::ParseCommandLineOptions(argc, argv, "PDLL LSP Language Server");
63 
64  if (litTest) {
65  inputStyle = JSONStreamStyle::Delimited;
66  logLevel = Logger::Level::Debug;
67  prettyPrint = true;
68  }
69 
70  // Configure the logger.
71  Logger::setLogLevel(logLevel);
72 
73  // Configure the transport used for communication.
74  llvm::sys::ChangeStdinToBinary();
75  JSONTransport transport(stdin, llvm::outs(), inputStyle, prettyPrint);
76 
77  // Configure the servers and start the main language server.
78  PDLLServer::Options options(compilationDatabases, extraIncludeDirs);
79  PDLLServer server(options);
80  return runPdllLSPServer(server, transport);
81 }
static llvm::ManagedStatic< PassManagerOptions > options
A transport class that performs the JSON-RPC communication with the LSP client.
Definition: Transport.h:48
static void setLogLevel(Level logLevel)
Set the severity level of the logger.
Definition: Logging.cpp:17
This class implements all of the PDLL related functionality necessary for a language server.
Definition: PDLLServer.h:40
llvm::LogicalResult runPdllLSPServer(PDLLServer &server, JSONTransport &transport)
Run the main loop of the LSP server using the given PDLL server and transport.
Definition: LSPServer.cpp:283
@ Delimited
Messages are delimited by a '// --—' line. Comment lines start with //.
Definition: Transport.h:43
@ Standard
Encoding per the LSP specification, with mandatory Content-Length header.
Definition: Transport.h:41
Include the generated interface declarations.
llvm::LogicalResult MlirPdllLspServerMain(int argc, char **argv)
Implementation for tools like mlir-pdll-lsp-server.