Closed frankli0324 closed 1 year ago
@frankli0324 This can happen if you have selected some text and running formatting. Please unselect, and run the command. Autopep8 extension doesn't yet support formatting on range.
This can happen if you have selected some text and running formatting.
The same happens without selecting any text
I'm surprised that this isn't found in testing stage, even a simple self-test would trigger this obvious bug if I remember correctly, the old python extension did support partial formatting, why is a extension "split" doesn't cover all previous features? also why is vscode pushing users to switch to unfinished extensions?
@frankli0324 I am not able to repro this locally. Can you provide your settings? This looks like an issue with VS Code itself and not this extension specifically. That command is contributed by VS Code and it picks up the formatter based on settings. So please share both your user and workspace settings.
if I remember correctly, the old python extension did support partial formatting
The old extension does not support partial formatting. What it did was format the entire file, even when partial formatting was requested.
why is a extension "split" doesn't cover all previous features? why is vscode pushing users to switch to unfinished extensions?
As I mentioned. The old formatter did not support it, it formatted the whole file. I agree that the missing selection formatting needs to be handled better.
my workspace settings used for the screenshot is generated by the ms-python extension
{
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.formatting.provider": "none"
}
while my python related user settings are
"[python]": {
"editor.defaultFormatter": "ms-python.python",
"editor.formatOnType": true,
},
"python.languageServer": "Pylance",
"python.defaultInterpreterPath": "/opt/homebrew/bin/python3",
"python.venvFolders": [
"envs",
".pyenv",
".direnv",
".env"
],
"pylint.args": [
"--disable=all",
"--disable=E1111",
"--enable=F,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode",
"--max-line-length=90"
],
"autopep8.args": [
"--ignore=E731",
"--max-line-length=95"
],
I seem to understood what's happening here... this extension declared hasDocumentSelectionFormattingProvider
but not implemented it yet right? so when I use cmd+k cmd+f
, which is bound to editor.action.formatSelection
triggered at editorHasDocumentSelectionFormattingProvider && editorTextFocus && !editorReadonly
(which is the default configuration), it actually tries to format with selection formatter
this image is to show that I didn't override the cmd+k cmd+f
settings
if I rebind cmd+k cmd+f
to editor.action.formatDocument
(and, of course, change the when
expression), it's working as expected (formatting the entire file).
When I format a file with Cmd K + Cmd F, the following message appears:
While using
Format With
command using Cmd+Shift+P, the file is successfully formatted.