Commit Graph

46 Commits

Author SHA1 Message Date
Artem Sokolovskii
2f18256633 Clangformat: Brings back some of checkboxes
Brought back checkboxes: format while typing, format on save.
Brought back format while typing feature.
Global checkboxes will be hidden in project settings,
and visible for global.

Change-Id: I193cf9e13b10de22091edb5fe04aef957dd74586
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2022-06-30 10:36:49 +00:00
Artem Sokolovskii
8f1a9ea6d7 Revert "ClangFormat: Remove format while typing feature"
This reverts commit 323ba720db.

Reason for revert: The feature is needed

Change-Id: Iaf09ef91c49ff0c85c1b5906a1c1464bd8e4cae6
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2022-06-29 11:53:04 +00:00
Artem Sokolovskii
323ba720db ClangFormat: Remove format while typing feature
Change-Id: I6737c429694218d39fc06c9ef3ce502228e26a2a
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2022-05-25 17:51:32 +00:00
Artem Sokolovskii
b634ec77fc ClangFormat: Fix override checkbox doesn't affect behavior
Override checkbox allows use clangFormat settings
from widget even if there is .clang-format file in
file's folder or parent folder.
It works for global settings and for project settings.

Change-Id: I03152f4b0e1b62b3ac038024e76cc9082fa37ec3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-05-16 07:00:07 +00:00
Artem Sokolovskii
9afe4f958a ClangFormat: Remove unneeded warning
- Remove warning when .clang-format file is absent
- Remove warning when a page is nullptr in addTab function

Change-Id: I4232bc77eaac56c78707fc37aaf75b00b8af9006
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2022-04-26 09:10:05 +00:00
Artem Sokolovskii
72dd90e512 ClangFormat: Start to use new file management
- Indenter uses .clang-format file from a dir of
editing file or from a parent dir. If there is no
such file then indenter starts to use file from a dir
with the name current CodeStyle settings.
- Test fixed

ToDo: Add file absentness processing in case of import

Change-Id: If09ef0c598899856b948c214e524bcfd5dad76e2
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2022-04-20 07:52:17 +00:00
Artem Sokolovskii
4022ed547d [ClangFormat] Remove redundant checkboxes
- Removed redundant checkboxes
- Removed apply button
- Combined checkboxes to combobox

ToDo:
- Specify behavior for global and project settings

Change-Id: I39a00ac8439ae7be3041890f7fc882849685d102
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-03-25 14:17:48 +00:00
Artem Sokolovskii
ab5fdd94f3 [ClangFormat] Add test checkking indentation after Q_OBJECT
Added test checking behavior when after Q_OBJECT all class structure
have correct indenting and redundent tabs doesn't appear before key words
such as  public:, private: , etc.
Made automatic addition Qt defines to StatementMacro to .clang-format files.

Fixes: QTCREATORBUG-26776
Change-Id: I3490421a9caf2831b593939597940358f7ce8f01
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2022-02-10 13:37:05 +00:00
Christian Kandeler
8cc4bbe4d8 ClangFormat: Prepend a space character to our inserted line comment
Otherwise, we could introduce unwanted syntactical constructs, for
instance if the previous character is an asterisk.

Fixes: QTCREATORBUG-25966
Change-Id: Ic0b535861bc1cb4f5f93d06bb11d0f3c7c583893
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-07-05 15:44:51 +00:00
Christian Kandeler
de2c26f7f5 ClangFormat: Prevent adding/removing lines when indenting
In indentation-only mode, any edit that adds or removes newlines is
wrong by definition.

Change-Id: Ida6e729f4d5e8dcd7893fb2bb9407e596661f942
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-07-05 11:26:20 +00:00
Christian Kandeler
b88b73d9c1 ClangFormat: Sprinkle some more magic pixie dust
Apparently, we can prevent clang-format from removing line breaks by
adding an empty comment at the end of the line.

