Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

VS Code integration doesn't work when using -L/--lint #252

Closed
mayk0gan opened this issue Jan 13, 2022 · 7 comments
Closed

VS Code integration doesn't work when using -L/--lint #252

mayk0gan opened this issue Jan 13, 2022 · 7 comments
Labels
invalid This doesn't seem right

Comments

@mayk0gan
Copy link
Collaborator

mayk0gan commented Jan 13, 2022

Hi,

I'm trying to follow the instuctions in the readme file, but it doesn't seem to work.
My settings.json:

{
    "workbench.colorTheme": "Default Dark+",
    "files.trimTrailingWhitespace": true,
    "window.zoomLevel": 2,
    "editor.formatOnSave": true,
    "python.formatting.provider": "black",
    "python.formatting.blackPath": "/bin/darker",
    "python.formatting.blackArgs": [
        "--diff"
    ]
}

I've started with more complex configuration which didn't work too:

    "python.formatting.blackArgs": [
        "--rev",
        "dev",
        "--line-length=120",
        "--diff",
        "-L",
        "mypy",
        "-L",
        "flake8"
    ]
@mayk0gan
Copy link
Collaborator Author

from vscode's OUTPUT (python category):

formatting with black failed.
Error: Invalid patch mode '/' in: <PATH_TO_FILE>:35:1: E302 expected 2 blank lines, found 1

Where PATH_TO_FILE appears without '/' in in the beginning of the string.
Running the same command from the CLI (and from the same cwd) results more output

@mayk0gan
Copy link
Collaborator Author

Another update, it seems to be the -L flag to cause the mess (I tired with flake8 and mypy), without this flag it seems to work well..
Any ideas why?

@mayk0gan
Copy link
Collaborator Author

mayk0gan commented Jan 14, 2022

finally! you should add quotes around the linting tool/ its path.
For example:

"python.formatting.blackArgs": [ "--rev", "develop", "-l", "120", "-L", "'flake8'" ]

But it seems that there isn't any integration between the chosen linting tool (flake8/ mypy) when running using darker, although they work great (and show suggestions under the PROBLEMS window) when run alone.

@akaihola
Copy link
Owner

Thanks a lot for your investigation @mayk0gan!

VSCode copies your .py file into a temporary .tmp.py file, submits that to Black (or in this case, Darker), and wants it to print on standard output the difference between the original and reformatted file – hence the --diff argument.

The problem with integrating other linting tools to the process is that their output is mixed in with the --diff output. So adding some -L options causes Darker to start acting very differently from Black, and VSCode doesn't understand that.

Maybe this is something we need to mention in the documentation.

On Linux, my VSCode configuration is:

{
    // ...
    "python.formatting.blackArgs": [
        "--revision=master...",
        "--isort"
    ],
    "python.formatting.blackPath": "/home/akaihola/.virtualenvs/darker/bin/darker",
    "python.formatting.provider": "black",
    // ...
}

which seems to work all right.

@akaihola
Copy link
Owner

@mayk0gan since you're a VSCode and macos user, could you take a look at #67 as well to verify whether it's a valid issue report?

@mayk0gan
Copy link
Collaborator Author

I tried something similar to the configuration here (#67) and it works, I think that the main problem is with external linters (-L flag)

@akaihola
Copy link
Owner

akaihola commented Feb 2, 2022

Thanks @mayk0gan for that information! I'll close this issue and improve documentation in #254 instead.

@akaihola akaihola closed this as completed Feb 2, 2022
@akaihola akaihola changed the title VS Code integration doesn't work [OSX] VS Code integration doesn't work when using -L/--lint Mar 2, 2022
Repository owner locked and limited conversation to collaborators Mar 2, 2022
@akaihola akaihola converted this issue into discussion #322 Mar 2, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
invalid This doesn't seem right
Projects
Development

No branches or pull requests

2 participants