1 //===-- SymbolIndexManager.h - Managing multiple SymbolIndices --*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_SYMBOLINDEXMANAGER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_SYMBOLINDEXMANAGER_H
12 #include "SymbolIndex.h"
13 #include "find-all-symbols/SymbolInfo.h"
14 #include "llvm/ADT/StringRef.h"
17 // Disable warnings from ppltasks.h transitively included by <future>.
19 #pragma warning(disable:4530)
29 namespace include_fixer
{
31 /// This class provides an interface for finding the header files corresponding
32 /// to an identifier in the source code from multiple symbol databases.
33 class SymbolIndexManager
{
35 void addSymbolIndex(std::function
<std::unique_ptr
<SymbolIndex
>()> F
) {
36 #if LLVM_ENABLE_THREADS
37 auto Strategy
= std::launch::async
;
39 auto Strategy
= std::launch::deferred
;
41 SymbolIndices
.push_back(std::async(Strategy
, F
));
44 /// Search for header files to be included for an identifier.
45 /// \param Identifier The identifier being searched for. May or may not be
47 /// \param IsNestedSearch Whether searching nested classes. If true, the
48 /// method tries to strip identifier name parts from the end until it
49 /// finds the corresponding candidates in database (e.g for identifier
50 /// "b::foo", the method will try to find "b" if it fails to find
53 /// \returns A list of symbol candidates.
54 std::vector
<find_all_symbols::SymbolInfo
>
55 search(llvm::StringRef Identifier
, bool IsNestedSearch
= true,
56 llvm::StringRef FileName
= "") const;
59 std::vector
<std::shared_future
<std::unique_ptr
<SymbolIndex
>>> SymbolIndices
;
62 } // namespace include_fixer