[rtsan] Remove mkfifoat interceptor (#116997)
[llvm-project.git] / mlir / lib / Tools / mlir-lsp-server / MLIRServer.h
blob979be615b82cc46c23cddc7f40bd2b792b4b0903
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 //===----------------------------------------------------------------------===//
9 #ifndef LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_
10 #define LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_
12 #include "mlir/Support/LLVM.h"
13 #include "llvm/Support/Error.h"
14 #include <memory>
15 #include <optional>
17 namespace mlir {
18 class DialectRegistry;
20 namespace lsp {
21 struct CodeAction;
22 struct CodeActionContext;
23 struct CompletionList;
24 struct Diagnostic;
25 struct DocumentSymbol;
26 struct Hover;
27 struct Location;
28 struct MLIRConvertBytecodeResult;
29 struct Position;
30 struct Range;
31 class URIForFile;
33 /// This class implements all of the MLIR related functionality necessary for a
34 /// language server. This class allows for keeping the MLIR specific logic
35 /// separate from the logic that involves LSP server/client communication.
36 class MLIRServer {
37 public:
38 /// Construct a new server with the given dialect regitstry.
39 MLIRServer(DialectRegistry &registry);
40 ~MLIRServer();
42 /// Add or update the document, with the provided `version`, at the given URI.
43 /// Any diagnostics emitted for this document should be added to
44 /// `diagnostics`.
45 void addOrUpdateDocument(const URIForFile &uri, StringRef contents,
46 int64_t version,
47 std::vector<Diagnostic> &diagnostics);
49 /// Remove the document with the given uri. Returns the version of the removed
50 /// document, or std::nullopt if the uri did not have a corresponding document
51 /// within the server.
52 std::optional<int64_t> removeDocument(const URIForFile &uri);
54 /// Return the locations of the object pointed at by the given position.
55 void getLocationsOf(const URIForFile &uri, const Position &defPos,
56 std::vector<Location> &locations);
58 /// Find all references of the object pointed at by the given position.
59 void findReferencesOf(const URIForFile &uri, const Position &pos,
60 std::vector<Location> &references);
62 /// Find a hover description for the given hover position, or std::nullopt if
63 /// one couldn't be found.
64 std::optional<Hover> findHover(const URIForFile &uri,
65 const Position &hoverPos);
67 /// Find all of the document symbols within the given file.
68 void findDocumentSymbols(const URIForFile &uri,
69 std::vector<DocumentSymbol> &symbols);
71 /// Get the code completion list for the position within the given file.
72 CompletionList getCodeCompletion(const URIForFile &uri,
73 const Position &completePos);
75 /// Get the set of code actions within the file.
76 void getCodeActions(const URIForFile &uri, const Range &pos,
77 const CodeActionContext &context,
78 std::vector<CodeAction> &actions);
80 /// Convert the given bytecode file to the textual format.
81 llvm::Expected<MLIRConvertBytecodeResult>
82 convertFromBytecode(const URIForFile &uri);
84 /// Convert the given textual file to the bytecode format.
85 llvm::Expected<MLIRConvertBytecodeResult>
86 convertToBytecode(const URIForFile &uri);
88 private:
89 struct Impl;
91 std::unique_ptr<Impl> impl;
94 } // namespace lsp
95 } // namespace mlir
97 #endif // LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_