| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INCLUDEFIXER_H |
| 10 |
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INCLUDEFIXER_H |
| 11 |
|
| 12 |
#include "Diagnostics.h" |
| 13 |
#include "Headers.h" |
| 14 |
#include "index/Index.h" |
| 15 |
#include "index/Symbol.h" |
| 16 |
#include "clang/AST/Type.h" |
| 17 |
#include "clang/Basic/Diagnostic.h" |
| 18 |
#include "clang/Basic/SourceLocation.h" |
| 19 |
#include "clang/Sema/ExternalSemaSource.h" |
| 20 |
#include "clang/Tooling/Inclusions/HeaderIncludes.h" |
| 21 |
#include "llvm/ADT/DenseMap.h" |
| 22 |
#include "llvm/ADT/IntrusiveRefCntPtr.h" |
| 23 |
#include "llvm/ADT/StringMap.h" |
| 24 |
#include "llvm/ADT/StringRef.h" |
| 25 |
#include <memory> |
| 26 |
#include <optional> |
| 27 |
|
| 28 |
namespace clang { |
| 29 |
namespace clangd { |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class IncludeFixer { |
| 35 |
public: |
| 36 |
IncludeFixer(llvm::StringRef File, std::shared_ptr<IncludeInserter> Inserter, |
| 37 |
const SymbolIndex &Index, unsigned IndexRequestLimit, |
| 38 |
Symbol::IncludeDirective Directive) |
| 39 |
: File(File), Inserter(std::move(Inserter)), Index(Index), |
| 40 |
IndexRequestLimit(IndexRequestLimit), Directive(Directive) {} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
std::vector<Fix> fix(DiagnosticsEngine::Level DiagLevel, |
| 45 |
const clang::Diagnostic &Info) const; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
llvm::IntrusiveRefCntPtr<ExternalSemaSource> unresolvedNameRecorder(); |
| 51 |
|
| 52 |
private: |
| 53 |
|
| 54 |
std::vector<Fix> fixIncompleteType(const Type &T) const; |
| 55 |
|
| 56 |
|
| 57 |
std::vector<Fix> fixesForSymbols(const SymbolSlab &Syms) const; |
| 58 |
|
| 59 |
std::optional<Fix> insertHeader(llvm::StringRef Name, |
| 60 |
llvm::StringRef Symbol = "", |
| 61 |
tooling::IncludeDirective Directive = |
| 62 |
tooling::IncludeDirective::Include) const; |
| 63 |
|
| 64 |
struct UnresolvedName { |
| 65 |
std::string Name; |
| 66 |
SourceLocation Loc; |
| 67 |
std::vector<std::string> Scopes; |
| 68 |
}; |
| 69 |
|
| 70 |
|
| 71 |
class UnresolvedNameRecorder; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
std::vector<Fix> fixUnresolvedName() const; |
| 78 |
|
| 79 |
std::string File; |
| 80 |
std::shared_ptr<IncludeInserter> Inserter; |
| 81 |
const SymbolIndex &Index; |
| 82 |
const unsigned IndexRequestLimit; |
| 83 |
mutable unsigned IndexRequestCount = 0; |
| 84 |
const Symbol::IncludeDirective Directive; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
std::optional<UnresolvedName> LastUnresolvedName; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
mutable llvm::StringMap<SymbolSlab> FuzzyFindCache; |
| 95 |
mutable llvm::DenseMap<SymbolID, SymbolSlab> LookupCache; |
| 96 |
|
| 97 |
std::optional<const SymbolSlab *> |
| 98 |
fuzzyFindCached(const FuzzyFindRequest &Req) const; |
| 99 |
std::optional<const SymbolSlab *> lookupCached(const SymbolID &ID) const; |
| 100 |
}; |
| 101 |
|
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
#endif |