123 lines · c
1//===- PDLLServer.h - PDL General Language Server ---------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LIB_MLIR_TOOLS_MLIRPDLLSPSERVER_SERVER_H_10#define LIB_MLIR_TOOLS_MLIRPDLLSPSERVER_SERVER_H_11 12#include "mlir/Support/LLVM.h"13#include "llvm/ADT/StringRef.h"14#include "llvm/Support/LSP/Protocol.h"15#include <memory>16#include <optional>17#include <string>18#include <vector>19 20namespace mlir {21namespace lsp {22using llvm::lsp::CompletionList;23using llvm::lsp::Diagnostic;24using llvm::lsp::DocumentLink;25using llvm::lsp::DocumentSymbol;26using llvm::lsp::Hover;27using llvm::lsp::InlayHint;28using llvm::lsp::Location;29using llvm::lsp::Position;30using llvm::lsp::Range;31using llvm::lsp::SignatureHelp;32using llvm::lsp::TextDocumentContentChangeEvent;33using llvm::lsp::URIForFile;34 35class CompilationDatabase;36struct PDLLViewOutputResult;37enum class PDLLViewOutputKind;38 39/// This class implements all of the PDLL related functionality necessary for a40/// language server. This class allows for keeping the PDLL specific logic41/// separate from the logic that involves LSP server/client communication.42class PDLLServer {43public:44 struct Options {45 Options(const std::vector<std::string> &compilationDatabases,46 const std::vector<std::string> &extraDirs)47 : compilationDatabases(compilationDatabases), extraDirs(extraDirs) {}48 49 /// The filenames for databases containing compilation commands for PDLL50 /// files passed to the server.51 const std::vector<std::string> &compilationDatabases;52 53 /// Additional list of include directories to search.54 const std::vector<std::string> &extraDirs;55 };56 57 PDLLServer(const Options &options);58 ~PDLLServer();59 60 /// Add the document, with the provided `version`, at the given URI. Any61 /// diagnostics emitted for this document should be added to `diagnostics`.62 void addDocument(const URIForFile &uri, StringRef contents, int64_t version,63 std::vector<Diagnostic> &diagnostics);64 65 /// Update the document, with the provided `version`, at the given URI. Any66 /// diagnostics emitted for this document should be added to `diagnostics`.67 void updateDocument(const URIForFile &uri,68 ArrayRef<TextDocumentContentChangeEvent> changes,69 int64_t version, std::vector<Diagnostic> &diagnostics);70 71 /// Remove the document with the given uri. Returns the version of the removed72 /// document, or std::nullopt if the uri did not have a corresponding document73 /// within the server.74 std::optional<int64_t> removeDocument(const URIForFile &uri);75 76 /// Return the locations of the object pointed at by the given position.77 void getLocationsOf(const URIForFile &uri, const Position &defPos,78 std::vector<Location> &locations);79 80 /// Find all references of the object pointed at by the given position.81 void findReferencesOf(const URIForFile &uri, const Position &pos,82 std::vector<Location> &references);83 84 /// Return the document links referenced by the given file.85 void getDocumentLinks(const URIForFile &uri,86 std::vector<DocumentLink> &documentLinks);87 88 /// Find a hover description for the given hover position, or std::nullopt if89 /// one couldn't be found.90 std::optional<Hover> findHover(const URIForFile &uri,91 const Position &hoverPos);92 93 /// Find all of the document symbols within the given file.94 void findDocumentSymbols(const URIForFile &uri,95 std::vector<DocumentSymbol> &symbols);96 97 /// Get the code completion list for the position within the given file.98 CompletionList getCodeCompletion(const URIForFile &uri,99 const Position &completePos);100 101 /// Get the signature help for the position within the given file.102 SignatureHelp getSignatureHelp(const URIForFile &uri,103 const Position &helpPos);104 105 /// Get the inlay hints for the range within the given file.106 void getInlayHints(const URIForFile &uri, const Range &range,107 std::vector<InlayHint> &inlayHints);108 109 /// Get the output of the given PDLL file, or std::nullopt if there is no110 /// valid output.111 std::optional<PDLLViewOutputResult>112 getPDLLViewOutput(const URIForFile &uri, PDLLViewOutputKind kind);113 114private:115 struct Impl;116 std::unique_ptr<Impl> impl;117};118 119} // namespace lsp120} // namespace mlir121 122#endif // LIB_MLIR_TOOLS_MLIRPDLLSPSERVER_SERVER_H_123