microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.69k stars 768 forks source link

block comments not adapt with python. #5091

Open zzdywc opened 9 months ago

zzdywc commented 9 months ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. write down some python code.
  2. use block comments(alt+shfit+A) on some for or with block code or any indented code. and the ''' will on the top of line witch is not correct.

example figure. image

KacieKK commented 8 months ago

Hey @zzdywc , Could you please provide a more detailed example that covers the range of codes you want to comment out, your expected behavior, etc That will help me reproduce this issue, thanks!

zzdywc commented 8 months ago

code sample as shown:

x = []
for i in range(100):
    print(i)
    print(i/10)
    x.append(i)
    if(i == 10):
        print("yes")
print("end")

normal comments like:

x = []
for i in range(100):
    print(i)
    '''
    print(i/10)
    x.append(i)
    '''
    if(i == 10):
        print("yes")
print("end")

select code:

    print(i/10)
    x.append(i)

press shift+alt+A, and will add comment symbol like this:

x = []
for i in range(100):
    print(i)
"""     
    print(i/10)
    x.append(i)
     """
    if(i == 10):
        print("yes")
print("end")

This code make if work improperly.

It seems like comment will added one space before the starting position and The last space of the end position of which have been selected. though this logic work fine with orther language like c etc. but not work on language that relies on indentation. I don't know what logic is the best, but in my opinion, add new line at the bothstart position and end postion of which have been selected, and than add comment symbol ''' at the new line with properly indentation will fix this problem. image

KacieKK commented 1 month ago

Thanks for the issue, I can repro it