1//===- TableGenServer.h - TableGen 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_TBLGENLSPSERVER_TABLEGENSERVER_H_
10#define LIB_MLIR_TOOLS_TBLGENLSPSERVER_TABLEGENSERVER_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;
21struct DocumentLink;
22struct Hover;
23struct Location;
24struct Position;
25struct TextDocumentContentChangeEvent;
26class URIForFile;
27
28/// This class implements all of the TableGen related functionality necessary
29/// for a language server. This class allows for keeping the TableGen specific
30/// logic separate from the logic that involves LSP server/client communication.
31class TableGenServer {
32public:
33 struct Options {
34 Options(const std::vector<std::string> &compilationDatabases,
35 const std::vector<std::string> &extraDirs)
36 : compilationDatabases(compilationDatabases), extraDirs(extraDirs) {}
37
38 /// The filenames for databases containing compilation commands for TableGen
39 /// files passed to the server.
40 const std::vector<std::string> &compilationDatabases;
41
42 /// Additional list of include directories to search.
43 const std::vector<std::string> &extraDirs;
44 };
45
46 TableGenServer(const Options &options);
47 ~TableGenServer();
48
49 /// Add the document, with the provided `version`, at the given URI. Any
50 /// diagnostics emitted for this document should be added to `diagnostics`.
51 void addDocument(const URIForFile &uri, StringRef contents, int64_t version,
52 std::vector<Diagnostic> &diagnostics);
53
54 /// Update the document, with the provided `version`, at the given URI. Any
55 /// diagnostics emitted for this document should be added to `diagnostics`.
56 void updateDocument(const URIForFile &uri,
57 ArrayRef<TextDocumentContentChangeEvent> changes,
58 int64_t version, std::vector<Diagnostic> &diagnostics);
59
60 /// Remove the document with the given uri. Returns the version of the removed
61 /// document, or std::nullopt if the uri did not have a corresponding document
62 /// within the server.
63 std::optional<int64_t> removeDocument(const URIForFile &uri);
64
65 /// Return the locations of the object pointed at by the given position.
66 void getLocationsOf(const URIForFile &uri, const Position &defPos,
67 std::vector<Location> &locations);
68
69 /// Find all references of the object pointed at by the given position.
70 void findReferencesOf(const URIForFile &uri, const Position &pos,
71 std::vector<Location> &references);
72
73 /// Return the document links referenced by the given file.
74 void getDocumentLinks(const URIForFile &uri,
75 std::vector<DocumentLink> &documentLinks);
76
77 /// Find a hover description for the given hover position, or std::nullopt if
78 /// one couldn't be found.
79 std::optional<Hover> findHover(const URIForFile &uri,
80 const Position &hoverPos);
81
82private:
83 struct Impl;
84 std::unique_ptr<Impl> impl;
85};
86
87} // namespace lsp
88} // namespace mlir
89
90#endif // LIB_MLIR_TOOLS_TBLGENLSPSERVER_TABLEGENSERVER_H_
91

source code of mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h