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-exception 6 // 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 <memory> 15 #include <string> 16 17 namespace mlir { 18 namespace lsp { 19 struct Diagnostic; 20 struct DocumentLink; 21 struct Hover; 22 struct Location; 23 struct Position; 24 struct TextDocumentContentChangeEvent; 25 class URIForFile; 26 27 /// This class implements all of the TableGen related functionality necessary 28 /// for a language server. This class allows for keeping the TableGen specific 29 /// logic separate from the logic that involves LSP server/client communication. 30 class TableGenServer { 31 public: 32 struct Options { OptionsOptions33 Options(const std::vector<std::string> &compilationDatabases, 34 const std::vector<std::string> &extraDirs) 35 : compilationDatabases(compilationDatabases), extraDirs(extraDirs) {} 36 37 /// The filenames for databases containing compilation commands for TableGen 38 /// files passed to the server. 39 const std::vector<std::string> &compilationDatabases; 40 41 /// Additional list of include directories to search. 42 const std::vector<std::string> &extraDirs; 43 }; 44 45 TableGenServer(const Options &options); 46 ~TableGenServer(); 47 48 /// Add the document, with the provided `version`, at the given URI. Any 49 /// diagnostics emitted for this document should be added to `diagnostics`. 50 void addDocument(const URIForFile &uri, StringRef contents, int64_t version, 51 std::vector<Diagnostic> &diagnostics); 52 53 /// Update the document, with the provided `version`, at the given URI. Any 54 /// diagnostics emitted for this document should be added to `diagnostics`. 55 void updateDocument(const URIForFile &uri, 56 ArrayRef<TextDocumentContentChangeEvent> changes, 57 int64_t version, std::vector<Diagnostic> &diagnostics); 58 59 /// Remove the document with the given uri. Returns the version of the removed 60 /// document, or None if the uri did not have a corresponding document within 61 /// the server. 62 Optional<int64_t> removeDocument(const URIForFile &uri); 63 64 /// Return the locations of the object pointed at by the given position. 65 void getLocationsOf(const URIForFile &uri, const Position &defPos, 66 std::vector<Location> &locations); 67 68 /// Find all references of the object pointed at by the given position. 69 void findReferencesOf(const URIForFile &uri, const Position &pos, 70 std::vector<Location> &references); 71 72 /// Return the document links referenced by the given file. 73 void getDocumentLinks(const URIForFile &uri, 74 std::vector<DocumentLink> &documentLinks); 75 76 /// Find a hover description for the given hover position, or None if one 77 /// couldn't be found. 78 Optional<Hover> findHover(const URIForFile &uri, const Position &hoverPos); 79 80 private: 81 struct Impl; 82 std::unique_ptr<Impl> impl; 83 }; 84 85 } // namespace lsp 86 } // namespace mlir 87 88 #endif // LIB_MLIR_TOOLS_TBLGENLSPSERVER_TABLEGENSERVER_H_ 89