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