diff --git a/mlir/lib/Tools/CMakeLists.txt b/mlir/lib/Tools/CMakeLists.txt --- a/mlir/lib/Tools/CMakeLists.txt +++ b/mlir/lib/Tools/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(lsp-server-support) add_subdirectory(mlir-lsp-server) add_subdirectory(mlir-opt) add_subdirectory(mlir-reduce) diff --git a/mlir/lib/Tools/lsp-server-support/CMakeLists.txt b/mlir/lib/Tools/lsp-server-support/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/lib/Tools/lsp-server-support/CMakeLists.txt @@ -0,0 +1,11 @@ +add_mlir_library(MLIRLspServerSupportLib + Logging.cpp + Protocol.cpp + Transport.cpp + + ADDITIONAL_HEADER_DIRS + ${MLIR_MAIN_INCLUDE_DIR}/mlir/Tools/lsp-server + + LINK_LIBS PUBLIC + MLIRSupport + ) diff --git a/mlir/lib/Tools/mlir-lsp-server/lsp/Logging.h b/mlir/lib/Tools/lsp-server-support/Logging.h rename from mlir/lib/Tools/mlir-lsp-server/lsp/Logging.h rename to mlir/lib/Tools/lsp-server-support/Logging.h --- a/mlir/lib/Tools/mlir-lsp-server/lsp/Logging.h +++ b/mlir/lib/Tools/lsp-server-support/Logging.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LIB_MLIR_TOOLS_MLIRLSPSERVER_LSP_LOGGING_H -#define LIB_MLIR_TOOLS_MLIRLSPSERVER_LSP_LOGGING_H +#ifndef LIB_MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H +#define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H #include "mlir/Support/LLVM.h" #include "llvm/Support/Debug.h" @@ -30,13 +30,16 @@ /// Initiate a log message at various severity levels. These should be called /// after a call to `initialize`. - template static void debug(const char *fmt, Ts &&... vals) { + template + static void debug(const char *fmt, Ts &&...vals) { log(Level::Debug, fmt, llvm::formatv(fmt, std::forward(vals)...)); } - template static void info(const char *fmt, Ts &&... vals) { + template + static void info(const char *fmt, Ts &&...vals) { log(Level::Info, fmt, llvm::formatv(fmt, std::forward(vals)...)); } - template static void error(const char *fmt, Ts &&... vals) { + template + static void error(const char *fmt, Ts &&...vals) { log(Level::Error, fmt, llvm::formatv(fmt, std::forward(vals)...)); } @@ -59,4 +62,4 @@ } // namespace lsp } // namespace mlir -#endif // LIB_MLIR_TOOLS_MLIRLSPSERVER_LSP_LOGGING_H +#endif // LIB_MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H diff --git a/mlir/lib/Tools/mlir-lsp-server/lsp/Logging.cpp b/mlir/lib/Tools/lsp-server-support/Logging.cpp rename from mlir/lib/Tools/mlir-lsp-server/lsp/Logging.cpp rename to mlir/lib/Tools/lsp-server-support/Logging.cpp diff --git a/mlir/lib/Tools/mlir-lsp-server/lsp/Protocol.h b/mlir/lib/Tools/lsp-server-support/Protocol.h rename from mlir/lib/Tools/mlir-lsp-server/lsp/Protocol.h rename to mlir/lib/Tools/lsp-server-support/Protocol.h --- a/mlir/lib/Tools/mlir-lsp-server/lsp/Protocol.h +++ b/mlir/lib/Tools/lsp-server-support/Protocol.h @@ -20,8 +20,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LIB_MLIR_TOOLS_MLIRLSPSERVER_LSP_PROTOCOL_H_ -#define LIB_MLIR_TOOLS_MLIRLSPSERVER_LSP_PROTOCOL_H_ +#ifndef LIB_MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H_ +#define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H_ #include "mlir/Support/LLVM.h" #include "llvm/ADT/Optional.h" @@ -644,7 +644,8 @@ } // namespace mlir namespace llvm { -template <> struct format_provider { +template <> +struct format_provider { static void format(const mlir::lsp::Position &pos, raw_ostream &os, StringRef style) { assert(style.empty() && "style modifiers for this type are not supported"); diff --git a/mlir/lib/Tools/mlir-lsp-server/lsp/Protocol.cpp b/mlir/lib/Tools/lsp-server-support/Protocol.cpp rename from mlir/lib/Tools/mlir-lsp-server/lsp/Protocol.cpp rename to mlir/lib/Tools/lsp-server-support/Protocol.cpp diff --git a/mlir/lib/Tools/mlir-lsp-server/lsp/Transport.h b/mlir/lib/Tools/lsp-server-support/Transport.h rename from mlir/lib/Tools/mlir-lsp-server/lsp/Transport.h rename to mlir/lib/Tools/lsp-server-support/Transport.h --- a/mlir/lib/Tools/mlir-lsp-server/lsp/Transport.h +++ b/mlir/lib/Tools/lsp-server-support/Transport.h @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LIB_MLIR_TOOLS_MLIRLSPSERVER_LSP_TRANSPORT_H_ -#define LIB_MLIR_TOOLS_MLIRLSPSERVER_LSP_TRANSPORT_H_ +#ifndef LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_ +#define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_ #include "Logging.h" #include "Protocol.h" diff --git a/mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp b/mlir/lib/Tools/lsp-server-support/Transport.cpp rename from mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp rename to mlir/lib/Tools/lsp-server-support/Transport.cpp diff --git a/mlir/lib/Tools/mlir-lsp-server/CMakeLists.txt b/mlir/lib/Tools/mlir-lsp-server/CMakeLists.txt --- a/mlir/lib/Tools/mlir-lsp-server/CMakeLists.txt +++ b/mlir/lib/Tools/mlir-lsp-server/CMakeLists.txt @@ -1,7 +1,4 @@ add_mlir_library(MLIRLspServerLib - lsp/Logging.cpp - lsp/Protocol.cpp - lsp/Transport.cpp LSPServer.cpp MLIRServer.cpp MlirLspServerMain.cpp @@ -11,5 +8,6 @@ LINK_LIBS PUBLIC MLIRIR + MLIRLspServerSupportLib MLIRParser ) diff --git a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp --- a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp @@ -7,10 +7,10 @@ //===----------------------------------------------------------------------===// #include "LSPServer.h" +#include "../lsp-server-support/Logging.h" +#include "../lsp-server-support/Protocol.h" +#include "../lsp-server-support/Transport.h" #include "MLIRServer.h" -#include "lsp/Logging.h" -#include "lsp/Protocol.h" -#include "lsp/Transport.h" #include "llvm/ADT/FunctionExtras.h" #include "llvm/ADT/StringMap.h" diff --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp --- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "MLIRServer.h" -#include "lsp/Logging.h" -#include "lsp/Protocol.h" +#include "../lsp-server-support/Logging.h" +#include "../lsp-server-support/Protocol.h" #include "mlir/IR/FunctionInterfaces.h" #include "mlir/IR/Operation.h" #include "mlir/Parser/AsmParserState.h" @@ -38,8 +38,7 @@ } /// Returns a language server location from the given source range. -static lsp::Location getLocationFromLoc(llvm::SourceMgr &mgr, - SMRange range, +static lsp::Location getLocationFromLoc(llvm::SourceMgr &mgr, SMRange range, const lsp::URIForFile &uri) { return lsp::Location{uri, getRangeFromLoc(mgr, range)}; } @@ -82,8 +81,7 @@ // Use range of potential identifier starting at location, else length 1 // range. location->range.end.character += 1; - if (Optional range = - AsmParserState::convertIdLocToRange(loc)) { + if (Optional range = AsmParserState::convertIdLocToRange(loc)) { auto lineCol = sourceMgr.getLineAndColumn(range->End); location->range.end.character = std::max(fileLoc.getColumn() + 1, lineCol.second - 1); @@ -134,9 +132,8 @@ } // Check the uses. - const auto *useIt = llvm::find_if(def.uses, [&](const SMRange &range) { - return contains(range, loc); - }); + const auto *useIt = llvm::find_if( + def.uses, [&](const SMRange &range) { return contains(range, loc); }); if (useIt != def.uses.end()) { if (overlappedRange) *overlappedRange = *useIt; @@ -188,8 +185,7 @@ /// Given a block and source location, print the source name of the block to the /// given output stream. -static void printDefBlockName(raw_ostream &os, Block *block, - SMRange loc = {}) { +static void printDefBlockName(raw_ostream &os, Block *block, SMRange loc = {}) { // Try to extract a name from the source location. Optional text = getTextFromRange(loc); if (text && text->startswith("^")) { @@ -288,10 +284,9 @@ Optional buildHoverForOperation(SMRange hoverRange, const AsmParserState::OperationDefinition &op); - lsp::Hover buildHoverForOperationResult(SMRange hoverRange, - Operation *op, unsigned resultStart, - unsigned resultEnd, - SMLoc posLoc); + lsp::Hover buildHoverForOperationResult(SMRange hoverRange, Operation *op, + unsigned resultStart, + unsigned resultEnd, SMLoc posLoc); lsp::Hover buildHoverForBlock(SMRange hoverRange, const AsmParserState::BlockDefinition &block); lsp::Hover diff --git a/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp b/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp --- a/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp @@ -7,10 +7,10 @@ //===----------------------------------------------------------------------===// #include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h" +#include "../lsp-server-support/Logging.h" +#include "../lsp-server-support/Transport.h" #include "LSPServer.h" #include "MLIRServer.h" -#include "lsp/Logging.h" -#include "lsp/Transport.h" #include "mlir/IR/Dialect.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Program.h"