Change-Id: Ia78ecb9e7351d059c544cbda11d33af5734e2218
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-04-12 09:28:55 +00:00
Björn Schäpers
14eb5b382c clangformat: Fix build with LLVM 13
Change-Id: I5eaad17a6f240aa1e3f246492b69f093b4f59fee
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-03-11 07:50:30 +00:00
Eike Ziller
91db1b51ab Fix compilation by not using optional from std
Amends 874029809f

Change-Id: I7eee4700a67b429fa2012389c39a0c965443a065
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2021-02-02 11:03:45 +00:00
Björn Schäpers
d9cd74f06d Texteditor: Add ability to get margin from indenter
And implement it in the clang-format plugin to use the ColumnLimit from
the style. This would be quite useful if you're working on different
projects with a different ColumnLimit. This way you get an visual
representation and do not only have to rely on clang-format.

Change-Id: Ib0258e3fba6f45f0f46ce612f806527a47868ad9
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-01-29 17:03:07 +00:00
hjk
086a4be734 More Qt6 porting
Change-Id: I96bef1772149eb718e250563c65bf5da7259d9d6
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-07-22 15:06:54 +00:00
Christian Kandeler
eaea03ba42 ClangFormat: Adapt to clang 11 API changes
Change-Id: Id5d977e56017a80138f2c033e145b67446eff3ab
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-06-04 10:23:19 +00:00
David Schulz
4070d6a289 Editor: add formatter support
Change-Id: I65590273b2541e08a39970cd9bb4739a5634b2f7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-01-22 06:00:11 +00:00
David Schulz
c56e58fab4 Utils: move text replacement helper to Utils::Text
Change-Id: I82b3304f91d575369e74d5f7404c189e14ba4730
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-01-09 08:23:07 +00:00
David Schulz
372014b843 Editor: Rename format -> autoIndent
Renaming the auto indent function triggered by Ctrl+I to make room
for a real format action.

Change-Id: If5731353311030d66a20f1093a7fdd300703ebbc
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-01-09 07:41:05 +00:00
Ivan Donchevskii
01a528c77a ClangFormat: Fix indentation when empty lines are involved
Unify continuation and new statement to get less false indentations.
Handle one-statement if/else as a special case.
Properly handle empty lines after
 - includes
 - preprocessor directives
 - beginning of the file
 - if/else

Fixes: QTCREATORBUG-22238
Change-Id: Ic334eeca7de47d9fcb74963d2e31711838d04bde
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-04-02 11:32:39 +00:00
Orgad Shaneh
d0867955af ClangFormat: Fix GCC8 warnings
* Missing return (false positive. All enum values are covered).
* Unused static function.

Amends commits 7f0589ef59 and
40fcc728b2.

Change-Id: I0e5c4ae09739a7ca9edbbbbe3f081d8a732245e7
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2019-04-01 06:56:29 +00:00
Ivan Donchevskii
7f0589ef59 ClangFormat: Extract switch statement into function
Clarifies the logic and improves readability.

Change-Id: I42668c65d73fb455996fa3a9bc5384f0b204a778
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-03-12 12:37:01 +00:00
Ivan Donchevskii
d7eeb0bd90 ClangFormat: Reduce dummy text to minimum size
... and tweak continuation dummy text to fix the indentation
for the line with existing text inside parenthesis.

Change-Id: Iaebd2f58823fcbeed24bb7e47769af53261c18ca
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-03-12 10:45:46 +00:00
Ivan Donchevskii
5333331362 ClangFormat: Tweak dummy text for consecutive empty lines
If empty lines follow each other it makes sense to use
the empty comment as dummy text for all but the last one of them.

This prevents increasing indentation lengths after if (foo) when
there are multiple new empty lines inserted.

Change-Id: I4c948161b674b3af0a131bfb85e7a45a80ed3fb0
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-03-12 10:11:12 +00:00
Ivan Donchevskii
cb3a553583 ClangFormat: Indent closing brace on the new line
Sometimes the curly brace also requires indentation.
These are the cases when it comes directly after the
comma, for example inside the initializer list.

