summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/IncludeFixer.h
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2019-02-07 09:23:22 +0000
committerEric Liu <ioeric@google.com>2019-02-07 09:23:22 +0000
commita9e9c506aabe2fe9f4ba9cad8f1fb10b86c89741 (patch)
tree701fc8a0fd41148bf960219b5eb36acf8b4d9546 /clang-tools-extra/clangd/IncludeFixer.h
parent55f7c72beaeeb7c188e6c94ee9049180893ba168 (diff)
downloadbcm5719-llvm-a9e9c506aabe2fe9f4ba9cad8f1fb10b86c89741.tar.gz
bcm5719-llvm-a9e9c506aabe2fe9f4ba9cad8f1fb10b86c89741.zip
[clangd] Suggest adding missing includes for typos (like include-fixer).
Summary: This adds include-fixer feature into clangd based on D56903. Clangd now captures diagnostics caused by typos and attach include insertion fixes to potentially fix the typo. Reviewers: sammccall Reviewed By: sammccall Subscribers: cfe-commits, kadircet, arphaman, mgrang, jkorous, MaskRay, javed.absar, ilya-biryukov, mgorny Tags: #clang Differential Revision: https://reviews.llvm.org/D57021 llvm-svn: 353380
Diffstat (limited to 'clang-tools-extra/clangd/IncludeFixer.h')
-rw-r--r--clang-tools-extra/clangd/IncludeFixer.h37
1 files changed, 35 insertions, 2 deletions
diff --git a/clang-tools-extra/clangd/IncludeFixer.h b/clang-tools-extra/clangd/IncludeFixer.h
index 740710cf4ea..da292b56b00 100644
--- a/clang-tools-extra/clangd/IncludeFixer.h
+++ b/clang-tools-extra/clangd/IncludeFixer.h
@@ -14,6 +14,13 @@
#include "index/Index.h"
#include "clang/AST/Type.h"
#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Sema/ExternalSemaSource.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include <memory>
@@ -34,18 +41,44 @@ public:
std::vector<Fix> fix(DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic &Info) const;
+ /// Returns an ExternalSemaSource that records failed name lookups in Sema.
+ /// This allows IncludeFixer to suggest inserting headers that define those
+ /// names.
+ llvm::IntrusiveRefCntPtr<ExternalSemaSource> unresolvedNameRecorder();
+
private:
/// Attempts to recover diagnostic caused by an incomplete type \p T.
std::vector<Fix> fixIncompleteType(const Type &T) const;
- /// Generates header insertion fixes for \p Sym.
- std::vector<Fix> fixesForSymbol(const Symbol &Sym) const;
+ /// Generates header insertion fixes for all symbols. Fixes are deduplicated.
+ std::vector<Fix> fixesForSymbols(llvm::ArrayRef<Symbol> Syms) const;
+
+ struct UnresolvedName {
+ std::string Name; // E.g. "X" in foo::X.
+ SourceLocation Loc; // Start location of the unresolved name.
+ // Lazily get the possible scopes of the unresolved name. `Sema` must be
+ // alive when this is called.
+ std::function<std::vector<std::string>()> GetScopes;
+ };
+
+ /// Records the last unresolved name seen by Sema.
+ class UnresolvedNameRecorder;
+
+ /// Attempts to fix the unresolved name associated with the current
+ /// diagnostic. We assume a diagnostic is caused by a unresolved name when
+ /// they have the same source location and the unresolved name is the last
+ /// one we've seen during the Sema run.
+ std::vector<Fix> fixUnresolvedName() const;
std::string File;
std::shared_ptr<IncludeInserter> Inserter;
const SymbolIndex &Index;
const unsigned IndexRequestLimit; // Make at most 5 index requests.
mutable unsigned IndexRequestCount = 0;
+
+ // These collect the last unresolved name so that we can associate it with the
+ // diagnostic.
+ llvm::Optional<UnresolvedName> LastUnresolvedName;
};
} // namespace clangd
OpenPOWER on IntegriCloud