IncludeFixerContext
getIncludeFixerContext(const clang::SourceManager &SourceManager,
clang::HeaderSearch &HeaderSearch) const {
- return SemaSource.getIncludeFixerContext(SourceManager, HeaderSearch);
+ return SemaSource.getIncludeFixerContext(SourceManager, HeaderSearch,
+ SemaSource.getMatchedSymbols());
}
private:
T.getUnqualifiedType().getAsString(context.getPrintingPolicy());
DEBUG(llvm::dbgs() << "Query missing complete type '" << QueryString << "'");
// Pass an empty range here since we don't add qualifier in this case.
- query(QueryString, "", tooling::Range());
+ std::vector<find_all_symbols::SymbolInfo> MatchedSymbols =
+ query(QueryString, "", tooling::Range());
- if (GenerateDiagnostics) {
+ if (!MatchedSymbols.empty() && GenerateDiagnostics) {
TypoCorrection Correction;
FileID FID = CI->getSourceManager().getFileID(Loc);
StringRef Code = CI->getSourceManager().getBufferData(FID);
addDiagnosticsForContext(
Correction,
getIncludeFixerContext(CI->getSourceManager(),
- CI->getPreprocessor().getHeaderSearchInfo()),
+ CI->getPreprocessor().getHeaderSearchInfo(),
+ MatchedSymbols),
Code, StartOfFile, CI->getASTContext());
for (const PartialDiagnostic &PD : Correction.getExtraDiagnostics())
CI->getSema().Diag(Loc, PD);
}
DEBUG(llvm::dbgs() << "TypoScopeQualifiers: " << TypoScopeString << "\n");
- query(QueryString, TypoScopeString, SymbolRange);
+ std::vector<find_all_symbols::SymbolInfo> MatchedSymbols =
+ query(QueryString, TypoScopeString, SymbolRange);
clang::TypoCorrection Correction(Typo.getName());
Correction.setCorrectionRange(SS, Typo);
- if (GenerateDiagnostics) {
+ if (!MatchedSymbols.empty() && GenerateDiagnostics) {
FileID FID = SM.getFileID(Typo.getLoc());
StringRef Code = SM.getBufferData(FID);
SourceLocation StartOfFile = SM.getLocForStartOfFile(FID);
addDiagnosticsForContext(
Correction,
- getIncludeFixerContext(SM, CI->getPreprocessor().getHeaderSearchInfo()),
+ getIncludeFixerContext(SM, CI->getPreprocessor().getHeaderSearchInfo(),
+ MatchedSymbols),
Code, StartOfFile, CI->getASTContext());
}
return Correction;
/// Get the include fixer context for the queried symbol.
IncludeFixerContext IncludeFixerSemaSource::getIncludeFixerContext(
const clang::SourceManager &SourceManager,
- clang::HeaderSearch &HeaderSearch) const {
+ clang::HeaderSearch &HeaderSearch,
+ ArrayRef<find_all_symbols::SymbolInfo> MatchedSymbols) const {
std::vector<find_all_symbols::SymbolInfo> SymbolCandidates;
for (const auto &Symbol : MatchedSymbols) {
std::string FilePath = Symbol.getFilePath().str();
return IncludeFixerContext(FilePath, QuerySymbolInfos, SymbolCandidates);
}
-bool IncludeFixerSemaSource::query(StringRef Query, StringRef ScopedQualifiers,
- tooling::Range Range) {
+std::vector<find_all_symbols::SymbolInfo>
+IncludeFixerSemaSource::query(StringRef Query, StringRef ScopedQualifiers,
+ tooling::Range Range) {
assert(!Query.empty() && "Empty query!");
// Save all instances of an unidentified symbol.
Query == QuerySymbolInfos.front().RawIdentifier) {
QuerySymbolInfos.push_back({Query.str(), ScopedQualifiers, Range});
}
- return false;
+ return {};
}
DEBUG(llvm::dbgs() << "Looking up '" << Query << "' at ");
// It's unsafe to do nested search for the identifier with scoped namespace
// context, it might treat the identifier as a nested class of the scoped
// namespace.
- MatchedSymbols = SymbolIndexMgr.search(QueryString, /*IsNestedSearch=*/false);
+ std::vector<find_all_symbols::SymbolInfo> MatchedSymbols =
+ SymbolIndexMgr.search(QueryString, /*IsNestedSearch=*/false);
if (MatchedSymbols.empty())
MatchedSymbols = SymbolIndexMgr.search(Query);
DEBUG(llvm::dbgs() << "Having found " << MatchedSymbols.size()
<< " symbols\n");
- return !MatchedSymbols.empty();
+ // We store a copy of MatchedSymbols in a place where it's globally reachable.
+ // This is used by the standalone version of the tool.
+ this->MatchedSymbols = MatchedSymbols;
+ return MatchedSymbols;
}
llvm::Expected<tooling::Replacements> createIncludeFixerReplacements(