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
Exclude Regex is not working for formatOnSave #141
Comments
@kirankumarmanku This is a limitation of
For example black has this CLI argument:
|
Is it possible to work around the limitation of autopep8? Basically, since we are doing this only for single file, we can run the command with passing the file name and if we don't get any matching files or empty response from autopep8, then we ignore format on save and return. Otherwise, we can execute formatOnSave logic. |
Or, better yet, we can save the file and send the file name as an argument to autopep8? Autopep8 will take care of formatting the file and save it if the file has changes or ignore the file if it it matches exclude regex. |
@kirankumarmanku With VS Code save takes on several steps, when a user triggers save, there are the things that can happen based on code actions on save configuration. Following things are run one after the other, on the unsaved file buffer: Import organization (think isort), Quick fixes from linter (think pylint/flake8/ruff), Formatting or source changes (think autopep8/docformatter). Each tool is sent the content of the file, and we get a response back with updated content that is sent to the next tool. If we send the path to autopep8 and it forces a save to disk, then the content that editor and other tools are expecting vs the one that got saved will be inconsistent. We want to prevent doing multiple passes for a single save as this can severely affect performance on save. |
@karthiknadig , I see. Is it possible to defer running autopep8 until last? I mean, we can run all other tools, save the file and trigger autopep8 run as the last step. |
Unfortunately, no. If you need this for some scenario, you could disable format on save, and use task.json to set this up. |
@karthiknadig, I didn't understand how we can use task.json to disable format on save for specific files. Is there any example? |
@karthiknadig , |
I meant disable the setting manually and use task.json to run
we are open to review PRs solving this. |
@karthiknadig , |
@karthiknadig , |
@karthiknadig, when can I expect this update to go live in extension? |
If you want to test this immediately you can use the build here: https://github.com/microsoft/vscode-autopep8/suites/14963376853/artifacts/853474846 Insiders build will be available for this usually by next day morning Pacific time. The fix will get into stable after about a month in insiders. |
Hi,
It's very easy to repro this. Say, you have this setting in your for autopep8.args:
Ideally, this shouldn't let autopep8 format on save any Python files. However, when I save a Python file, it's not respecting this setting and ending up formatting the file.
This is the log trace:
I debugged this and found that we are not passing the path to autopep8 command at this line:
vscode-autopep8/bundled/tool/lsp_server.py
Line 97 in df3e688
use_stdin=True
.This is a bug and should be fixed since autopep8 supports excluding specific files and we should pass complete path while doing autoformat.
Is there any work around for this issue?
The text was updated successfully, but these errors were encountered: