1 //===-- IndexHelpers.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 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTINDEX_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTINDEX_H
11 
12 #include "index/Index.h"
13 
14 namespace clang {
15 namespace clangd {
16 
17 // Creates Symbol instance and sets SymbolID to given QualifiedName.
18 Symbol symbol(llvm::StringRef QName);
19 
20 // Helpers to produce fake index symbols with proper SymbolID.
21 // USRFormat is a regex replacement string for the unqualified part of the USR.
22 Symbol sym(llvm::StringRef QName, index::SymbolKind Kind,
23            llvm::StringRef USRFormat);
24 // Creats a function symbol assuming no function arg.
25 Symbol func(llvm::StringRef Name);
26 // Creates a class symbol.
27 Symbol cls(llvm::StringRef Name);
28 // Creates an enum symbol.
29 Symbol enm(llvm::StringRef Name);
30 // Creates a variable symbol.
31 Symbol var(llvm::StringRef Name);
32 // Creates a namespace symbol.
33 Symbol ns(llvm::StringRef Name);
34 // Create a C++20 concept symbol.
35 Symbol conceptSym(llvm::StringRef Name);
36 
37 // Create an Objective-C symbol.
38 Symbol objcSym(llvm::StringRef Name, index::SymbolKind Kind,
39                llvm::StringRef USRPrefix);
40 // Create an @interface or @implementation.
41 Symbol objcClass(llvm::StringRef Name);
42 // Create an @protocol.
43 Symbol objcProtocol(llvm::StringRef Name);
44 
45 // Create a slab of symbols with the given qualified names as IDs and names.
46 SymbolSlab generateSymbols(std::vector<std::string> QualifiedNames);
47 
48 // Create a slab of symbols with IDs and names [Begin, End].
49 SymbolSlab generateNumSymbols(int Begin, int End);
50 
51 // Returns fully-qualified name out of given symbol.
52 std::string getQualifiedName(const Symbol &Sym);
53 
54 // Performs fuzzy matching-based symbol lookup given a query and an index.
55 // Incomplete is set true if more items than requested can be retrieved, false
56 // otherwise.
57 std::vector<std::string> match(const SymbolIndex &I,
58                                const FuzzyFindRequest &Req,
59                                bool *Incomplete = nullptr);
60 
61 // Returns qualified names of symbols with any of IDs in the index.
62 std::vector<std::string> lookup(const SymbolIndex &I,
63                                 llvm::ArrayRef<SymbolID> IDs);
64 
65 } // namespace clangd
66 } // namespace clang
67 
68 #endif
69