MLIR  20.0.0git
TableGenLspServerMain.cpp
Go to the documentation of this file.
1 //===- TableGenLspServerMain.cpp - TableGen 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 "TableGenServer.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::TableGenLspServerMain(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  "tablegen-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  "tablegen-compilation-database",
59  llvm::cl::desc("Compilation YAML databases containing additional "
60  "compilation information for .td files"));
61 
62  llvm::cl::ParseCommandLineOptions(argc, argv, "TableGen 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  TableGenServer::Options options(compilationDatabases, extraIncludeDirs);
79  TableGenServer server(options);
80  return runTableGenLSPServer(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 TableGen related functionality necessary for a language server.
@ 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
llvm::LogicalResult runTableGenLSPServer(TableGenServer &server, JSONTransport &transport)
Run the main loop of the LSP server using the given TableGen server and transport.
Definition: LSPServer.cpp:190
Include the generated interface declarations.
llvm::LogicalResult TableGenLspServerMain(int argc, char **argv)
Implementation for tools like tblgen-lsp-server.