150
|
1 //===--- XRefs.h -------------------------------------------------*- 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 // Features that traverse references between symbols.
|
|
10 //
|
|
11 //===----------------------------------------------------------------------===//
|
|
12
|
|
13 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
|
|
14 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
|
|
15
|
|
16 #include "FormattedString.h"
|
|
17 #include "Path.h"
|
|
18 #include "Protocol.h"
|
|
19 #include "index/Index.h"
|
|
20 #include "index/SymbolLocation.h"
|
|
21 #include "clang/AST/Type.h"
|
|
22 #include "clang/Format/Format.h"
|
|
23 #include "clang/Index/IndexSymbol.h"
|
|
24 #include "llvm/ADT/Optional.h"
|
|
25 #include "llvm/Support/raw_ostream.h"
|
|
26 #include <vector>
|
|
27
|
|
28 namespace clang {
|
|
29 namespace clangd {
|
|
30 class ParsedAST;
|
|
31
|
|
32 // Describes where a symbol is declared and defined (as far as clangd knows).
|
|
33 // There are three cases:
|
|
34 // - a declaration only, no definition is known (e.g. only header seen)
|
|
35 // - a declaration and a distinct definition (e.g. function declared in header)
|
|
36 // - a declaration and an equal definition (e.g. inline function, or class)
|
|
37 // For some types of symbol, e.g. macros, definition == declaration always.
|
|
38 struct LocatedSymbol {
|
|
39 // The (unqualified) name of the symbol.
|
|
40 std::string Name;
|
|
41 // The canonical or best declaration: where most users find its interface.
|
|
42 Location PreferredDeclaration;
|
|
43 // Where the symbol is defined, if known. May equal PreferredDeclaration.
|
|
44 llvm::Optional<Location> Definition;
|
|
45 };
|
|
46 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const LocatedSymbol &);
|
|
47 /// Get definition of symbol at a specified \p Pos.
|
|
48 /// Multiple locations may be returned, corresponding to distinct symbols.
|
|
49 std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
|
|
50 const SymbolIndex *Index = nullptr);
|
|
51
|
|
52 /// Get all document links
|
|
53 std::vector<DocumentLink> getDocumentLinks(ParsedAST &AST);
|
|
54
|
|
55 /// Returns highlights for all usages of a symbol at \p Pos.
|
|
56 std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
|
|
57 Position Pos);
|
|
58
|
|
59 struct ReferencesResult {
|
|
60 std::vector<Location> References;
|
|
61 bool HasMore = false;
|
|
62 };
|
|
63 /// Returns references of the symbol at a specified \p Pos.
|
|
64 /// \p Limit limits the number of results returned (0 means no limit).
|
|
65 ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
|
|
66 const SymbolIndex *Index = nullptr);
|
|
67
|
|
68 /// Get info about symbols at \p Pos.
|
|
69 std::vector<SymbolDetails> getSymbolInfo(ParsedAST &AST, Position Pos);
|
|
70
|
|
71 /// Find the record type references at \p Pos.
|
|
72 const CXXRecordDecl *findRecordTypeAt(ParsedAST &AST, Position Pos);
|
|
73
|
|
74 /// Given a record type declaration, find its base (parent) types.
|
|
75 std::vector<const CXXRecordDecl *> typeParents(const CXXRecordDecl *CXXRD);
|
|
76
|
|
77 /// Get type hierarchy information at \p Pos.
|
|
78 llvm::Optional<TypeHierarchyItem> getTypeHierarchy(
|
|
79 ParsedAST &AST, Position Pos, int Resolve, TypeHierarchyDirection Direction,
|
|
80 const SymbolIndex *Index = nullptr, PathRef TUPath = PathRef{});
|
|
81
|
|
82 void resolveTypeHierarchy(TypeHierarchyItem &Item, int ResolveLevels,
|
|
83 TypeHierarchyDirection Direction,
|
|
84 const SymbolIndex *Index);
|
|
85
|
|
86 /// Returns all decls that are referenced in the \p FD except local symbols.
|
|
87 llvm::DenseSet<const Decl *> getNonLocalDeclRefs(ParsedAST &AST,
|
|
88 const FunctionDecl *FD);
|
|
89 } // namespace clangd
|
|
90 } // namespace clang
|
|
91
|
|
92 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
|