Bug 415913

Summary: KDevelop code formatter generates incorrect formatting with kdev_format_source
Product: [Applications] kdevelop Reporter: Scott Deagan <scott.deagan>
Component: AstyleAssignee: kdevelop-bugs-null
Status: RESOLVED NOT A BUG    
Severity: normal    
Priority: NOR    
Version First Reported In: 5.4.5   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Scott Deagan 2020-01-06 02:25:48 UTC
SUMMARY

Code formatting not working correctly when using source formatter "KDevelop: kdev_format_source" with uncrustify.

STEPS TO REPRODUCE

1. Generate uncrustify config file: uncrustify --update-config > myconfig.cfg
2. Open KDevelop
3. Navigate to Settings > Configure KDevelop > Source Formatter.
4. For the "Language" dropdown, select "C++".
5. For the "Formatter" dropdown, select "Custom Script Formatter".
6. In the "Style" listbox, select "KDevelop: kdev_format_source".
7. Click on the "OK" button.
8. Create "format_source" file in the project's root directory.
9. In the "format_source" file, add: */*.cpp: uncrustify -c myconfig.cfg --no-backup $TMPFILE
10. In KDevelop, open a .cpp file that includes a function like:


void test(int someParam1, int someParam2){
  std::cout<<"This is a test..."<<std::endl;
}

11. Right-click in the editor, and select "Reformat Source".

OBSERVED RESULT

  void test(int someParam1, int someParam2)
    {
    std::cout<<"This is a test..."<<std::endl;
  }


EXPECTED RESULT

void test(int someParam1, int someParam2)
{
  std::cout<<"This is a test..."<<std::endl;
}

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 5.17.4
KDE Frameworks Version: 5.65.0
Qt Version: 5.14.0

ADDITIONAL INFORMATION

uncrustify works as expected if the same command in "format_source" is executed directly from a terminal:

uncrustify -c myconfig.cfg --no-backup test.cpp

A workaround:

1. Create an external script.
2. For the "command", use: uncrustify -c myconfig.cfg -f %f
3. For "Output", select "Replace contents of current file"
4. Untick the "Show Output" checkbox.
5. Set a keyboard shortcut for the external script.
Comment 1 Scott Deagan 2020-01-07 19:27:08 UTC
This issue should be closed as it looks like it's an uncrustify issue instead of a KDevelop issue. The same incorrect formatting can be generated from the terminal using:

cat filename.cpp | uncrustify -c myconf.cfg

The file I'm using to test formatting on is classes/SimpleDate.cpp from: https://github.com/syddel/simple-date.

cat classes/SimpleDate.cpp | uncrustify -c myconfig.cfg

produces incorrect output (same as formatting in KDevelop), while:

uncrustify -c myconfig.cfg -f classes/SimpleDate.cpp

produces correct (expected/desired) output.

How can I close this bug? Should I just mark it as "Resolved"?
Comment 2 Kevin Funk 2020-01-08 08:14:05 UTC
I can close it. Thanks for the feedback!