Lets handle such cases in the similar way we do it for
the closing parenthesis.

Change-Id: Ia0d25fa08f7224567dd41dd17f9757d9d8b27362
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-03-12 10:10:28 +00:00
Ivan Donchevskii
5006bfb157 ClangFormat: Simplify the dummy text for empty line heuristics
The text to fill the empty line mostly depends not on the
fact of being inside parenthesis or not but rather on the
last preceding meaningful character.

Let's check for this character and sometimes for the following
one to better understand the current context and pick the
proper dummy text.

With this behavior improvement we can better indent empty lines
inside initializer lists with empty lines inside.

Change-Id: Id2f27454ef56dfdf8c15b5efb14c4d09242908a9
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-03-11 10:32:23 +00:00
Ivan Donchevskii
df23fbdc89 ClangFormat: Improve dummy text guessing for empty lines
Improve detection of the cases when the empty line is inside
the parenthesis to get more proper indentation.

Change-Id: I4aa37c29b17bedcd0e4a781d12c7066e818a07f3
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-03-07 14:03:36 +00:00
Ivan Donchevskii
7e5e99d551 ClangFormat: Add whitespace unit-tests and fix bugs
Check that extra whitespace does not prevent the indentation
and that indentation is the same for the consecutive empty lines.

Change-Id: I04aa12c4cd31aaf07daf9320c98d2eea7afcc9a8
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-03-06 14:24:07 +00:00
Ivan Donchevskii
35b0b44b21 ClangFormat: Enable includes sorting
Sort includes only in modes when all replacements are
used (manual indentation with "Format instead of indent" selected
and saving with "Format on save" activated).

Change-Id: I73dfa1d3211760269fe7d33a141f4d831ff65c15
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-03-06 14:23:55 +00:00
Ivan Donchevskii
ad8cabdf45 ClangFormat: Do not remove empty lines while only indenting
Insert dummy text into empty lines also for the electic characters
not to remove empty lines when only indentation is intended.

Fixes: QTCREATORBUG-22050
Change-Id: Ife5374459feb510a0587880a6772c90a2d68d70e
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-03-06 08:44:22 +00:00
Ivan Donchevskii
2484a5e209 ClangFormat: Do not apply "smart" formatting before new lines
In the concept that behavior seemed fine but in practive it
looks quite strange.

Add comma to the dummy text inserted into the empty line to have
a proper indentation for the following empty lines.

Change-Id: I770af02a475e6489bdc8f44d9f84eb3c5e7398d7
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-03-05 13:06:30 +00:00
Ivan Donchevskii
c5e4d73431 ClangFormat: Fix crashes when new project is created
Indenter is used by wizards so make sure it works.

Change-Id: If26eae322e26bf2e32cb86acf45e7b3d33b67e98
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-02-22 13:05:43 +00:00
Ivan Donchevskii
8a93074d0e ClangFormat: Fix the indentation for lines starting with ')'
Fix the insetred text position for such cases.
In the 'smart indentation mode" do not indent empty lines above
the current one but apply the formatting for them instead.

Change-Id: I4cfe7f9778bac5e311aa339e2fcfc717f436cb20
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-02-22 13:05:18 +00:00
Ivan Donchevskii
118c126f98 ClangFormat: Refactor code
Reorder some functions, remove code duplication.

Change-Id: I33e118e567dee7db622bbc99e6a7c500db54e5c5
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-02-20 06:49:47 +00:00
Ivan Donchevskii
be65a57935 ClangFormat: Fix unit-tests
Amends dcf763c7ee.
Change the logic in empty lines modification to properly
indent all empty lines.

Change-Id: Id945cf66915dfd192216660543594a7905426761
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-02-19 12:47:22 +00:00
Ivan Donchevskii
dcf763c7ee ClangFormat: Improve mass indentation performance
Do not indent lines separately but call reformat only
once and then extract the proper replacements.

