[mlir][NFC] Move the headers for lsp-server-support to include/
This makes it a bit easier to share the functionality for building language servers, and makes the API public. No real functional change, as the API was already intended for this anyways. Differential Revision: https://reviews.llvm.org/D142790
This commit is contained in:
@@ -13,8 +13,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LIB_MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H_
|
||||
#define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H_
|
||||
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H
|
||||
#define MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H
|
||||
|
||||
#include "mlir/Support/LLVM.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
@@ -67,4 +67,4 @@ private:
|
||||
} // namespace lsp
|
||||
} // namespace mlir
|
||||
|
||||
#endif // LIB_MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H_
|
||||
#endif // MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H
|
||||
@@ -6,8 +6,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LIB_MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
|
||||
#define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
|
||||
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
|
||||
#define MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
|
||||
|
||||
#include "mlir/Support/LLVM.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
@@ -62,4 +62,4 @@ private:
|
||||
} // namespace lsp
|
||||
} // namespace mlir
|
||||
|
||||
#endif // LIB_MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
|
||||
#endif // MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
|
||||
@@ -20,8 +20,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LIB_MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H_
|
||||
#define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H_
|
||||
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
|
||||
#define MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
|
||||
|
||||
#include "mlir/Support/LLVM.h"
|
||||
#include "llvm/Support/JSON.h"
|
||||
@@ -29,10 +29,10 @@
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <bitset>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
namespace mlir {
|
||||
struct LogicalResult;
|
||||
@@ -11,10 +11,10 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_
|
||||
#define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_
|
||||
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
|
||||
#define MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
|
||||
|
||||
#include "Protocol.h"
|
||||
#include "mlir/Tools/lsp-server-support/Protocol.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include <optional>
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace lsp {
|
||||
/// Returns the range of a lexical token given a SMLoc corresponding to the
|
||||
/// start of an token location. The range is computed heuristically, and
|
||||
/// supports identifier-like tokens, strings, etc.
|
||||
SMRange convertTokenLocToRange(SMLoc loc);
|
||||
SMRange convertTokenLocToRange(SMLoc loc, StringRef identifierChars = "");
|
||||
|
||||
/// Extract a documentation comment for the given location within the source
|
||||
/// manager. Returns std::nullopt if no comment could be computed.
|
||||
@@ -12,13 +12,13 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_
|
||||
#define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_
|
||||
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
|
||||
#define MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
|
||||
|
||||
#include "Logging.h"
|
||||
#include "Protocol.h"
|
||||
#include "mlir/Support/LLVM.h"
|
||||
#include "mlir/Support/LogicalResult.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Protocol.h"
|
||||
#include "llvm/ADT/FunctionExtras.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
@@ -6,7 +6,7 @@ add_mlir_library(MLIRLspServerSupportLib
|
||||
Transport.cpp
|
||||
|
||||
ADDITIONAL_HEADER_DIRS
|
||||
${MLIR_MAIN_INCLUDE_DIR}/mlir/Tools/lsp-server
|
||||
${MLIR_MAIN_INCLUDE_DIR}/mlir/Tools/lsp-server-support
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRSupport
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CompilationDatabase.h"
|
||||
#include "../lsp-server-support/Logging.h"
|
||||
#include "Protocol.h"
|
||||
#include "mlir/Tools/lsp-server-support/CompilationDatabase.h"
|
||||
#include "mlir/Support/FileUtilities.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Protocol.h"
|
||||
#include "llvm/ADT/SetVector.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/YAMLTraits.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "llvm/Support/Chrono.h"
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "Protocol.h"
|
||||
#include "Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Protocol.h"
|
||||
#include "mlir/Support/LogicalResult.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "llvm/ADT/Hashing.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/StringSet.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "SourceMgrUtils.h"
|
||||
#include "mlir/Tools/lsp-server-support/SourceMgrUtils.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include <optional>
|
||||
|
||||
@@ -43,7 +43,7 @@ static const char *lexLocStringTok(const char *curPtr) {
|
||||
return curPtr - 1;
|
||||
}
|
||||
|
||||
SMRange lsp::convertTokenLocToRange(SMLoc loc) {
|
||||
SMRange lsp::convertTokenLocToRange(SMLoc loc, StringRef identifierChars) {
|
||||
if (!loc.isValid())
|
||||
return SMRange();
|
||||
const char *curPtr = loc.getPointer();
|
||||
@@ -55,8 +55,8 @@ SMRange lsp::convertTokenLocToRange(SMLoc loc) {
|
||||
// Otherwise, default to handling an identifier.
|
||||
} else {
|
||||
// Return if the given character is a valid identifier character.
|
||||
auto isIdentifierChar = [](char c) {
|
||||
return isalnum(c) || c == '$' || c == '.' || c == '_' || c == '-';
|
||||
auto isIdentifierChar = [=](char c) {
|
||||
return isalnum(c) || c == '_' || identifierChars.contains(c);
|
||||
};
|
||||
|
||||
while (*curPtr && isIdentifierChar(*(++curPtr)))
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "Transport.h"
|
||||
#include "Logging.h"
|
||||
#include "Protocol.h"
|
||||
#include "mlir/Tools/lsp-server-support/Transport.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Protocol.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/Support/Errno.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include <optional>
|
||||
#include <system_error>
|
||||
#include <utility>
|
||||
#include <optional>
|
||||
|
||||
using namespace mlir;
|
||||
using namespace mlir::lsp;
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "LSPServer.h"
|
||||
#include "../lsp-server-support/Logging.h"
|
||||
#include "../lsp-server-support/Transport.h"
|
||||
#include "MLIRServer.h"
|
||||
#include "Protocol.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Transport.h"
|
||||
#include "llvm/ADT/FunctionExtras.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include <optional>
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "MLIRServer.h"
|
||||
#include "../lsp-server-support/Logging.h"
|
||||
#include "../lsp-server-support/SourceMgrUtils.h"
|
||||
#include "Protocol.h"
|
||||
#include "mlir/AsmParser/AsmParser.h"
|
||||
#include "mlir/AsmParser/AsmParserState.h"
|
||||
@@ -17,12 +15,21 @@
|
||||
#include "mlir/IR/FunctionInterfaces.h"
|
||||
#include "mlir/IR/Operation.h"
|
||||
#include "mlir/Parser/Parser.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/SourceMgrUtils.h"
|
||||
#include "llvm/Support/Base64.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include <optional>
|
||||
|
||||
using namespace mlir;
|
||||
|
||||
/// Returns the range of a lexical token given a SMLoc corresponding to the
|
||||
/// start of an token location. The range is computed heuristically, and
|
||||
/// supports identifier-like tokens, strings, etc.
|
||||
static SMRange convertTokenLocToRange(SMLoc loc) {
|
||||
return lsp::convertTokenLocToRange(loc, "$-.");
|
||||
}
|
||||
|
||||
/// Returns a language server location from the given MLIR file location.
|
||||
/// `uriScheme` is the scheme to use when building new uris.
|
||||
static std::optional<lsp::Location> getLocationFromLoc(StringRef uriScheme,
|
||||
@@ -65,7 +72,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 (std::optional<SMRange> range = lsp::convertTokenLocToRange(loc)) {
|
||||
if (std::optional<SMRange> range = convertTokenLocToRange(loc)) {
|
||||
auto lineCol = sourceMgr.getLineAndColumn(range->End);
|
||||
location->range.end.character =
|
||||
std::max(fileLoc.getColumn() + 1, lineCol.second - 1);
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#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 "mlir/IR/Dialect.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Transport.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef LIB_MLIR_TOOLS_MLIRLSPSERVER_PROTOCOL_H_
|
||||
#define LIB_MLIR_TOOLS_MLIRLSPSERVER_PROTOCOL_H_
|
||||
|
||||
#include "../lsp-server-support/Protocol.h"
|
||||
#include "mlir/Tools/lsp-server-support/Protocol.h"
|
||||
|
||||
namespace mlir {
|
||||
namespace lsp {
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
#include "LSPServer.h"
|
||||
|
||||
#include "../lsp-server-support/Logging.h"
|
||||
#include "../lsp-server-support/Transport.h"
|
||||
#include "PDLLServer.h"
|
||||
#include "Protocol.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Transport.h"
|
||||
#include "llvm/ADT/FunctionExtras.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include <optional>
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h"
|
||||
#include "../lsp-server-support/Logging.h"
|
||||
#include "../lsp-server-support/Transport.h"
|
||||
#include "LSPServer.h"
|
||||
#include "PDLLServer.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Transport.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
|
||||
#include "PDLLServer.h"
|
||||
|
||||
#include "../lsp-server-support/CompilationDatabase.h"
|
||||
#include "../lsp-server-support/Logging.h"
|
||||
#include "../lsp-server-support/SourceMgrUtils.h"
|
||||
#include "Protocol.h"
|
||||
#include "mlir/IR/BuiltinOps.h"
|
||||
#include "mlir/Tools/PDLL/AST/Context.h"
|
||||
@@ -24,6 +21,9 @@
|
||||
#include "mlir/Tools/PDLL/ODS/Operation.h"
|
||||
#include "mlir/Tools/PDLL/Parser/CodeComplete.h"
|
||||
#include "mlir/Tools/PDLL/Parser/Parser.h"
|
||||
#include "mlir/Tools/lsp-server-support/CompilationDatabase.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/SourceMgrUtils.h"
|
||||
#include "llvm/ADT/IntervalMap.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/StringSet.h"
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef LIB_MLIR_TOOLS_MLIRPDLLLSPSERVER_PROTOCOL_H_
|
||||
#define LIB_MLIR_TOOLS_MLIRPDLLLSPSERVER_PROTOCOL_H_
|
||||
|
||||
#include "../lsp-server-support/Protocol.h"
|
||||
#include "mlir/Tools/lsp-server-support/Protocol.h"
|
||||
|
||||
namespace mlir {
|
||||
namespace lsp {
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
#include "LSPServer.h"
|
||||
|
||||
#include "../lsp-server-support/Logging.h"
|
||||
#include "../lsp-server-support/Protocol.h"
|
||||
#include "../lsp-server-support/Transport.h"
|
||||
#include "TableGenServer.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Protocol.h"
|
||||
#include "mlir/Tools/lsp-server-support/Transport.h"
|
||||
#include "llvm/ADT/FunctionExtras.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include <optional>
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h"
|
||||
#include "../lsp-server-support/Logging.h"
|
||||
#include "../lsp-server-support/Transport.h"
|
||||
#include "LSPServer.h"
|
||||
#include "TableGenServer.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Transport.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
#include "TableGenServer.h"
|
||||
|
||||
#include "../lsp-server-support/CompilationDatabase.h"
|
||||
#include "../lsp-server-support/Logging.h"
|
||||
#include "../lsp-server-support/Protocol.h"
|
||||
#include "../lsp-server-support/SourceMgrUtils.h"
|
||||
#include "mlir/Support/IndentedOstream.h"
|
||||
#include "mlir/Support/LogicalResult.h"
|
||||
#include "mlir/Tools/lsp-server-support/CompilationDatabase.h"
|
||||
#include "mlir/Tools/lsp-server-support/Logging.h"
|
||||
#include "mlir/Tools/lsp-server-support/Protocol.h"
|
||||
#include "mlir/Tools/lsp-server-support/SourceMgrUtils.h"
|
||||
#include "llvm/ADT/IntervalMap.h"
|
||||
#include "llvm/ADT/PointerUnion.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
@@ -27,6 +27,13 @@
|
||||
|
||||
using namespace mlir;
|
||||
|
||||
/// Returns the range of a lexical token given a SMLoc corresponding to the
|
||||
/// start of an token location. The range is computed heuristically, and
|
||||
/// supports identifier-like tokens, strings, etc.
|
||||
static SMRange convertTokenLocToRange(SMLoc loc) {
|
||||
return lsp::convertTokenLocToRange(loc, "$");
|
||||
}
|
||||
|
||||
/// Returns a language server uri for the given source location. `mainFileURI`
|
||||
/// corresponds to the uri for the main file of the source manager.
|
||||
static lsp::URIForFile getURIFromLoc(const llvm::SourceMgr &mgr, SMLoc loc,
|
||||
@@ -51,7 +58,7 @@ static lsp::Location getLocationFromLoc(llvm::SourceMgr &mgr, SMRange loc,
|
||||
}
|
||||
static lsp::Location getLocationFromLoc(llvm::SourceMgr &mgr, SMLoc loc,
|
||||
const lsp::URIForFile &uri) {
|
||||
return getLocationFromLoc(mgr, lsp::convertTokenLocToRange(loc), uri);
|
||||
return getLocationFromLoc(mgr, convertTokenLocToRange(loc), uri);
|
||||
}
|
||||
|
||||
/// Convert the given TableGen diagnostic to the LSP form.
|
||||
@@ -139,10 +146,9 @@ namespace {
|
||||
struct TableGenIndexSymbol {
|
||||
TableGenIndexSymbol(const llvm::Record *record)
|
||||
: definition(record),
|
||||
defLoc(lsp::convertTokenLocToRange(record->getLoc().front())) {}
|
||||
defLoc(convertTokenLocToRange(record->getLoc().front())) {}
|
||||
TableGenIndexSymbol(const llvm::RecordVal *value)
|
||||
: definition(value),
|
||||
defLoc(lsp::convertTokenLocToRange(value->getLoc())) {}
|
||||
: definition(value), defLoc(convertTokenLocToRange(value->getLoc())) {}
|
||||
virtual ~TableGenIndexSymbol() = default;
|
||||
|
||||
// The main definition of the symbol.
|
||||
@@ -256,7 +262,7 @@ void TableGenIndex::initialize(const llvm::RecordKeeper &records) {
|
||||
// If the location we got was empty, try to lex a token from the start
|
||||
// location.
|
||||
if (startLoc == endLoc) {
|
||||
refLoc = lsp::convertTokenLocToRange(SMLoc::getFromPointer(startLoc));
|
||||
refLoc = convertTokenLocToRange(SMLoc::getFromPointer(startLoc));
|
||||
startLoc = refLoc.Start.getPointer();
|
||||
endLoc = refLoc.End.getPointer();
|
||||
|
||||
@@ -286,7 +292,7 @@ void TableGenIndex::initialize(const llvm::RecordKeeper &records) {
|
||||
|
||||
// Add references to the definition.
|
||||
for (SMLoc loc : def.getLoc().drop_front())
|
||||
insertRef(sym, lsp::convertTokenLocToRange(loc));
|
||||
insertRef(sym, convertTokenLocToRange(loc));
|
||||
for (SMRange loc : def.getReferenceLocs())
|
||||
insertRef(sym, loc);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user