Bug 358798 - Source formatter every time selects language as "C"
Summary: Source formatter every time selects language as "C"
Status: RESOLVED NOT A BUG
Alias: None
Product: kdevplatform
Classification: Developer tools
Component: sourceformatter (show other bugs)
Version: 4.90.91
Platform: Kubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-30 20:55 UTC by Piotr Mierzwinski
Modified: 2023-09-15 22:59 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Piotr Mierzwinski 2016-01-30 20:55:11 UTC
I think configuration of "Source formatter" it's not clear, because every time when I open this option I can see that selected is "Language: C". I'm not sure from where KDevelop knows that I use C, whereas I'm working on C++ project :-/.

And some idea.
I think would be nice to have "Source formatter" assigned to project, so configured in project configuration. In KDevelop settings I would configured the settings of "Source formatter" and in project configuration just set it. In this moment KDevelop every time select "Language: C", but when I select "C++" then on list below is highlighted last used formatter - for me newly defined.

Reproducible: Always


Actual Results:  
After defined/selected own "Source formatter" with different than C language - every next invoking this option showing "Language: C".

Expected Results:  
After defined/selected own "Source formatter" with different than C language - every next invoking this option should show selected language.

KDevelop, KDevplatform cloned at 30.12.2016 (at evening) from 5.0 branch.
Comment 1 Kevin Funk 2016-01-31 13:31:17 UTC
Piotr: Thanks a lot for your comprehensive bug reports!

If you got time to work on any of these issues yourself, patches would be highly appreciated! Unfortunately we're all pretty busy with fixing release blockers.

Thanks!
Comment 2 Kevin Funk 2016-01-31 13:31:31 UTC
Piotr: Thanks a lot for your comprehensive bug reports!

If you got time to work on any of these issues yourself, patches would be highly appreciated! Unfortunately we're all pretty busy with fixing release blockers.

Thanks!
Comment 3 Piotr Mierzwinski 2016-01-31 19:12:07 UTC
@Kevin. This is just regular bug report. Fixing the problem is not urgent for me. I didn't mark it anywhere as important/urgent. Milian (in one of bug report) told me, if I find any in sourceformatter then I might to report it.
I understand that release blockers are more important, and this bug doesn't block release.
Would be nice if someone mark it as confirmed.

I know that any patches are highly appreciated. You told me about it earlier (bug related with "crash in debugger"). Unfortunately I don't have so much time to dive in not known source code, analyze how does it work, fix, test and prepare patch. Sorry.
Anyway. I can report bugs. I hope this is helpful.
Comment 4 Igor Kushnir 2020-03-21 11:39:37 UTC
Piotr, I think you are misunderstanding the configuration page. By picking a formatter for each language in the Language combobox you can use different formatters for different languages. The Language combobox does not show the currently configured language, but lets you pick the language you want to select a formatter for.

Here is what I have in my ~/.local/share/kdevelop/sessions/{session-id}/sessionrc:

[SourceFormatter]
ModelinesEnabled=false
OverrideKateIndentation=false
text/x-c++hdr=kdevastyle||Qt
text/x-c++src=kdevastyle||Qt
text/x-chdr=kdevastyle||KDELibs
text/x-csharp=kdevastyle||1TBS
text/x-csrc=kdevastyle||KDELibs
text/x-java=kdevastyle||1TBS
text/x-objcsrc=kdevastyle||1TBS

This is after I picked Qt as the style for the C++ Language and KDELibs as the style for the C Language, while leaving the default 1TBS style for other languages that I don't use.

So if you only use C++, configure the source formatter for this language in KDevelop settings. However note Bug 335549: if your headers have the *.h extension, configure the formatter for the C language as well. You could even use different formatters for headers and source files in this case.

As for your project configuration idea, it's already implemented. There is a Source Formatter section on the Configure Project page.

To summarize:
  - custom formatting styles that a user creates are stored in ~/.config/kdeveloprc. So a user can create a custom style "My style" once, then select it for any other session or project.
  - Source formatters ("Artistic Style" or "Custom Script Formatter") and styles (1TBS, ANSI, ... or "Gnu Indent : GNU", "Clang Format", ...) selections for each language on the Source Formatter page of the Configure KDevelop window are stored separately for each session (as I showed above).
  - Source formatters can also be configured on a per-project basis.

