Commit Graph
128 Commits
Author SHA1 Message Date
Mikhail Golubev eb64521ae2 PY-20744 Python formatter is aware of variable annotations 2016-09-16 08:16:26 +03:00
Mikhail Golubev 10abeaea46 PY-20392 Handle ambiguous settings for space after trailing comma in collection literals
If one has chosen to omit a space after comma in settings but still
wants a space within braces or brackets in collection literals.
2016-08-25 15:07:14 +03:00
Mikhail Golubev 2d8fe72a93 PY-20392 Put space after trailing comma in dict literals if SPACE_AFTER_COMMA is enabled 2016-08-25 15:07:13 +03:00
Mikhail Golubev 01b33880f9 PY-18265 Add dedicated option for spacing around "**" operator 2016-01-27 15:17:52 +03:00
Mikhail Golubev 0f0ee7d731 PY-13304, PY-17979 Add option that allows to use continuation indent for arguments 2016-01-13 20:19:39 +03:00
Mikhail Golubev 5b763d7de7 PY-17979 Reverted controversial fix for the PY-13304
Continuation indent is used for function arguments only to avoid
structure ambiguity.
2016-01-13 20:19:39 +03:00
Mikhail Golubev cde29bdae2 PY-17674 Add linefeed before right brace in dict literals when it's preceded by colon
Rules about literal braces is considered earlier than those for colons
in spacing builder.
2015-11-17 12:55:40 +03:00
Mikhail Golubev 41f66d616d PY-17564 Keep blank lines between imports inserted by user
It doesn't solve the problem that reformatting doesn't add blank lines
before import groups according to PEP-8 until "Optimize Imports" is
called on a file, but at least it doesn't remove blank lines inserted
manually by user.
2015-11-13 17:23:05 +03:00
Mikhail Golubev c9a2a6396f PY-13304 Always use continuation indent after function arguments
It probably conflicts with existing fix for PY-12749.
2015-11-09 13:51:12 +03:00
Mikhail Golubev 5c4b6ceaa4 PY-15791 Force spaces around "=" sign preceding default value of annotated parameter 2015-07-16 19:15:11 +03:00
Mikhail Golubev b633713288 PY-16393 Ignore intermediate comments while searching for line feed to recognize hanging indent 2015-07-07 12:40:39 +03:00
Mikhail Golubev f71d87d428 PY-15701 Allow to specify minimum number of blank lines after local imports
Add new option "After local imports" on "Blank lines" tab of Python
code style settings.
2015-06-17 21:00:44 +03:00
Mikhail Golubev 1a35c61156 PY-9923 Add two blank lines between top-level declarations and surrounding statements 2015-06-17 21:00:43 +03:00
Mikhail Golubev 6b5ea8f750 PY-16050 Formatter inserts exactly one space after ":" and "->" in annotations 2015-05-27 22:45:01 +03:00
Mikhail Golubev df512e8b7d PY-14962 Allow to enforce braces position for dict literals like it's done e.g. for JavaScript 2015-05-27 22:45:00 +03:00
Mikhail Golubev e0bb7c5a6d PY-14962 Allow to specify wrapping for key-value pairs of dict literals 2015-05-25 21:37:48 +03:00
Yaroslav Lepenkin 1bcff41926 [PsiBasedFormattingModel] Perform whitespace modification with disabled automatic formatting of changed psi elements. Changed whitespace would not be formatted twice, which will prevent from reformatting whitespaces of aligned blocks and producing inconsistent result 2015-05-14 15:19:38 +03:00
Mikhail Golubev 3a2c670972 PY-14962 Add tests for new dict formatting options 2015-05-14 13:37:24 +03:00
Mikhail Golubev a0ae967b34 PY-12360 Do not add trailing blank line in Python template languages and injected fragments
Additionally now PyTrailingBlankLinesPostFormatProcessor modifies adjacent
whitespace when reformat action was called on a single PSI element, similarly
to the way it works for specific text range (hence the change in test data).
2015-05-06 01:52:29 +03:00
Mikhail Golubev ec61bd4736 PY-12360 Fix test data in remaining tests, commit document after modification 2015-04-27 20:34:51 +03:00
Mikhail Golubev 15cf5b06f6 PY-12360 Do not add extra blank line at the end of empty file 2015-04-27 20:34:50 +03:00
Mikhail Golubev a1382d3f9a PY-12360 PyTrailingBlankLinesPostFormatProcessor operates solely on Document level
Since it finally works as expected now, I also updated test data files to include this extra
line feed required by PEP8.
2015-04-27 20:34:49 +03:00
Mikhail Golubev 09f918bf28 PY-12360 More robust way to handle trailing continuation backslashes
Python lexer and parser can split whitespaces and attach them to different parents,
so we have to scan backward through consequtive leaf elements to collect all of them.

