-
Notifications
You must be signed in to change notification settings - Fork 672
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
An error message "Invalid path mode '\' in: No newline at end of file" pops up when for formatting document. #6752
Comments
I'm on VS 17.0 Preview 6.0. I installed all three formatters in my global python environment, and I can confirm that this issue repros as reported. Both I tried adding a newline to the end of the file, and both I've opened bugs in the repos for both of those formatters. |
This might be an issue with the way we call these formatters. Leaving this open until I know for sure after speaking with the owners of the tools. |
The reason why this happens is because we call the formatters with a switch to produce a .diff patch, which we then apply to the document (IIRC this is so that it can format without saving). Now if you run Black on a file like that, here's the output you get: >py -3.9 -m black --diff input.py
--- input.py 2021-10-18 08:22:14.637461 +0000
+++ input.py 2021-10-18 08:23:56.950593 +0000
@@ -1 +1 @@
-adasasd
\ No newline at end of file
+adasasd would reformat input.py
All done! ✨ � ✨
1 file would be reformatted. and our diff parser doesn't understand how to handle it. The reason why that's there is because of this: https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html#Incomplete-Lines and this: https://bugs.python.org/issue2142 So we just need to parse that as spec'd. |
Ah ok, so you're saying this IS ours to fix? Jake mentioned that the core extension just sends the contents with a newline appended on if there isn't one. I wanted to test it out in vscode and see what they do. I was thinking we have a couple options here:
@int19h You're saying the other option is for us to handle the "no newline at end of file" message more elegantly? |
I don't think we can do the second option. The whole reason why this line occurs in the diff is because Black etc are trying to add a newline there, because that's part of the style guidelines they enforce. So if we strip the newline at the end of the file, we're effectively reverting what Black did (and what the user expected to happen). What VSCode does sounds more reasonable to me, if they don't strip the newline out after. It does mean that formatters that don't add a newline at EOF will have one added for them, but I doubt anyone would complain about that (it doesn't break anything; not having a newline at the end can actually break some things on Unix). But, yes, we could also just handle |
I can repro in today's build |
same bug in latest (1.70.2) |
I've fixed this particular issue, but it looks like we have other issues with the formatting code. I'm investigating. |
Describe the bug
Steps to Reproduce
black
(default)Expected behavior
The package is successfully installed and the code is automatically formatted.
Additional context and screenshots
An error message pops up. This issue reproduced when set Tools/Options/Text Editor/Python/Formatting to
black
andautopep8
, do not reproduce when setyapf
.The text was updated successfully, but these errors were encountered: