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

VSCode integration no longer working #527

Open
kedhammar opened this issue Nov 28, 2023 · 2 comments
Open

VSCode integration no longer working #527

kedhammar opened this issue Nov 28, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@kedhammar
Copy link

Making a formal issue, referencing discussions #516 and #525.

Both threads now contains a workaround by @Ashblaze but it would be helpful if the issues are properly addressed by Darker.

@akaihola akaihola self-assigned this Feb 23, 2024
@akaihola akaihola added the enhancement New feature or request label Feb 23, 2024
@akaihola akaihola added this to the Darker 1.9.0 - Graylint milestone Feb 23, 2024
@akaihola
Copy link
Owner

Thanks @kedhammar for creating this issue. I think I'll use this one to collect links to related discussions and issues and to form a picture of current issues with VSCode.

On that note, it seems #523 is related.

@shane-kearns
Copy link

With "black-formatter.args": ["--stdout", "--isort"] or "black-formatter.args": ["-d"], it almost works.
However the file in vscode gains double line breaks when using SHIFT+ALT+F to format the file, and with format on save.
This is caused by https://github.com/akaihola/darkgraylib/blob/875dbaf613556f27a4e7949b45fcd798d4ab91f1/src/darkgraylib/utils.py#L17-L22 and commenting out that function to always return "\n" makes it work.

What seems to be happening is that you read a file with \r\n line ending and output a file with \r\r\n line endings.

Debug wrapper script:

import subprocess
import sys

print(sys.argv, file=sys.stderr)
cp = subprocess.run(["bin/darker.exe"] + sys.argv[1:], stdout=subprocess.PIPE)

print(cp.stdout[:400], file=sys.stderr)
sys.stdout.buffer.write(cp.stdout)
sys.exit(cp.returncode)

Sample file to format

import sys
import collections

settings.json

{
    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter",
        "editor.formatOnSave": true
    },
    "python.analysis.typeCheckingMode": "off",
    "black-formatter.path": ["py", "-3.11", "./scripts/darkerer.py"],
    "black-formatter.args": ["--stdout", "--isort"],
    "black-formatter.serverTransport": "stdio"
}

The black formatter console in vs code shows this:

2024-05-20 16:14:39.727 [info] ['./scripts/darkerer.py', '--stdout', '--isort', '--stdin-filename', 'c:\\XXX\\new-file.py', '-']
b'import collections\r\r\nimport sys\r\r\n'

2024-05-20 16:14:39.729 [info] [Trace - 4:14:39 PM] Received response 'textDocument/formatting - (7)' in 1037ms.

Running darker on the file normally (bin/darker --isort new-file.py) does not create bad line endings.
The problem can be reproduced without VSCode thusly, stdout gets double line endings:

cat new-file.py | bin/darker --stdout --isort --stdin-file new-file.py - | py -3.11 -c "import sys; print(sys.stdin.buffer.read())"
b'import collections\r\n\r\nimport sys\r\n\r\n'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

3 participants