Skip to content
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

Copying and pasting code from function body messes up with indentation #5885

Open
luabud opened this issue May 15, 2024 · 4 comments
Open

Copying and pasting code from function body messes up with indentation #5885

luabud opened this issue May 15, 2024 · 4 comments
Assignees
Labels
auto-indent Bugs in the auto indent feature needs repro Issue has not been reproduced yet

Comments

@luabud
Copy link
Member

luabud commented May 15, 2024

Environment data

  • Language Server version: 2024.5.100
  • OS and version: win32 x64
  • Python version (and distribution if applicable, e.g. Anaconda): Python3.12.0, .venv
  • python.analysis.indexing: true
  • python.analysis.typeCheckingMode: basic

Code Snippet

on file1.py:

def make_dot_string(x):
    """
    creates a string of spaces followed by a dot.
    @param x: the number of spaces before the dot.
    @return: a string with x spaces, then a dot.
    """
    rad = radians(x)
    c = abs(round(cos(rad), 2))
    if c == 0:
        return 0
    
    numspaces = int((9 * 1 / c - 9))
    return numspaces

On file2.py:

def home():
    
    numspaces_list = []
    for i in range(0, 1800, 3):
        numspaces_list.append(wave.make_dot_string(i))
    
    return numspaces_list

Repro Steps

  1. Copy code from the function body on file1.py for example
  2. Paste it right below def home(): on file2.py
  3. Notice how the indentation gets messed up

image

Logs

pylance051524.txt

Maybe it's something enabling format on paste would solve?

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label May 15, 2024
@luabud
Copy link
Member Author

luabud commented May 15, 2024

#4342

@debonte debonte added the auto-indent Bugs in the auto indent feature label May 15, 2024
@heejaechang
Copy link
Contributor

are you saying you copied things correctly but something interfered and messed up indentation? or you copied things incorrectly, so format was messed up? but you want us to fix that up?

@luabud
Copy link
Member Author

luabud commented May 28, 2024

the first one, things were copied correctly but when pasting it, the indentation was broken

@heejaechang
Copy link
Contributor

heejaechang commented May 28, 2024

so, you are saying the extra whitespace before """ below def home is added by something (pylance or something else) even if user didn't put that whitespace when they make the copy nor when they paste. something else automatically added that whitespace

asking since based on the answer, we need to look for different thing. if it is automatically added, we need to inspect things like auto formatter or other extensions who might have added that extra whitespace.

if user added that whitespace when copy or pasted the code after that whitespace accidently or not, then it is by design and we would need to look for enhancement. either we implement formatter ourselves, or talk with vscode whether they can add auto format on paste like they do auto format on save.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-indent Bugs in the auto indent feature needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

4 participants