1 //===- MlirLspServerMain.cpp - MLIR 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-lsp-server/MlirLspServerMain.h"
10 #include "LSPServer.h"
11 #include "MLIRServer.h"
12 #include "mlir/IR/Dialect.h"
13 #include "mlir/Tools/lsp-server-support/Logging.h"
14 #include "mlir/Tools/lsp-server-support/Transport.h"
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/Program.h"
19 using namespace mlir::lsp
;
21 LogicalResult
mlir::MlirLspServerMain(int argc
, char **argv
,
22 DialectRegistry
®istry
) {
23 llvm::cl::opt
<JSONStreamStyle
> inputStyle
{
25 llvm::cl::desc("Input JSON stream encoding"),
26 llvm::cl::values(clEnumValN(JSONStreamStyle::Standard
, "standard",
27 "usual LSP protocol"),
28 clEnumValN(JSONStreamStyle::Delimited
, "delimited",
29 "messages delimited by `// -----` lines, "
30 "with // comment support")),
31 llvm::cl::init(JSONStreamStyle::Standard
),
34 llvm::cl::opt
<bool> litTest
{
37 "Abbreviation for -input-style=delimited -pretty -log=verbose. "
38 "Intended to simplify lit tests"),
39 llvm::cl::init(false),
41 llvm::cl::opt
<Logger::Level
> logLevel
{
43 llvm::cl::desc("Verbosity of log messages written to stderr"),
45 clEnumValN(Logger::Level::Error
, "error", "Error messages only"),
46 clEnumValN(Logger::Level::Info
, "info",
47 "High level execution tracing"),
48 clEnumValN(Logger::Level::Debug
, "verbose", "Low level details")),
49 llvm::cl::init(Logger::Level::Info
),
51 llvm::cl::opt
<bool> prettyPrint
{
53 llvm::cl::desc("Pretty-print JSON output"),
54 llvm::cl::init(false),
56 llvm::cl::ParseCommandLineOptions(argc
, argv
, "MLIR LSP Language Server");
59 inputStyle
= JSONStreamStyle::Delimited
;
60 logLevel
= Logger::Level::Debug
;
64 // Configure the logger.
65 Logger::setLogLevel(logLevel
);
67 // Configure the transport used for communication.
68 llvm::sys::ChangeStdinToBinary();
69 JSONTransport
transport(stdin
, llvm::outs(), inputStyle
, prettyPrint
);
71 // Register the additionally supported URI schemes for the MLIR server.
72 URIForFile::registerSupportedScheme("mlir.bytecode-mlir");
74 // Configure the servers and start the main language server.
75 MLIRServer
server(registry
);
76 return runMlirLSPServer(server
, transport
);