Remove some redundant code in process.

Change-Id: If3a0419fef9fb2ec5422d11343fdc3414f5751b7
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-02-19 07:33:33 +00:00
Ivan Donchevskii
7f461b2e22 ClangFormat: Clean up some code and and few unit-tests
Check the context related stuff and remove the restriction
to format after the stream operator.

Change-Id: Iaa2d32c9bffe7a0eeb7e8ade39f109b529e1eab0
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-02-19 07:33:20 +00:00
Ivan Donchevskii
9bcc871ece ClangFormat: Format multiple text ranges at once
'reformat' function in LibFormat accepts mutilple ranges.
Let's provide the ranges for the same file together when
formatting on save and formatting after fix-its.

Change-Id: I27789da83a1efc27beb57acf238508a191562bb9
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-02-19 07:33:13 +00:00
Ivan Donchevskii
4066dee257 ClangFormat: Improve formatting performance to reformat the whole file
Allows not to cut the file and removes extra logic.

To achieve that do "smart" formatting in one go by adding a trick
with comment to keep the last line break and provide the proper indent
for the current line together with formatting the code above.

Disable adding namespace comments because it causes one extra
formatting pass (not for the manual formatting).

Change-Id: I8f644129606238c5438e636f56e6097ab149aa0c
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-02-12 13:16:22 +00:00
Ivan Donchevskii
1740fcc008 ClangFormat: Take line context into account when formatting
In some cases indenting/formatting after special characters can
break the code. Let's try to avoid such corner cases.

Change-Id: I8918bc460af31d696e49f60e0ea85f34e9ff5664
Fixes: QTCREATORBUG-21474
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-02-11 11:08:09 +00:00
Ivan Donchevskii
536b733f29 ClangFormat: Format more code while typing
With the extra option "Format while typing" checked try to format
text before the current position without breaking the current input.
To accomplish that we make proper choices which replacements to apply.

The advantage of this change is to decrease the need to manually
format code which is just written.

Some minor bugs are fixed during the testing of this change.

Change-Id: Ibed569042e6c46a881e7a83b1882cf2bb23b3626
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-02-05 08:36:06 +00:00
Ivan Donchevskii
1dee275f58 ClangFormat: Add cursor position to the indenter interface
Sometimes it's imnportant where the cursor currently is
to properly format the code without affecting the current line.

Change-Id: I8b1fb11d2303adb5f960c7cb80a0ed2e6e45010f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-01-31 10:25:18 +00:00
Ivan Donchevskii
80fb0178fd ClangFormat: Introduce check to format code instead of indenting
Ctrl+I with the new check will reformat the selected code or
the current line instead.

Change-Id: Ia5a72c4a09621034d0dfe463f669fe1ca36b0b5f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-01-31 10:25:05 +00:00
Orgad Shaneh
2781c2a900 ClangFormat: Remove #pragma once from source file
Detected by GCC8.

Amends commit d7058e1afe.

Change-Id: I06c6f23dc69ab729a45f3bf9a8aff53e41b35cfa
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2019-01-23 06:22:54 +00:00
Ivan Donchevskii
def5248db2 ClangFormat: Reduce the amount of electric characters
Adding '.' or ',' very ofter makes the statement invalid.
Do not force the formatting in such cases.

Change-Id: I7e58e5af6eed065a3bc0df29698aececa579feed
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-01-22 14:18:10 +00:00
Ivan Donchevskii
d7058e1afe ClangFormat: Refactor indenter to allow ClangFormat unit-tests
We do not build texteditor files in unit-tests so some tricks
were required to make ClangFormatIndenter available.

First simple unit-test proofs it builds and runs.

Change-Id: I81d5ea099bd27fd1c1ed8b5b7877299dcc62a67f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2019-01-22 09:52:15 +00:00