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