In conclusion, I think there is no bug here, so this issue can be closed as not a bug.
Comment 5 Piotr Mierzwinski 2020-03-24 21:29:42 UTC
(In reply to Igor Kushnir from comment #4)
> Piotr, I think you are misunderstanding the configuration page. By picking a
> formatter for each language in the Language combobox you can use different
> formatters for different languages. The Language combobox does not show the
> currently configured language, but lets you pick the language you want to
> select a formatter for.
> 
> Here is what I have in my
> ~/.local/share/kdevelop/sessions/{session-id}/sessionrc:
> 
> [SourceFormatter]
> ModelinesEnabled=false
> OverrideKateIndentation=false
> text/x-c++hdr=kdevastyle||Qt
> text/x-c++src=kdevastyle||Qt
> text/x-chdr=kdevastyle||KDELibs
> text/x-csharp=kdevastyle||1TBS
> text/x-csrc=kdevastyle||KDELibs
> text/x-java=kdevastyle||1TBS
> text/x-objcsrc=kdevastyle||1TBS
> 
> This is after I picked Qt as the style for the C++ Language and KDELibs as
> the style for the C Language, while leaving the default 1TBS style for other
> languages that I don't use.
> 
> So if you only use C++, configure the source formatter for this language in
> KDevelop settings. However note Bug 335549: if your headers have the *.h
> extension, configure the formatter for the C language as well. You could
> even use different formatters for headers and source files in this case.
> 
> As for your project configuration idea, it's already implemented. There is a
> Source Formatter section on the Configure Project page.
> 
> To summarize:
>   - custom formatting styles that a user creates are stored in
> ~/.config/kdeveloprc. So a user can create a custom style "My style" once,
> then select it for any other session or project.
>   - Source formatters ("Artistic Style" or "Custom Script Formatter") and
> styles (1TBS, ANSI, ... or "Gnu Indent : GNU", "Clang Format", ...)
> selections for each language on the Source Formatter page of the Configure
> KDevelop window are stored separately for each session (as I showed above).
>   - Source formatters can also be configured on a per-project basis.
> 
> In conclusion, I think there is no bug here, so this issue can be closed as
> not a bug.

Yes. You are right. I misunderstood this configuration.
Now I get it that I can just set Formatter for given language and my recent setting (made couple days ago) just reflects this. I mean I had one Formatter for C and for C++ different. Today I checked and all was fine.
And about Artistic Style->Qt what you mentioned that you set in your side and KDevelop thanks that stopped insert spaces next to brackets, I found it also. Before seems I just overlooked this entry in Formatter combobox list. Anyway I have set it for both (C and C++).

Thank you for explanation.
I'm going to change status this ticket.
Comment 6 Piotr Mierzwinski 2020-03-24 21:32:41 UTC
Reported as bug because of incorrect understanding the settings..
Comment 7 Igor Kushnir 2023-07-10 12:17:27 UTC
Git commit 65227a6fe0d5ed14107b5a80561ed8eae618eaf5 by Igor Kushnir.
Committed on 06/06/2023 at 14:37.
Pushed by igorkushnir into branch 'fix-and-refactor-formatter-selection-edit'.

SourceFormatterSelectionEdit: add usage help and info

Configure Source Formatter user interface is unusual. The fact that the
Language combobox defines what is being configured and the Formatter
combobox actually configures something is not obvious (Bug 358798). The
first paragraph of the added usage help should clear this up for new
users.

The second paragraph of the usage help explains what functionality
depends on configured Formatting Styles and why correctly configuring
them is very important. The third paragraph of the usage help points out
the unobvious fact that all *.h are formatted with formatter and style
configured for C language. Piotr Mierzwinski has reported many source
formatter bugs, some of which were caused by incompletely or incorrectly
configured formatting. Hopefully the added usage help will avoid such
user misunderstanding and trouble in the future.

Both AStylePlugin and CustomScriptPlugin implement
ISourceFormatter::description(). The descriptions must have been
translated into many languages long ago, but are not used anywhere. Show
these informative descriptions in Configure Source Formatter UI.

Show the usage help and formatter descriptions as whatsThis of two added
tool buttons. This way, the information is easily discoverable by new
users and practically does not take up useful UI space. The whatsThis
popup can be displayed in two intuitive ways:
1) common: hover over the button, read the tooltip and press Shift;
2) custom: click the button.

