-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Fix commenting/uncommenting to not change leading whitespaces #14768
Conversation
Hi @remisalmon thanks for the help! However after a quick review seems like you changed the previous test available. So the new version of the tests seems like are not covering all the cases that the old test did? Pinging @ccordoba12 just in case |
@dalthviz yes I did changes the tests because the changes to So for ex. toggling the comments off (Ctrl+1) on spyder 3-style comments like: #from pprint import pprint
#x = [1,
# 2]
#y=[1,
# 2]
#def f(x, y):
# pprint(x,
# y) Results in: from pprint import pprint
x = [1,
2]
y=[1,
2]
def f(x, y):
pprint(x,
y) Which breaks the indentation but should be expected and is the default behavior in other editors (tested with VSCode and Atom). Hope that makes sense! |
Thanks for the explanation @remisalmon 👍 What do you think @ccordoba12, @spyder-ide/core-developers ? |
I think it makes sense that commenting / uncommenting should not change the file. I think the change as described here looks reasonable. |
While I agree that it is very unfortunate that the change in code formatting, as describes #14326, occurs, it seems unfortunate to throw out all the compatibility with manual and Spyder 3 comments that we currently have. This change goes from breaking formatting, to breaking code (indents). The code above may now get a difficult to find indentation error with the def block now at three spaces, It seems that Spyder is alone in caring about this however as VSCode, Atom and even Pycharm and Jupyter-lab prefer this simpler approach. It's does have an advantage from a maintainability perspective but we are losing some user friendliness by making code errors. |
Well now if I uncomment this code:
The
vs
The number of spaces before the |
I believe currently the code will remove one space only if the number of spaces between the
Yes that would be the goal, but how can we tell if it would break the indentation?
I like this. If a block is continuing to multiple lines remove the same number of spaces from all the line of the block as the block starting line. The code would also have to detect function call and definition headings continuations. Currently this is a problem as well: # def ab(a=1,
# b=2):
# return |
Alternatively, we keep the current behaviour, unless multiple lines are deindented, one of them has only a single space after the |
I looks like it has a bracket matching element in there with |
5fde9ae
to
0ff61ce
Compare
I rebased this on 5.x, this is still breaking compatibility with Spyder 3 which is still better than breaking formatting after uncommenting commented code, in my opinion. |
Hi @remisalmon thank you for checking this again! I think due to this breaking compatibility with Spyder 3 (and also since we are not planning to do further Spyder 5 release for the moment) it needs to be rebased on top of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @remisalmon, thanks for your work and sorry for not reviewing it before.
I like that your changes made our code much simpler but I'm concerned about the changes you did to our tests (see below).
@@ -62,30 +62,30 @@ def test_single_line_comment(codeeditor): | |||
# Toggle comment with space at the right of prefix but manually inserted | |||
text = toggle_comment(editor, start_line=2) | |||
assert text == ("class a():\n" | |||
" self.b = 1\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this space not present now? I think your changes shouldn't alter this, so I don't understand this change.
The same goes for all modifications you did for all other tests here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text line 35 is defined with Spyder 3 style comments (leading #
with no space) but the tests are expecting Spyder 4/5/6 style comments (#
with a space).
This PR breaks compatibility with Spyder 3 style comments which I have argued elsewhere in the comments is prefered (in my opinion) to breaking the formatting after commenting/uncommenting. In this case we could rewrite the tests to use Spyder 4/5/6 style comments.
To move your work to the master branch, please run the following commands:
|
0ff61ce
to
4ae32bf
Compare
Thanks @ccordoba12 for taking a look, I rebased on the master branch and replied to your comment. (I also tried to look at the |
Thanks @remisalmon! I tested your changes locally and they are working as expected, so thanks a lot for your work and your patience with us. I think the new way of toggling comments feels natural and intuitive, so I really like it. I only have one question about a sentence in your OP:
Could you post an example about this new behavior to understand better what you mean? |
🎉
Take this code and uncomment the commented lines (first two use the old Spyder 3 comment style, last two use the new Spyder 4/5/6 comment syle): if True:
# pass
#pass
# pass
# pass Spyder currently: |
Ok, thanks for the clarification. Since this makes Spyder behave as other IDEs in that particular case, I agree with you that it's the right thing to do. |
Missed this one, lol! Yeah, that code is not easy to follow but we'd really appreciate your help to improve it later if you have the energy for it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @remisalmon!
Description of Changes
This PR changes the way spyder uncomments code and fixes an issue where toggling comments on and off over lines with an uneven number of leading whitespaces would add an extra whitespace (regardless of indentation level).
Example:
Commenting (Ctrl+1) then uncommenting (Ctrl+1), before:
Commenting (Ctrl+1) then uncommenting (Ctrl+1), after:
This PR breaks compatibility with spyder 3: commenting with spyder 3 and uncommenting with spyder 4 with break indentation but that should not be happening much.
This PR also break toggling comments on manually commented lines (prefixing
'#'
instead of'# '
) but that should be expected and other IDE behave the same (at least VSCode and Atom do).Issue(s) Resolved
Fixes #14326
Affirmation
By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.
I certify the above statement is true and correct: remisalmon