-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Format on save with black isn't working #229
Comments
It's expected, a temp file is created and formatted with black. coc-pyright will parse and apply the output to the origin file and delete the temp file. Looks like there is something block format-on-save. |
The file is updated when running |
All of the characteristics in the first comment are still present when running
|
@eulertour format on save does the same thing as |
I've found that the formatting consistently fails when editing the original file (which is around 1300 lines), but will consistently format when it's around 10 lines. There's also a length around 850 lines where saving will sometimes format and sometimes not. This leads me to believe there's some sort of race occurring, does that sound possible? |
I think I found the reason, here is the formatting steps:
The different between format-onsave and The time limit is needed because it's called on save. |
Would adding an option to disable the creation and deletion of the temp file and instead format the file directly help with the runtime? This issue never occurred using coc-python. |
@eulertour coc-python does the same: https://github.com/neoclide/coc-python/blob/master/src/formatters/baseFormatter.ts#L52 |
Would adding an option to disable it help with the runtime? Or is there anything else coc-pyright does differently that might contribute to a longer runtime? |
The formatting works properly same as coc-python, and I don't think it will make any improvement to disable the temp file. I'll dig and improve the formatting. |
I have same issue on raspberrypi. On save i get only message but call ... works fine (with any file length). |
I solved the issue of formatting on save by installing pip3 install --user pyls-black in my {
"python.formatting.provider": "black",
"languageserver": {
"python": {
"formatting": {
"provider": "black"
},
"black": {
"enabled": true
}
} don't know if the config helps, but with this config and |
On my machine, with minimal call plug#begin('~/.config/nvim/autoload/plugged')
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
call plug#end()
let g:coc_global_extensions = [ 'coc-pyright' ] and no
I also tried installing autopep8 with both |
in my |
@swizzard, autopep8 or black?
… On 4 Jan 2021, at 22:31, Sam Raker ***@***.***> wrote:
aug python
au!
au BufWrite *.py call CocAction('format')
aug END
in my .nvimrc file worked for me
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#229 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJNB5LBUI6K4TNKSARBBZ2TSYIXTBANCNFSM4VN6ASNQ>.
|
black
On Mon, Jan 4, 2021 at 3:32 PM Daniel Falbo <notifications@github.com>
wrote:
… autopep8 or black?
> On 4 Jan 2021, at 22:31, Sam Raker ***@***.***> wrote:
>
>
> aug python
> au!
> au BufWrite *.py call CocAction('format')
> aug END
> in my .nvimrc file worked for me
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub <
#229 (comment)>,
or unsubscribe <
https://github.com/notifications/unsubscribe-auth/AJNB5LBUI6K4TNKSARBBZ2TSYIXTBANCNFSM4VN6ASNQ
>.
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#229 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOSJHTF2JDA5337FXF3SELSYIXXRANCNFSM4VN6ASNQ>
.
--
.
|
I think I'll keep both |
While I haven't bothered to actually try it, I see no reason why the `aug`
solution wouldn't also work for `autopep8`--it basically circumvents the
`coc` timeout that seemed to be causing the issue. The one potential hassle
I could see being introduced would be the chance of creating tempfiles when
doing `:wqa` with multiple long files (which, again, isn't
`black`-vs-`autopep8` specific).
…On Mon, Jan 4, 2021 at 3:38 PM Daniel Falbo ***@***.***> wrote:
I think I'll keep both coc-pyright and coc-python until formatting with
autopep8 is fixed here: autopep8 with coc-python works as expected and
does not affect coc-pyright's other features like
CocActionAsync('highlight') that do not work with coc-python
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#229 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOSJHUPRW6335WCCTQ37A3SYIYLRANCNFSM4VN6ASNQ>
.
--
.
|
Tried the aug solution but didn't work :/ Anyway, this is the
seems like it doesn't find autopep8, but this time it is in my PATH so I don't know where could the bug be... |
I usually use It worked fine in my environment. Install Example: coc-settings.json {
// ...snip
"python.formatting.provider": "autopep8",
"python.formatting.autopep8Path": "~/.local/bin/autopep8",
// ...snip
} As a supplement, I also tried If there are any other problems with |
Setting |
In my environment, I tried To make it easier to share the situation, I verified it with this python file of about 700 lines from django. https://github.com/django/django/blob/master/django/http/request.py The same is true for black in "coc-python", so you may need to refer to the |
It's a "workaround". Adding {
// ...snip
"python.formatting.provider": "black",
"python.formatting.blackPath": "~/.local/bin/black",
"python.formatting.blackArgs": ["--diff", "--quiet", "--fast"],
// ...snip
} |
Oh..., I added |
I'm working on add |
I tried the I have confirmed that POST with |
There was a behavior in I don't know if this is a bug in e.g. pyproject.toml
|
Oh... It seemed to be a specification of blackd. https://github.com/psf/black#where-black-looks-for-the-file
|
|
I'm going to close this. |
I also have the problem. Note that My confinguration is: {
//...
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["--quiet" , "--experimental-string-processing"]
//...
} Whatever I do, the only way to autoformat is to use PS: blackd isn't the choice I want as it doesn't respect 88 chars for line length. |
blackd doesn't changes anything, the autoformat isn't made on save |
OK. actually there isn't any autoformat for python which works on save... |
@metal3d check Use something like this |
This is what I finally did @fannheyward - but unfortunately, I had got other problems to use coc-pyright that made me use coc-jedi instead :( |
The latest coc has added |
Manually triggering the save seems to have done the trick. Workaround sourced here: fannheyward/coc-pyright#229 (comment)
When saving a file,
[coc.nvim] Formatted with black
is printed, but the file isn't changed. Runningcall CocAction('format')
also prints the message, but the file is then updated. The output from:CocCommand workspace.showOutput
is as follows:It seems like a temp file may be being formatted instead of the actual file, but I don't know if this is expected.
The text was updated successfully, but these errors were encountered: