86 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h"10#include "LSPServer.h"11#include "TableGenServer.h"12#include "llvm/Support/CommandLine.h"13#include "llvm/Support/LSP/Logging.h"14#include "llvm/Support/LSP/Transport.h"15#include "llvm/Support/Program.h"16 17using namespace mlir;18using namespace mlir::lsp;19 20using llvm::lsp::JSONStreamStyle;21using llvm::lsp::JSONTransport;22using llvm::lsp::Logger;23 24LogicalResult mlir::TableGenLspServerMain(int argc, char **argv) {25 llvm::cl::opt<JSONStreamStyle> inputStyle{26 "input-style",27 llvm::cl::desc("Input JSON stream encoding"),28 llvm::cl::values(clEnumValN(JSONStreamStyle::Standard, "standard",29 "usual LSP protocol"),30 clEnumValN(JSONStreamStyle::Delimited, "delimited",31 "messages delimited by `// -----` lines, "32 "with // comment support")),33 llvm::cl::init(JSONStreamStyle::Standard),34 llvm::cl::Hidden,35 };36 llvm::cl::opt<bool> litTest{37 "lit-test",38 llvm::cl::desc(39 "Abbreviation for -input-style=delimited -pretty -log=verbose. "40 "Intended to simplify lit tests"),41 llvm::cl::init(false),42 };43 llvm::cl::opt<Logger::Level> logLevel{44 "log",45 llvm::cl::desc("Verbosity of log messages written to stderr"),46 llvm::cl::values(47 clEnumValN(Logger::Level::Error, "error", "Error messages only"),48 clEnumValN(Logger::Level::Info, "info",49 "High level execution tracing"),50 clEnumValN(Logger::Level::Debug, "verbose", "Low level details")),51 llvm::cl::init(Logger::Level::Info),52 };53 llvm::cl::opt<bool> prettyPrint{54 "pretty",55 llvm::cl::desc("Pretty-print JSON output"),56 llvm::cl::init(false),57 };58 llvm::cl::list<std::string> extraIncludeDirs(59 "tablegen-extra-dir", llvm::cl::desc("Extra directory of include files"),60 llvm::cl::value_desc("directory"), llvm::cl::Prefix);61 llvm::cl::list<std::string> compilationDatabases(62 "tablegen-compilation-database",63 llvm::cl::desc("Compilation YAML databases containing additional "64 "compilation information for .td files"));65 66 llvm::cl::ParseCommandLineOptions(argc, argv, "TableGen LSP Language Server");67 68 if (litTest) {69 inputStyle = JSONStreamStyle::Delimited;70 logLevel = Logger::Level::Debug;71 prettyPrint = true;72 }73 74 // Configure the logger.75 Logger::setLogLevel(logLevel);76 77 // Configure the transport used for communication.78 llvm::sys::ChangeStdinToBinary();79 JSONTransport transport(stdin, llvm::outs(), inputStyle, prettyPrint);80 81 // Configure the servers and start the main language server.82 TableGenServer::Options options(compilationDatabases, extraIncludeDirs);83 TableGenServer server(options);84 return runTableGenLSPServer(server, transport);85}86