I also added several new tests for various such corner cases.
2015-04-27 20:34:49 +03:00
Mikhail Golubev 6792b58ce4 PY-15171 Detect hanging indent in the value of key-value pair in dict literals 2015-04-27 20:34:48 +03:00
Mikhail Golubev 32b76de893 PY-11552 Keep maximum 1 empty line between declarations and in code by default
Fix affected test data where reformat is invoked during refactoring.
Also use entire sample provided by user in the corresponding test case
for the issue.
2015-04-27 20:34:47 +03:00
Mikhail Golubev ff28809f20 Remove formatter logic that prevented proper alignment of empty collection literals
It was added a while back for PY-6751, but corresponding test
passes without it now. Also it turned out that
PyIndentTest#testEnterInDictInTuple depended on this change, but
behavior tested there was recreated (once again) by proper use of
hasHangingIndent in formatter, i.e. once opening and closing braces of
the dict are on different lines, the literal should not have alignment.
2015-04-23 22:06:23 +03:00
Mikhail Golubev 5181eedd3d Hanging indent detection takes into account named parameters and default values of arguments 2015-04-23 22:06:22 +03:00
Mikhail Golubev efc43fbd53 PY-15530 Fix detection of hanging indent for the case of function call as the first argument of another call
Hanging indent is recognized only when there is no items after
opening brace AND there is no closing brace on the same line.
2015-04-23 22:06:22 +03:00
Mikhail Golubev 6d9c1caa12 PY-11552 Automatically remove blank lines at the end of file using dedicated PostFormatProcessor 2015-04-23 17:45:59 +03:00
Mikhail Golubev e033602143 PY-12932 Fix wrong test data 2015-02-09 21:48:34 +03:00
Mikhail Golubev 4ca4d0d396 PY-12932 Fix trailing comment detection when it's the first child element 2015-02-09 21:43:37 +03:00
Mikhail Golubev 909ed2837e PY-13232 Remove ignoring of multiline comments that was previously added for PY-12932
It would not help to preseve indentation of code fragments commented
without whitespace after '#' (i.e. commented not in PyCharm) anyway.
2015-02-09 20:32:14 +03:00
Mikhail Golubev 1fcf101da8 Add test cases for comment formatting scenarios described in PY-12938 2015-02-09 20:03:12 +03:00
Mikhail Golubev e5f1141929 PY-12932 New policy for pre-formatting comments in Python code
In addition to existing detection of shebang/double hash/doc comments we
consider the following new cases when trying to insert space after '#'
in Python line comments:

