MLIR  19.0.0git
PDLLServer.h
Go to the documentation of this file.
1 //===- PDLLServer.h - PDL 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_MLIRPDLLSPSERVER_SERVER_H_
10 #define LIB_MLIR_TOOLS_MLIRPDLLSPSERVER_SERVER_H_
11 
12 #include "mlir/Support/LLVM.h"
13 #include "llvm/ADT/StringRef.h"
14 #include <memory>
15 #include <string>
16 #include <optional>
17 
18 namespace mlir {
19 namespace lsp {
20 struct Diagnostic;
21 class CompilationDatabase;
22 struct PDLLViewOutputResult;
23 enum class PDLLViewOutputKind;
24 struct CompletionList;
25 struct DocumentLink;
26 struct DocumentSymbol;
27 struct Hover;
28 struct InlayHint;
29 struct Location;
30 struct Position;
31 struct Range;
32 struct SignatureHelp;
33 struct TextDocumentContentChangeEvent;
34 class URIForFile;
35 
36 /// This class implements all of the PDLL related functionality necessary for a
37 /// language server. This class allows for keeping the PDLL specific logic
38 /// separate from the logic that involves LSP server/client communication.
39 class PDLLServer {
40 public:
41  struct Options {
42  Options(const std::vector<std::string> &compilationDatabases,
43  const std::vector<std::string> &extraDirs)
45 
46  /// The filenames for databases containing compilation commands for PDLL
47  /// files passed to the server.
48  const std::vector<std::string> &compilationDatabases;
49 
50  /// Additional list of include directories to search.
51  const std::vector<std::string> &extraDirs;
52  };
53 
54  PDLLServer(const Options &options);
56 
57  /// Add the document, with the provided `version`, at the given URI. Any
58  /// diagnostics emitted for this document should be added to `diagnostics`.
59  void addDocument(const URIForFile &uri, StringRef contents, int64_t version,
60  std::vector<Diagnostic> &diagnostics);
61 
62  /// Update the document, with the provided `version`, at the given URI. Any
63  /// diagnostics emitted for this document should be added to `diagnostics`.
64  void updateDocument(const URIForFile &uri,
66  int64_t version, std::vector<Diagnostic> &diagnostics);
67 
68  /// Remove the document with the given uri. Returns the version of the removed
69  /// document, or std::nullopt if the uri did not have a corresponding document
70  /// within the server.
71  std::optional<int64_t> removeDocument(const URIForFile &uri);
72 
73  /// Return the locations of the object pointed at by the given position.
74  void getLocationsOf(const URIForFile &uri, const Position &defPos,
75  std::vector<Location> &locations);
76 
77  /// Find all references of the object pointed at by the given position.
78  void findReferencesOf(const URIForFile &uri, const Position &pos,
79  std::vector<Location> &references);
80 
81  /// Return the document links referenced by the given file.
82  void getDocumentLinks(const URIForFile &uri,
83  std::vector<DocumentLink> &documentLinks);
84 
85  /// Find a hover description for the given hover position, or std::nullopt if
86  /// one couldn't be found.
87  std::optional<Hover> findHover(const URIForFile &uri,
88  const Position &hoverPos);
89 
90  /// Find all of the document symbols within the given file.
91  void findDocumentSymbols(const URIForFile &uri,
92  std::vector<DocumentSymbol> &symbols);
93 
94  /// Get the code completion list for the position within the given file.
96  const Position &completePos);
97 
98  /// Get the signature help for the position within the given file.
100  const Position &helpPos);
101 
102  /// Get the inlay hints for the range within the given file.
103  void getInlayHints(const URIForFile &uri, const Range &range,
104  std::vector<InlayHint> &inlayHints);
105 
106  /// Get the output of the given PDLL file, or std::nullopt if there is no
107  /// valid output.
108  std::optional<PDLLViewOutputResult>
110 
111 private:
112  struct Impl;
113  std::unique_ptr<Impl> impl;
114 };
115 
116 } // namespace lsp
117 } // namespace mlir
118 
119 #endif // LIB_MLIR_TOOLS_MLIRPDLLSPSERVER_SERVER_H_
static llvm::ManagedStatic< PassManagerOptions > options
This class implements all of the PDLL related functionality necessary for a language server.
Definition: PDLLServer.h:39
void getLocationsOf(const URIForFile &uri, const Position &defPos, std::vector< Location > &locations)
Return the locations of the object pointed at by the given position.
void getDocumentLinks(const URIForFile &uri, std::vector< DocumentLink > &documentLinks)
Return the document links referenced by the given file.
void getInlayHints(const URIForFile &uri, const Range &range, std::vector< InlayHint > &inlayHints)
Get the inlay hints for the range within the given file.
void addDocument(const URIForFile &uri, StringRef contents, int64_t version, std::vector< Diagnostic > &diagnostics)
Add the document, with the provided version, at 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.
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.
void findDocumentSymbols(const URIForFile &uri, std::vector< DocumentSymbol > &symbols)
Find all of the document symbols within the given file.
std::optional< int64_t > removeDocument(const URIForFile &uri)
Remove the document with the given uri.
CompletionList getCodeCompletion(const URIForFile &uri, const Position &completePos)
Get the code completion list for the position within the given file.
SignatureHelp getSignatureHelp(const URIForFile &uri, const Position &helpPos)
Get the signature help for the position within the given file.
void updateDocument(const URIForFile &uri, ArrayRef< TextDocumentContentChangeEvent > changes, int64_t version, std::vector< Diagnostic > &diagnostics)
Update the document, with the provided version, at the given URI.
PDLLServer(const Options &options)
std::optional< PDLLViewOutputResult > getPDLLViewOutput(const URIForFile &uri, PDLLViewOutputKind kind)
Get the output of the given PDLL file, or std::nullopt if there is no valid output.
URI in "file" scheme for a file.
Definition: Protocol.h:100
PDLLViewOutputKind
The type of output to view from PDLL.
Definition: Protocol.h:32
Include the generated interface declarations.
Represents a collection of completion items to be presented in the editor.
Definition: Protocol.h:887
const std::vector< std::string > & extraDirs
Additional list of include directories to search.
Definition: PDLLServer.h:51
Options(const std::vector< std::string > &compilationDatabases, const std::vector< std::string > &extraDirs)
Definition: PDLLServer.h:42
const std::vector< std::string > & compilationDatabases
The filenames for databases containing compilation commands for PDLL files passed to the server.
Definition: PDLLServer.h:48
Represents the signature of a callable.
Definition: Protocol.h:986