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

Format Selection is formatting the entire file #101

Closed
lsouder-ozone3d opened this issue Dec 13, 2023 · 5 comments
Closed

Format Selection is formatting the entire file #101

lsouder-ozone3d opened this issue Dec 13, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@lsouder-ozone3d
Copy link

I am having an issue where doing Format Selection is making changes outside the selected range. To clarify, doing Format Document does yield different results (more changes), so they are at least different.

I am using:

  • yapf 0.40.2
  • yapf VSCode extension version v2023.11.122090301
  • Python 3.9.13

My .vscode/settings.json is

{
    "python.languageServer": "Pylance",
    "python.analysis.diagnosticSeverityOverrides": {

    },
    "python.analysis.inlayHints.variableTypes": "off",
    "python.analysis.inlayHints.functionReturnTypes": true,
    "python.analysis.inlayHints.callArgumentNames": "off",
    "[python]": {
        "editor.defaultFormatter": "eeyore.yapf"
    },
}
@EeyoreLee
Copy link
Owner

@lsouder-ozone3d - hi, has the formatOnSave affected you? Could you try the following setting for [python] section

  "[python]": {
    "editor.formatOnSave": false,
    "editor.defaultFormatter": "eeyore.yapf",
    "editor.formatOnType": false
  }

If there's still a unexpect problem, please show me a code snippet can reproduct this as I just try this on my side that seems working fine.

@EeyoreLee EeyoreLee added the bug Something isn't working label Dec 14, 2023
@lsouder-ozone3d
Copy link
Author

@EeyoreLee thanks for responding. That config didn't solve the problem.

def do_something():
    xs = []
    for x in xs:
        y = 'y'
        
        if y:
            pass

def do_something_else():
    return '-path 1'

Line 5 has 2 unnecessary tabs. If I Format Selection for just the last line, it will strip the whitespace in Line 5

@EeyoreLee
Copy link
Owner

@lsouder-ozone3d - yup, I reproducted it not only through vscode extension but also yapf xx.py -l 10-10 -i. So it's a bug of yapf package. I'll issue it to yapf repo.

@EeyoreLee
Copy link
Owner

Seems there's a PR to fix it, upgrade your local yapf package when yapf merge it may fix it. Related PR yapf #1102

@lsouder-ozone3d
Copy link
Author

@EeyoreLee Thanks for looking into that! I'll close out this issue and watch for a change over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants