1 //===- MlirPdllLspServerMain.cpp - MLIR PDLL Language Server main ---------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h"
10 #include "LSPServer.h"
11 #include "PDLLServer.h"
12 #include "mlir/Tools/lsp-server-support/Logging.h"
13 #include "mlir/Tools/lsp-server-support/Transport.h"
14 #include "llvm/Support/CommandLine.h"
15 #include "llvm/Support/Program.h"
18 using namespace mlir::lsp
;
20 LogicalResult
mlir::MlirPdllLspServerMain(int argc
, char **argv
) {
21 llvm::cl::opt
<JSONStreamStyle
> inputStyle
{
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
),
32 llvm::cl::opt
<bool> litTest
{
35 "Abbreviation for -input-style=delimited -pretty -log=verbose. "
36 "Intended to simplify lit tests"),
37 llvm::cl::init(false),
39 llvm::cl::opt
<Logger::Level
> logLevel
{
41 llvm::cl::desc("Verbosity of log messages written to stderr"),
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
),
49 llvm::cl::opt
<bool> prettyPrint
{
51 llvm::cl::desc("Pretty-print JSON output"),
52 llvm::cl::init(false),
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"));
62 llvm::cl::ParseCommandLineOptions(argc
, argv
, "PDLL LSP Language Server");
65 inputStyle
= JSONStreamStyle::Delimited
;
66 logLevel
= Logger::Level::Debug
;
70 // Configure the logger.
71 Logger::setLogLevel(logLevel
);
73 // Configure the transport used for communication.
74 llvm::sys::ChangeStdinToBinary();
75 JSONTransport
transport(stdin
, llvm::outs(), inputStyle
, prettyPrint
);
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
);