* Comments that already start with whitespace are ignored by
formatter.
* Comments that span several lines (up to the first empty line or
non-whitespace element) are not altered either because they may contain
Python code fragments.
* Trailing comments however can be safely adjusted because even if
they contain any code, there cannot be any indentation inside.
2015-02-09 20:03:12 +03:00
Mikhail Golubev 969213593e Align closing parenthesis in PyFromImportStatement if needed
Closing parenthesis is aligned inside PyFromImportStatement the same way
it was done previously for various braces in collection literals and
parameter/argument lists, i.e. it's aligned with PyImportElements if
there is no hanging indent after opening parenthesis.
2015-01-29 13:03:50 +03:00
Mikhail Golubev a74226bac9 PY-12748 Indent comments inside multiline imports
It was done so already for other elements with braces that may
span multiple lines, e.g. literals of collections and parameter/argument
lists. Now formatter behavior for PyFromImportStatement is consistent
with them.
2015-01-29 13:03:49 +03:00
Mikhail Golubev 0f6f631210 Unconditionally add alignment to arguments when there is no hanging indent 2015-01-29 13:03:49 +03:00
Mikhail Golubev e4d7a000db PY-12749 Sparingly use continuation indents for arguments in the headers of control statements
Usage of continuation indents (which presumably are wider than normal
indents) in the headers of control statements was supposed to prevent
PEP8's error E125 "Continuation line with same indent as next logical
line". However such indents is not necessary for e.g. nested function
calls where indent of the arguments is already visually distinctive
(larger) from the offset of the following statement list. To
distinguish such cases I've added check that argument list is located
on the same line as the header of the containing control statement. If
line numbers differ we use normal indent for the arguments and
continuation indent otherwise. It doesn't matter for complex
non-hanging indent cases like if foo(bar(1... because alignment will
be used there anyway.
2015-01-29 13:03:49 +03:00
Mikhail Golubev 964d78b0d9 PY-13004 Add test for the code sample given by user
Issue itself was fixed earlier together with PY-12145, PY-14838 and
PY-13955.
2015-01-29 13:03:48 +03:00
Mikhail Golubev 6719f44e51 PY-14408 PyBlock#isWhitespaceWithLineBreaks takes into account multiple sibling PsiWhiteSpaces
When we use tab characters for indents in Python sources, for some
reason indents and line feeds inside literal expressions for
collections are represented as several consecutive PsiWhiteSpace
elements. Method isWhitespaceWithLineBreaks can't count new lines in
such cases correctly and hence PyBlocks for PyKeyValuePair don't get
desired indentation.
2015-01-21 22:51:00 +03:00
Mikhail Golubev 4ced2f94f7 PY-12145 Align closing brace when there is no hanging indent in parental expression
Also update expected test data in a couple of existing tests to be PEP8 complaint
2015-01-19 21:41:13 +03:00
Mikhail Golubev 697afe15ec PY-14838, PY-13955 Do not align function arguments when first of them contains "hanging indent"
Regardless of option "Align multiline call arguments", alignment should
take place only when there is no, so called, "hanging indent" in function
call (see PEP-8). In accordance to behavior of 'pep8' utility several such
indents at the end of line are collapsed into one. E.g. fragment
'func([{\n' is considered as having "hanging indent" both for function
call, list and dict literals.
2015-01-19 21:41:13 +03:00
Mikhail Golubev 65cc6f3fbf PY-12861 Remove whitespaces before/after parenthesis in Python formatter 2015-01-19 21:41:12 +03:00
Mikhail Golubev 5e30498fe5 Strip spaces before/after parenthesis inside generator expression 2014-09-25 14:10:37 +04:00
Mikhail Golubev d96766df2d PyFormatterModelBuilder always uses PyFile as root block element
The same way FormatterModelBuilders are implemented for Java and JavaScript.
It allows to call codeStyleManager.reformat(PsiElement) directly instead of
codeStyleManager.reformatText(elt.getContainingFile(),
elt.getTextRange().getStartOffset(), elt.getTextRange().getEndOffset());
2014-08-29 16:38:45 +04:00
Dmitry Trofimov 08cab53d7e Fixed shebang formatting (PY-12775). 2014-06-10 14:16:47 +04:00
Dmitry Trofimov 62476fa88f Fix alignment in list comprehension in dict (PY-10076). 2014-02-04 13:59:25 +04:00
Dmitry Trofimov a15373896e Fix test data to satisfy PEP8 2014-02-03 14:13:31 +04:00
Dmitry Trofimov 0147c24bb2 Added test for PY-11337 2014-01-24 21:28:09 +01:00
Dmitry Trofimov 4db90932c0 Fix align multiline elements in parenthesized expressions, parameters and arguments lists. 2014-01-23 22:12:30 +01:00