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