clang-tools 24.0.0git
FindSymbols.h
Go to the documentation of this file.
1//===--- FindSymbols.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// Queries that provide a list of symbols matching a string.
10//
11//===----------------------------------------------------------------------===//
12#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FINDSYMBOLS_H
13#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FINDSYMBOLS_H
14
15#include "index/Symbol.h"
16#include "clang/AST/Decl.h"
17#include "llvm/ADT/StringRef.h"
18
19namespace clang {
20class NamedDecl;
21
22namespace clangd {
23class ParsedAST;
24class SymbolIndex;
25struct Symbol;
26struct SymbolLocation;
27
28/// Helper function for deriving an LSP Location from an index SymbolLocation.
29llvm::Expected<Location> indexToLSPLocation(const SymbolLocation &Loc,
30 llvm::StringRef TUPath);
31
32/// Helper function for deriving an LSP Location for a Symbol.
33llvm::Expected<Location> symbolToLocation(const Symbol &Sym,
34 llvm::StringRef TUPath);
35
36/// Searches for the symbols matching \p Query. The syntax of \p Query can be
37/// the non-qualified name or fully qualified of a symbol. For example,
38/// "vector" will match the symbol std::vector and "std::vector" would also
39/// match it. Direct children of scopes (namespaces, etc) can be listed with a
40/// trailing
41/// "::". For example, "std::" will list all children of the std namespace and
42/// "::" alone will list all children of the global namespace.
43/// \p Limit limits the number of results returned (0 means no limit).
44/// \p HintPath This is used when resolving URIs. If empty, URI resolution can
45/// fail if a hint path is required for the scheme of a specific URI.
46llvm::Expected<std::vector<SymbolInformation>>
47getWorkspaceSymbols(llvm::StringRef Query, int Limit,
48 const SymbolIndex *const Index, llvm::StringRef HintPath);
49
50/// Retrieves the symbols contained in the "main file" section of an AST in the
51/// same order that they appear.
52llvm::Expected<std::vector<DocumentSymbol>> getDocumentSymbols(ParsedAST &AST);
53
54/// Converts a single SymbolTag to a bitmask.
56
57/// Computes symbol tags for a given NamedDecl.
58SymbolTags computeSymbolTags(const NamedDecl &ND);
59
60/// Returns the symbol tags for the given declaration.
61/// This is a wrapper around computeSymbolTags() which unpacks
62/// the tags into a vector.
63/// \p ND The declaration to get tags for.
64std::vector<SymbolTag> getSymbolTags(const NamedDecl &ND);
65
66/// Returns the \c SymbolTag values for the given indexed \p S.
67///
68/// Converts the bitmask stored in \c Symbol::Tags into a flat vector of
69/// \c SymbolTag enum values. For C++ class methods (instance methods, static
70/// methods, constructors, destructors, and conversion functions), a semantic
71/// filter is applied first to remove tags that are implied by higher-priority
72/// tags (e.g. \c Overrides implies \c Virtual, so \c Virtual is suppressed).
73/// For all other symbol kinds the bitmask is expanded as-is.
74///
75/// \param S The indexed symbol whose tags should be returned.
76/// \return A vector of \c SymbolTag values present in \c S.Tags, after
77/// applying any applicable filters.
78std::vector<SymbolTag> getSymbolTags(const Symbol &S);
79} // namespace clangd
80} // namespace clang
81
82#endif
Stores and provides access to parsed AST.
Definition ParsedAST.h:46
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition Index.h:134
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
Definition AST.cpp:44
llvm::Expected< Location > indexToLSPLocation(const SymbolLocation &Loc, llvm::StringRef TUPath)
Helper function for deriving an LSP Location from an index SymbolLocation.
uint32_t SymbolTags
A bitmask type representing symbol tags supported by LSP.
Definition Symbol.h:29
SymbolTag
Symbol tags are extra annotations that can be attached to a symbol.
Definition Protocol.h:1126
std::vector< SymbolTag > getSymbolTags(const Symbol &S)
Returns the SymbolTag values for the given indexed S.
llvm::Expected< Location > symbolToLocation(const Symbol &Sym, llvm::StringRef TUPath)
Helper function for deriving an LSP Location for a Symbol.
SymbolTags toSymbolTagBitmask(const SymbolTag ST)
Converts a single SymbolTag to a bitmask.
llvm::Expected< std::vector< DocumentSymbol > > getDocumentSymbols(ParsedAST &AST)
Retrieves the symbols contained in the "main file" section of an AST in the same order that they appe...
llvm::Expected< std::vector< SymbolInformation > > getWorkspaceSymbols(llvm::StringRef Query, int Limit, const SymbolIndex *const Index, llvm::StringRef HintPath)
Searches for the symbols matching Query.
SymbolTags computeSymbolTags(const NamedDecl &ND)
Computes symbol tags for a given NamedDecl.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Ensure we have enough bits to represent all SymbolTag values.
Definition Symbol.h:49