mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-01 12:43:47 +00:00
[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:
parent
943ad665e2
commit
7bc5273367
@ -1,3 +1,4 @@
|
||||
add_subdirectory(lsp-server-support)
|
||||
add_subdirectory(mlir-lsp-server)
|
||||
add_subdirectory(mlir-opt)
|
||||
add_subdirectory(mlir-reduce)
|
||||
|
11
mlir/lib/Tools/lsp-server-support/CMakeLists.txt
Normal file
11
mlir/lib/Tools/lsp-server-support/CMakeLists.txt
Normal 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
|
||||
)
|
@ -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
|
@ -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 ¶ms);
|
||||
} // 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");
|
@ -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"
|
@ -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
|
||||
)
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user