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
18namespace mlir {
19namespace lsp {
20struct Diagnostic;
21class CompilationDatabase;
22struct PDLLViewOutputResult;
23enum class PDLLViewOutputKind;
24struct CompletionList;
25struct DocumentLink;
26struct DocumentSymbol;
27struct Hover;
28struct InlayHint;
29struct Location;
30struct Position;
31struct Range;
32struct SignatureHelp;
33struct TextDocumentContentChangeEvent;
34class 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.
39class PDLLServer {
40public:
41 struct Options {
42 Options(const std::vector<std::string> &compilationDatabases,
43 const std::vector<std::string> &extraDirs)
44 : compilationDatabases(compilationDatabases), extraDirs(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);
55 ~PDLLServer();
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,
65 ArrayRef<TextDocumentContentChangeEvent> changes,
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.
95 CompletionList getCodeCompletion(const URIForFile &uri,
96 const Position &completePos);
97
98 /// Get the signature help for the position within the given file.
99 SignatureHelp getSignatureHelp(const URIForFile &uri,
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>
109 getPDLLViewOutput(const URIForFile &uri, PDLLViewOutputKind kind);
110
111private:
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_
120

source code of mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h