[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
This commit is contained in:
River Riddle 2022-03-10 23:17:24 -08:00
parent 943ad665e2
commit 7bc5273367
12 changed files with 43 additions and 34 deletions

View File

@ -1,3 +1,4 @@
add_subdirectory(lsp-server-support)
add_subdirectory(mlir-lsp-server)
add_subdirectory(mlir-opt)
add_subdirectory(mlir-reduce)

View File

@ -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
)

View File

@ -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 @@ public:
/// 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 @@ private:
} // namespace lsp
} // namespace mlir
#endif // LIB_MLIR_TOOLS_MLIRLSPSERVER_LSP_LOGGING_H
#endif // LIB_MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H

View File

@ -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");

View File

@ -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"

View File

@ -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
)

View File

@ -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"

View File

@ -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

View File

@ -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"