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