[Mlir-commits] [mlir] 7bc5273 - [mlir][NFC] Move the LSP agnostic files to a new lsp-server directory

River Riddle llvmlistbot at llvm.org
Thu Mar 17 00:05:09 PDT 2022


Author: River Riddle
Date: 2022-03-16T23:40:00-07:00
New Revision: 7bc5273367360347801f892d4312d0088c4961d4

URL: https://github.com/llvm/llvm-project/commit/7bc5273367360347801f892d4312d0088c4961d4
DIFF: https://github.com/llvm/llvm-project/commit/7bc5273367360347801f892d4312d0088c4961d4.diff

LOG: [mlir][NFC] Move the LSP agnostic files to a new lsp-server directory

This allows for sharing the implementation of key components across multiple
MLIR language servers. These will be used in a followup to help implement
a PDLL language server.

Differential Revision: https://reviews.llvm.org/D121540

Added: 
    mlir/lib/Tools/lsp-server-support/CMakeLists.txt
    mlir/lib/Tools/lsp-server-support/Logging.cpp
    mlir/lib/Tools/lsp-server-support/Logging.h
    mlir/lib/Tools/lsp-server-support/Protocol.cpp
    mlir/lib/Tools/lsp-server-support/Protocol.h
    mlir/lib/Tools/lsp-server-support/Transport.cpp
    mlir/lib/Tools/lsp-server-support/Transport.h

Modified: 
    mlir/lib/Tools/CMakeLists.txt
    mlir/lib/Tools/mlir-lsp-server/CMakeLists.txt
    mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp
    mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
    mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp

Removed: 
    mlir/lib/Tools/mlir-lsp-server/lsp/Logging.cpp
    mlir/lib/Tools/mlir-lsp-server/lsp/Logging.h
    mlir/lib/Tools/mlir-lsp-server/lsp/Protocol.cpp
    mlir/lib/Tools/mlir-lsp-server/lsp/Protocol.h
    mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp
    mlir/lib/Tools/mlir-lsp-server/lsp/Transport.h


################################################################################
diff  --git a/mlir/lib/Tools/CMakeLists.txt b/mlir/lib/Tools/CMakeLists.txt
index 864e428e88cf4..0c90545da6c58 100644
--- 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
index 0000000000000..15cb9cd1c9eec
--- /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.cpp b/mlir/lib/Tools/lsp-server-support/Logging.cpp
similarity index 100%
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/Logging.h b/mlir/lib/Tools/lsp-server-support/Logging.h
similarity index 81%
rename from mlir/lib/Tools/mlir-lsp-server/lsp/Logging.h
rename to mlir/lib/Tools/lsp-server-support/Logging.h
index 871f3112e76f6..5e68e7eb00f09 100644
--- 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 @@ class Logger {
 
   /// Initiate a log message at various severity levels. These should be called
   /// after a call to `initialize`.
-  template <typename... Ts> static void debug(const char *fmt, Ts &&... vals) {
+  template <typename... Ts>
+  static void debug(const char *fmt, Ts &&...vals) {
     log(Level::Debug, fmt, llvm::formatv(fmt, std::forward<Ts>(vals)...));
   }
-  template <typename... Ts> static void info(const char *fmt, Ts &&... vals) {
+  template <typename... Ts>
+  static void info(const char *fmt, Ts &&...vals) {
     log(Level::Info, fmt, llvm::formatv(fmt, std::forward<Ts>(vals)...));
   }
-  template <typename... Ts> static void error(const char *fmt, Ts &&... vals) {
+  template <typename... Ts>
+  static void error(const char *fmt, Ts &&...vals) {
     log(Level::Error, fmt, llvm::formatv(fmt, std::forward<Ts>(vals)...));
   }
 
@@ -59,4 +62,4 @@ class Logger {
 } // 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/Protocol.cpp b/mlir/lib/Tools/lsp-server-support/Protocol.cpp
similarity index 100%
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/Protocol.h b/mlir/lib/Tools/lsp-server-support/Protocol.h
similarity index 99%
rename from mlir/lib/Tools/mlir-lsp-server/lsp/Protocol.h
rename to mlir/lib/Tools/lsp-server-support/Protocol.h
index e5c85199e2679..79ef3855fa733 100644
--- 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 @@ llvm::json::Value toJSON(const PublishDiagnosticsParams &params);
 } // namespace mlir
 
 namespace llvm {
-template <> struct format_provider<mlir::lsp::Position> {
+template <>
+struct format_provider<mlir::lsp::Position> {
   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/Transport.cpp b/mlir/lib/Tools/lsp-server-support/Transport.cpp
similarity index 100%
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/lsp/Transport.h b/mlir/lib/Tools/lsp-server-support/Transport.h
similarity index 98%
rename from mlir/lib/Tools/mlir-lsp-server/lsp/Transport.h
rename to mlir/lib/Tools/lsp-server-support/Transport.h
index 6311b78192233..1f2f7d05219e6 100644
--- 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/CMakeLists.txt b/mlir/lib/Tools/mlir-lsp-server/CMakeLists.txt
index 1a54547a8fb57..999005148f326 100644
--- 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 @@ add_mlir_library(MLIRLspServerLib
 
   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
index 93600465abcff..e5c24443a9efb 100644
--- 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
index f5c551574377f..6b6dcc28cddde 100644
--- 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 @@ static lsp::Range getRangeFromLoc(llvm::SourceMgr &mgr, SMRange range) {
 }
 
 /// 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 @@ getLocationFromLoc(llvm::SourceMgr &sourceMgr, Location loc,
       // Use range of potential identifier starting at location, else length 1
       // range.
       location->range.end.character += 1;
-      if (Optional<SMRange> range =
-              AsmParserState::convertIdLocToRange(loc)) {
+      if (Optional<SMRange> 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 @@ static bool isDefOrUse(const AsmParserState::SMDefinition &def, SMLoc loc,
   }
 
   // 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 @@ static unsigned getBlockNumber(Block *block) {
 
 /// 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<StringRef> text = getTextFromRange(loc);
   if (text && text->startswith("^")) {
@@ -288,10 +284,9 @@ struct MLIRDocument {
   Optional<lsp::Hover>
   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
index e093b2602af29..3dc5d7cf2444d 100644
--- 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"


        


More information about the Mlir-commits mailing list