MLIR  19.0.0git
MLIRServer.h
Go to the documentation of this file.
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 "llvm/Support/Error.h"
14 #include <memory>
15 #include <optional>
16 
17 namespace mlir {
18 class DialectRegistry;
19 
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;
32 
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);
41 
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);
48 
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);
53 
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);
57 
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);
61 
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);
66 
67  /// Find all of the document symbols within the given file.
68  void findDocumentSymbols(const URIForFile &uri,
69  std::vector<DocumentSymbol> &symbols);
70 
71  /// Get the code completion list for the position within the given file.
73  const Position &completePos);
74 
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);
79 
80  /// Convert the given bytecode file to the textual format.
82  convertFromBytecode(const URIForFile &uri);
83 
84  /// Convert the given textual file to the bytecode format.
86  convertToBytecode(const URIForFile &uri);
87 
88 private:
89  struct Impl;
90 
91  std::unique_ptr<Impl> impl;
92 };
93 
94 } // namespace lsp
95 } // namespace mlir
96 
97 #endif // LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
This class implements all of the MLIR related functionality necessary for a language server.
Definition: MLIRServer.h:36
void addOrUpdateDocument(const URIForFile &uri, StringRef contents, int64_t version, std::vector< Diagnostic > &diagnostics)
Add or update the document, with the provided version, at the given URI.
std::optional< int64_t > removeDocument(const URIForFile &uri)
Remove the document with the given uri.
void findReferencesOf(const URIForFile &uri, const Position &pos, std::vector< Location > &references)
Find all references of the object pointed at by the given position.
void getLocationsOf(const URIForFile &uri, const Position &defPos, std::vector< Location > &locations)
Return the locations of the object pointed at by the given position.
std::optional< Hover > findHover(const URIForFile &uri, const Position &hoverPos)
Find a hover description for the given hover position, or std::nullopt if one couldn't be found.
llvm::Expected< MLIRConvertBytecodeResult > convertFromBytecode(const URIForFile &uri)
Convert the given bytecode file to the textual format.
llvm::Expected< MLIRConvertBytecodeResult > convertToBytecode(const URIForFile &uri)
Convert the given textual file to the bytecode format.
MLIRServer(DialectRegistry &registry)
Construct a new server with the given dialect regitstry.
CompletionList getCodeCompletion(const URIForFile &uri, const Position &completePos)
Get the code completion list for the position within the given file.
void findDocumentSymbols(const URIForFile &uri, std::vector< DocumentSymbol > &symbols)
Find all of the document symbols within the given file.
void getCodeActions(const URIForFile &uri, const Range &pos, const CodeActionContext &context, std::vector< CodeAction > &actions)
Get the set of code actions within the file.
URI in "file" scheme for a file.
Definition: Protocol.h:100
Include the generated interface declarations.
Represents a collection of completion items to be presented in the editor.
Definition: Protocol.h:900