Set formatter description whatsThis to an empty string when there are no
enabled formatter plugins. QWhatsThis never shows up when the text is
empty.

Set the tool buttons' iconSize to 22x22. Optimized icons of this size
are present in most icon themes. A button with this icon size is a pixel
or two higher than a combobox in the same row, so only a few pixels of
vertical UI space are lost.

The usage help button is positioned as close as possible to the top left
corner of the SourceFormatterSelectionEdit widget because it explains
the entire interface. The formatter description button is placed to the
right of the Formatter combobox because it describes a selected
formatter. Unfortunately, the resulting misalignment of the buttons and
comboboxes looks weird. On the other hand, the asymmetry might help the
user understand that the two comboboxes have vastly different roles.
Related: bug 335549

M  +11   -0    kdevplatform/shell/sourceformatterselectionedit.cpp
M  +43   -0    kdevplatform/shell/sourceformatterselectionedit.ui

https://invent.kde.org/kdevelop/kdevelop/-/commit/65227a6fe0d5ed14107b5a80561ed8eae618eaf5
Comment 8 Igor Kushnir 2023-09-15 11:26:35 UTC
Git commit 2d8cafaae7ee82ab89507b384f5385f9a21d3f97 by Igor Kushnir.
Committed on 15/09/2023 at 11:57.
Pushed by igorkushnir into branch 'master'.

SourceFormatterSelectionEdit: add usage help and info

Configure Source Formatter user interface is unusual. The fact that the
Language combobox defines what is being configured and the Formatter
combobox actually configures something is not obvious (Bug 358798). The
first paragraph of the added usage help should clear this up for new
users.

The second paragraph of the usage help explains what functionality
depends on configured Formatting Styles and why correctly configuring
them is very important. The third paragraph of the usage help points out
the unobvious fact that all *.h are formatted with formatter and style
configured for C language. Piotr Mierzwinski has reported many source
formatter bugs, some of which were caused by incompletely or incorrectly
configured formatting. Hopefully the added usage help will avoid such
user misunderstanding and trouble in the future.

Both AStylePlugin and CustomScriptPlugin implement
ISourceFormatter::description(). The descriptions must have been
translated into many languages long ago, but are not used anywhere. Show
these informative descriptions in Configure Source Formatter UI.

Show the usage help and formatter descriptions as whatsThis of two added
tool buttons. This way, the information is easily discoverable by new
users and practically does not take up useful UI space. The whatsThis
popup can be displayed in two intuitive ways:
1) common: hover over the button, read the tooltip and press Shift;
2) custom: click the button.

Set formatter description whatsThis to an empty string when there are no
enabled formatter plugins. QWhatsThis never shows up when the text is
empty.

Set the tool buttons' iconSize to 22x22. Optimized icons of this size
are present in most icon themes. A button with this icon size is a pixel
or two higher than a combobox in the same row, so only a few pixels of
vertical UI space are lost.

The usage help button is positioned as close as possible to the top left
corner of the SourceFormatterSelectionEdit widget because it explains
the entire interface. The formatter description button is placed to the
right of the Formatter combobox because it describes a selected
formatter. Unfortunately, the resulting misalignment of the buttons and
comboboxes looks weird. On the other hand, the asymmetry might help the
user understand that the two comboboxes have vastly different roles.
Related: bug 335549

M  +11   -0    kdevplatform/shell/sourceformatterselectionedit.cpp
M  +43   -0    kdevplatform/shell/sourceformatterselectionedit.ui

https://invent.kde.org/kdevelop/kdevelop/-/commit/2d8cafaae7ee82ab89507b384f5385f9a21d3f97
Comment 9 Piotr Mierzwinski 2023-09-15 22:59:05 UTC
Big thanks for fix.