clang-tools 23.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 "Protocol.h"
16#include "index/Symbol.h"
17#include "clang/AST/Decl.h"
18#include "llvm/ADT/StringRef.h"
19
20namespace clang {
21namespace clangd {
22class ParsedAST;
23class SymbolIndex;
24
25/// A bitmask type representing symbol tags supported by LSP.
26/// \see
27/// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#symbolTag
28using SymbolTags = uint32_t;
29/// Ensure we have enough bits to represent all SymbolTag values.
30static_assert(static_cast<unsigned>(SymbolTag::LastTag) <= 32,
31 "Too many SymbolTags to fit in uint32_t. Change to uint64_t if "
32 "we ever have more than 32 tags.");
33
34/// Helper function for deriving an LSP Location from an index SymbolLocation.
35llvm::Expected<Location> indexToLSPLocation(const SymbolLocation &Loc,
36 llvm::StringRef TUPath);
37
38/// Helper function for deriving an LSP Location for a Symbol.
39llvm::Expected<Location> symbolToLocation(const Symbol &Sym,
40 llvm::StringRef TUPath);
41
42/// Searches for the symbols matching \p Query. The syntax of \p Query can be
43/// the non-qualified name or fully qualified of a symbol. For example,
44/// "vector" will match the symbol std::vector and "std::vector" would also
45/// match it. Direct children of scopes (namespaces, etc) can be listed with a
46/// trailing
47/// "::". For example, "std::" will list all children of the std namespace and
48/// "::" alone will list all children of the global namespace.
49/// \p Limit limits the number of results returned (0 means no limit).
50/// \p HintPath This is used when resolving URIs. If empty, URI resolution can
51/// fail if a hint path is required for the scheme of a specific URI.
52llvm::Expected<std::vector<SymbolInformation>>
53getWorkspaceSymbols(llvm::StringRef Query, int Limit,
54 const SymbolIndex *const Index, llvm::StringRef HintPath);
55
56/// Retrieves the symbols contained in the "main file" section of an AST in the
57/// same order that they appear.
58llvm::Expected<std::vector<DocumentSymbol>> getDocumentSymbols(ParsedAST &AST);
59
60/// Converts a single SymbolTag to a bitmask.
62
63/// Computes symbol tags for a given NamedDecl.
64SymbolTags computeSymbolTags(const NamedDecl &ND);
65
66/// Returns the symbol tags for the given declaration.
67/// This is a wrapper around computeSymbolTags() which unpacks
68/// the tags into a vector.
69/// \p ND The declaration to get tags for.
70std::vector<SymbolTag> getSymbolTags(const NamedDecl &ND);
71
72} // namespace clangd
73} // namespace clang
74
75#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)
Ensure we have enough bits to represent all SymbolTag values.
uint32_t SymbolTags
A bitmask type representing symbol tags supported by LSP.
Definition FindSymbols.h:28
SymbolTag
Symbol tags are extra annotations that can be attached to a symbol.
Definition Protocol.h:1109
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...
std::vector< SymbolTag > getSymbolTags(const NamedDecl &ND)
Returns the symbol tags for the given declaration.
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++ -*-===//
The class presents a C++ symbol, e.g.
Definition Symbol.h:39