https://bugs.kde.org/show_bug.cgi?id=475921
--- Comment #2 from shlyonskikh.ale...@gmail.com --- (In reply to Igor Kushnir from comment #1) > > The cause is likely the KDevelop::extractFormattedTextFromContext function > > from kdevplatform/util/formattinghelpers.cpp file, called from > > plugins/customscript/customscript_plugin.cpp . The text matching done there > > fails to match parts of the file when its lines have been switched around. > You are right. My reimplementation of extractFormattedTextFromContext() in > https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/118 was recently > merged and will be available in the next released KDevelop version (5.13 or > 6.0). But the reimplementation does not support reordering include lines. > > Since the include lines contain alphanumeric (significant) characters, a > separate specific mechanism to ignore such diff will have to be implemented. > The implementation should be very careful and limited to avoid breaking user > code by mismatching context(s) or text. If you have an idea how to fix this, > we can discuss it here or you can create a (Draft) merge request for a more > involved discussion and review. I think the most obvious solution that will work in every case is making a separate plugin that passes --offset and --length to clang-format, then replaces the whole file with the result. But if that's not an option, here is a rough idea for a new way to format that should handle this case well enough: 1. Split the original file and the formatted file into blocks of lines that start with #include (plus empty ones) and other lines. Take care not to confuse #include lines with raw literal text where one of its lines starts with #include. 2. For every #include block, ensure the user either selects the whole block or none of it, error otherwise. Ensure all blocks match up, error otherwise (if it's not the whole file that's selected): match the normal blocks of code normally (for brace checking, the non-#include line blocks could be treated as continuous text); match includes by remembering the lines contained in the block, splitting them into lexemes beforehand --- if all lines in such a block are the same includes, everything is fine, error otherwise. 3. If no lines in a block are selected, write the original lines. If the whole block is selected, write its lines from the formatter's output. Otherwise (it's not an #include block), do the same thing as now but instead of the whole file only consider this block of lines. -- You are receiving this mail because: You are watching all bug changes.