#include "PDLLServer.h"
#include "Protocol.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Support/ToolUtilities.h"
#include "mlir/Tools/PDLL/AST/Context.h"
#include "mlir/Tools/PDLL/AST/Nodes.h"
#include "mlir/Tools/PDLL/AST/Types.h"
#include "mlir/Tools/PDLL/CodeGen/CPPGen.h"
#include "mlir/Tools/PDLL/CodeGen/MLIRGen.h"
#include "mlir/Tools/PDLL/ODS/Constraint.h"
#include "mlir/Tools/PDLL/ODS/Context.h"
#include "mlir/Tools/PDLL/ODS/Dialect.h"
#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"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include <optional>
usingnamespacemlir;
usingnamespacemlir::pdll;
static lsp::URIForFile getURIFromLoc(llvm::SourceMgr &mgr, SMRange loc,
const lsp::URIForFile &mainFileURI) { … }
static bool isMainFileLoc(llvm::SourceMgr &mgr, SMRange loc) { … }
static lsp::Location getLocationFromLoc(llvm::SourceMgr &mgr, SMRange range,
const lsp::URIForFile &uri) { … }
static std::optional<lsp::Diagnostic>
getLspDiagnoticFromDiag(llvm::SourceMgr &sourceMgr, const ast::Diagnostic &diag,
const lsp::URIForFile &uri) { … }
static std::optional<std::string>
getDocumentationFor(llvm::SourceMgr &sourceMgr, const ast::Decl *decl) { … }
namespace {
struct PDLIndexSymbol { … };
class PDLIndex { … };
}
void PDLIndex::initialize(const ast::Module &module,
const ods::Context &odsContext) { … }
const PDLIndexSymbol *PDLIndex::lookup(SMLoc loc,
SMRange *overlappedRange) const { … }
namespace {
struct PDLDocument { … };
}
PDLDocument::PDLDocument(const lsp::URIForFile &uri, StringRef contents,
const std::vector<std::string> &extraDirs,
std::vector<lsp::Diagnostic> &diagnostics)
: … { … }
void PDLDocument::getLocationsOf(const lsp::URIForFile &uri,
const lsp::Position &defPos,
std::vector<lsp::Location> &locations) { … }
void PDLDocument::findReferencesOf(const lsp::URIForFile &uri,
const lsp::Position &pos,
std::vector<lsp::Location> &references) { … }
void PDLDocument::getDocumentLinks(const lsp::URIForFile &uri,
std::vector<lsp::DocumentLink> &links) { … }
std::optional<lsp::Hover>
PDLDocument::findHover(const lsp::URIForFile &uri,
const lsp::Position &hoverPos) { … }
std::optional<lsp::Hover> PDLDocument::findHover(const ast::Decl *decl,
const SMRange &hoverRange) { … }
lsp::Hover PDLDocument::buildHoverForOpName(const ods::Operation *op,
const SMRange &hoverRange) { … }
lsp::Hover PDLDocument::buildHoverForVariable(const ast::VariableDecl *varDecl,
const SMRange &hoverRange) { … }
lsp::Hover PDLDocument::buildHoverForPattern(const ast::PatternDecl *decl,
const SMRange &hoverRange) { … }
lsp::Hover
PDLDocument::buildHoverForCoreConstraint(const ast::CoreConstraintDecl *decl,
const SMRange &hoverRange) { … }
template <typename T>
lsp::Hover PDLDocument::buildHoverForUserConstraintOrRewrite(
StringRef typeName, const T *decl, const SMRange &hoverRange) { … }
void PDLDocument::findDocumentSymbols(
std::vector<lsp::DocumentSymbol> &symbols) { … }
namespace {
class LSPCodeCompleteContext : public CodeCompleteContext { … };
}
lsp::CompletionList
PDLDocument::getCodeCompletion(const lsp::URIForFile &uri,
const lsp::Position &completePos) { … }
namespace {
class LSPSignatureHelpContext : public CodeCompleteContext { … };
}
lsp::SignatureHelp PDLDocument::getSignatureHelp(const lsp::URIForFile &uri,
const lsp::Position &helpPos) { … }
static bool shouldAddHintFor(const ast::Expr *expr, StringRef name) { … }
void PDLDocument::getInlayHints(const lsp::URIForFile &uri,
const lsp::Range &range,
std::vector<lsp::InlayHint> &inlayHints) { … }
void PDLDocument::getInlayHintsFor(const ast::VariableDecl *decl,
const lsp::URIForFile &uri,
std::vector<lsp::InlayHint> &inlayHints) { … }
void PDLDocument::getInlayHintsFor(const ast::CallExpr *expr,
const lsp::URIForFile &uri,
std::vector<lsp::InlayHint> &inlayHints) { … }
void PDLDocument::getInlayHintsFor(const ast::OperationExpr *expr,
const lsp::URIForFile &uri,
std::vector<lsp::InlayHint> &inlayHints) { … }
void PDLDocument::addParameterHintFor(std::vector<lsp::InlayHint> &inlayHints,
const ast::Expr *expr, StringRef label) { … }
void PDLDocument::getPDLLViewOutput(raw_ostream &os,
lsp::PDLLViewOutputKind kind) { … }
namespace {
struct PDLTextFileChunk { … };
}
namespace {
class PDLTextFile { … };
}
PDLTextFile::PDLTextFile(const lsp::URIForFile &uri, StringRef fileContents,
int64_t version,
const std::vector<std::string> &extraDirs,
std::vector<lsp::Diagnostic> &diagnostics)
: … { … }
LogicalResult
PDLTextFile::update(const lsp::URIForFile &uri, int64_t newVersion,
ArrayRef<lsp::TextDocumentContentChangeEvent> changes,
std::vector<lsp::Diagnostic> &diagnostics) { … }
void PDLTextFile::getLocationsOf(const lsp::URIForFile &uri,
lsp::Position defPos,
std::vector<lsp::Location> &locations) { … }
void PDLTextFile::findReferencesOf(const lsp::URIForFile &uri,
lsp::Position pos,
std::vector<lsp::Location> &references) { … }
void PDLTextFile::getDocumentLinks(const lsp::URIForFile &uri,
std::vector<lsp::DocumentLink> &links) { … }
std::optional<lsp::Hover> PDLTextFile::findHover(const lsp::URIForFile &uri,
lsp::Position hoverPos) { … }
void PDLTextFile::findDocumentSymbols(
std::vector<lsp::DocumentSymbol> &symbols) { … }
lsp::CompletionList PDLTextFile::getCodeCompletion(const lsp::URIForFile &uri,
lsp::Position completePos) { … }
lsp::SignatureHelp PDLTextFile::getSignatureHelp(const lsp::URIForFile &uri,
lsp::Position helpPos) { … }
void PDLTextFile::getInlayHints(const lsp::URIForFile &uri, lsp::Range range,
std::vector<lsp::InlayHint> &inlayHints) { … }
lsp::PDLLViewOutputResult
PDLTextFile::getPDLLViewOutput(lsp::PDLLViewOutputKind kind) { … }
void PDLTextFile::initialize(const lsp::URIForFile &uri, int64_t newVersion,
std::vector<lsp::Diagnostic> &diagnostics) { … }
PDLTextFile::ChunkIterator PDLTextFile::getChunkItFor(lsp::Position &pos) { … }
struct lsp::PDLLServer::Impl { … };
lsp::PDLLServer::PDLLServer(const Options &options)
: … { … }
lsp::PDLLServer::~PDLLServer() = default;
void lsp::PDLLServer::addDocument(const URIForFile &uri, StringRef contents,
int64_t version,
std::vector<Diagnostic> &diagnostics) { … }
void lsp::PDLLServer::updateDocument(
const URIForFile &uri, ArrayRef<TextDocumentContentChangeEvent> changes,
int64_t version, std::vector<Diagnostic> &diagnostics) { … }
std::optional<int64_t> lsp::PDLLServer::removeDocument(const URIForFile &uri) { … }
void lsp::PDLLServer::getLocationsOf(const URIForFile &uri,
const Position &defPos,
std::vector<Location> &locations) { … }
void lsp::PDLLServer::findReferencesOf(const URIForFile &uri,
const Position &pos,
std::vector<Location> &references) { … }
void lsp::PDLLServer::getDocumentLinks(
const URIForFile &uri, std::vector<DocumentLink> &documentLinks) { … }
std::optional<lsp::Hover> lsp::PDLLServer::findHover(const URIForFile &uri,
const Position &hoverPos) { … }
void lsp::PDLLServer::findDocumentSymbols(
const URIForFile &uri, std::vector<DocumentSymbol> &symbols) { … }
lsp::CompletionList
lsp::PDLLServer::getCodeCompletion(const URIForFile &uri,
const Position &completePos) { … }
lsp::SignatureHelp lsp::PDLLServer::getSignatureHelp(const URIForFile &uri,
const Position &helpPos) { … }
void lsp::PDLLServer::getInlayHints(const URIForFile &uri, const Range &range,
std::vector<InlayHint> &inlayHints) { … }
std::optional<lsp::PDLLViewOutputResult>
lsp::PDLLServer::getPDLLViewOutput(const URIForFile &uri,
PDLLViewOutputKind kind) { … }