Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/clangd/IncludeFixer.cpp
Show First 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | if (Info.getNumArgs() > 0) | ||||
getArgStr(Info, 1).value_or(""))); | getArgStr(Info, 1).value_or(""))); | ||||
break; | break; | ||||
} | } | ||||
return {}; | return {}; | ||||
} | } | ||||
llvm::Optional<Fix> IncludeFixer::insertHeader(llvm::StringRef Spelled, | llvm::Optional<Fix> IncludeFixer::insertHeader(llvm::StringRef Spelled, | ||||
llvm::StringRef Symbol) const { | llvm::StringRef Symbol, | ||||
bool ViaImport) const { | |||||
kadircet: again can we rather pass the directive enum around? | |||||
Fix F; | Fix F; | ||||
if (auto Edit = Inserter->insert(Spelled)) | if (auto Edit = Inserter->insert(Spelled, ViaImport)) | ||||
F.Edits.push_back(std::move(*Edit)); | F.Edits.push_back(std::move(*Edit)); | ||||
else | else | ||||
return llvm::None; | return llvm::None; | ||||
if (Symbol.empty()) | if (Symbol.empty()) | ||||
nit: llvm::StringLiteral DirectiveSpelling = Directive == tooling::IncludeDirective::Include ? "Include" : "Import"; and use that inside formatv calls kadircet: nit: `llvm::StringLiteral DirectiveSpelling = Directive == tooling::IncludeDirective::Include ? | |||||
F.Message = llvm::formatv("Include {0}", Spelled); | F.Message = llvm::formatv("{0} {1}", ViaImport ? "Import" : "Include", | ||||
Spelled); | |||||
else | else | ||||
F.Message = llvm::formatv("Include {0} for symbol {1}", Spelled, Symbol); | F.Message = llvm::formatv("{0} {1} for symbol {2}", | ||||
ViaImport ? "Import" : "Include", Spelled, Symbol); | |||||
return F; | return F; | ||||
} | } | ||||
std::vector<Fix> IncludeFixer::fixIncompleteType(const Type &T) const { | std::vector<Fix> IncludeFixer::fixIncompleteType(const Type &T) const { | ||||
// Only handle incomplete TagDecl type. | // Only handle incomplete TagDecl type. | ||||
const TagDecl *TD = T.getAsTagDecl(); | const TagDecl *TD = T.getAsTagDecl(); | ||||
if (!TD) | if (!TD) | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | for (const auto &Inc : getRankedIncludes(Sym)) { | ||||
// FIXME: We should support #import directives here. | // FIXME: We should support #import directives here. | ||||
if ((Inc.Directive & clang::clangd::Symbol::Include) == 0) | if ((Inc.Directive & clang::clangd::Symbol::Include) == 0) | ||||
continue; | continue; | ||||
if (auto ToInclude = Inserted(Sym, Inc.Header)) { | if (auto ToInclude = Inserted(Sym, Inc.Header)) { | ||||
if (ToInclude->second) { | if (ToInclude->second) { | ||||
if (!InsertedHeaders.try_emplace(ToInclude->first).second) | if (!InsertedHeaders.try_emplace(ToInclude->first).second) | ||||
continue; | continue; | ||||
if (auto Fix = | if (auto Fix = | ||||
insertHeader(ToInclude->first, (Sym.Scope + Sym.Name).str())) | insertHeader(ToInclude->first, (Sym.Scope + Sym.Name).str(), | ||||
Inc.Directive == Symbol::Import)) | |||||
Fixes.push_back(std::move(*Fix)); | Fixes.push_back(std::move(*Fix)); | ||||
} | } | ||||
} else { | } else { | ||||
vlog("Failed to calculate include insertion for {0} into {1}: {2}", | vlog("Failed to calculate include insertion for {0} into {1}: {2}", | ||||
Inc.Header, File, ToInclude.takeError()); | Inc.Header, File, ToInclude.takeError()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 286 Lines • Show Last 20 Lines |
again can we rather pass the directive enum around?