Commit c321a913 authored by Daniel Mensinger's avatar Daniel Mensinger

clangFormat: Sort includes

parent 0632bc41
Pipeline #8535 passed with stage
in 48 minutes and 17 seconds
......@@ -189,19 +189,31 @@ QString ClangFormatPlugin::formatSourceWithStyle(SourceFormatterStyle style, con
return text;
}
// LLVM uses string REFERENCES ==> always keep the original string around on the stack
string filename = url.fileName().toStdString();
if (filename.empty()) {
filename = "<stdin>";
}
tooling::Range codeRange(left.size(), center.size());
auto replacements = format::reformat(cfStyle, code, { codeRange }, filename);
// Includes have to be sorted seperately (not sure why but thats waht clang-format does)
auto replacements = format::sortIncludes(cfStyle, code, { codeRange }, filename);
auto result = tooling::applyAllReplacements(code, replacements);
if (!result) {
return text;
}
code = *result;
auto newRanges = tooling::calculateRangesAfterReplacements(replacements, { codeRange });
// Do the main clang-format
replacements = format::reformat(cfStyle, code, newRanges, filename);
result = tooling::applyAllReplacements(code, replacements);
if (!result) {
return text;
}
return KDevelop::extractFormattedTextFromContext(QString::fromStdString(*result), text, leftContext, rightContext,
cfStyle.TabWidth);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment