93 lines · c
1//===- TableGenServer.h - TableGen 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_TBLGENLSPSERVER_TABLEGENSERVER_H_10#define LIB_MLIR_TOOLS_TBLGENLSPSERVER_TABLEGENSERVER_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::Diagnostic;23using llvm::lsp::DocumentLink;24using llvm::lsp::Hover;25using llvm::lsp::Location;26using llvm::lsp::Position;27using llvm::lsp::TextDocumentContentChangeEvent;28using llvm::lsp::URIForFile;29 30/// This class implements all of the TableGen related functionality necessary31/// for a language server. This class allows for keeping the TableGen specific32/// logic separate from the logic that involves LSP server/client communication.33class TableGenServer {34public:35 struct Options {36 Options(const std::vector<std::string> &compilationDatabases,37 const std::vector<std::string> &extraDirs)38 : compilationDatabases(compilationDatabases), extraDirs(extraDirs) {}39 40 /// The filenames for databases containing compilation commands for TableGen41 /// files passed to the server.42 const std::vector<std::string> &compilationDatabases;43 44 /// Additional list of include directories to search.45 const std::vector<std::string> &extraDirs;46 };47 48 TableGenServer(const Options &options);49 ~TableGenServer();50 51 /// Add the document, with the provided `version`, at the given URI. Any52 /// diagnostics emitted for this document should be added to `diagnostics`.53 void addDocument(const URIForFile &uri, StringRef contents, int64_t version,54 std::vector<Diagnostic> &diagnostics);55 56 /// Update the document, with the provided `version`, at the given URI. Any57 /// diagnostics emitted for this document should be added to `diagnostics`.58 void updateDocument(const URIForFile &uri,59 ArrayRef<TextDocumentContentChangeEvent> changes,60 int64_t version, std::vector<Diagnostic> &diagnostics);61 62 /// Remove the document with the given uri. Returns the version of the removed63 /// document, or std::nullopt if the uri did not have a corresponding document64 /// within the server.65 std::optional<int64_t> removeDocument(const URIForFile &uri);66 67 /// Return the locations of the object pointed at by the given position.68 void getLocationsOf(const URIForFile &uri, const Position &defPos,69 std::vector<Location> &locations);70 71 /// Find all references of the object pointed at by the given position.72 void findReferencesOf(const URIForFile &uri, const Position &pos,73 std::vector<Location> &references);74 75 /// Return the document links referenced by the given file.76 void getDocumentLinks(const URIForFile &uri,77 std::vector<DocumentLink> &documentLinks);78 79 /// Find a hover description for the given hover position, or std::nullopt if80 /// one couldn't be found.81 std::optional<Hover> findHover(const URIForFile &uri,82 const Position &hoverPos);83 84private:85 struct Impl;86 std::unique_ptr<Impl> impl;87};88 89} // namespace lsp90} // namespace mlir91 92#endif // LIB_MLIR_TOOLS_TBLGENLSPSERVER_TABLEGENSERVER_H_93