1 //===- MLIRServer.h - MLIR 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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_ 10 #define LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_ 11 12 #include "mlir/Support/LLVM.h" 13 #include <memory> 14 15 namespace mlir { 16 class DialectRegistry; 17 18 namespace lsp { 19 struct Diagnostic; 20 struct DocumentSymbol; 21 struct Hover; 22 struct Location; 23 struct Position; 24 class URIForFile; 25 26 /// This class implements all of the MLIR related functionality necessary for a 27 /// language server. This class allows for keeping the MLIR specific logic 28 /// separate from the logic that involves LSP server/client communication. 29 class MLIRServer { 30 public: 31 /// Construct a new server with the given dialect regitstry. 32 MLIRServer(DialectRegistry ®istry); 33 ~MLIRServer(); 34 35 /// Add or update the document, with the provided `version`, at the given URI. 36 /// Any diagnostics emitted for this document should be added to 37 /// `diagnostics`. 38 void addOrUpdateDocument(const URIForFile &uri, StringRef contents, 39 int64_t version, 40 std::vector<Diagnostic> &diagnostics); 41 42 /// Remove the document with the given uri. Returns the version of the removed 43 /// document, or None if the uri did not have a corresponding document within 44 /// the server. 45 Optional<int64_t> removeDocument(const URIForFile &uri); 46 47 /// Return the locations of the object pointed at by the given position. 48 void getLocationsOf(const URIForFile &uri, const Position &defPos, 49 std::vector<Location> &locations); 50 51 /// Find all references of the object pointed at by the given position. 52 void findReferencesOf(const URIForFile &uri, const Position &pos, 53 std::vector<Location> &references); 54 55 /// Find a hover description for the given hover position, or None if one 56 /// couldn't be found. 57 Optional<Hover> findHover(const URIForFile &uri, const Position &hoverPos); 58 59 /// Find all of the document symbols within the given file. 60 void findDocumentSymbols(const URIForFile &uri, 61 std::vector<DocumentSymbol> &symbols); 62 63 private: 64 struct Impl; 65 66 std::unique_ptr<Impl> impl; 67 }; 68 69 } // namespace lsp 70 } // namespace mlir 71 72 #endif // LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_ 73