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