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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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