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