neoclide / coc-python

Python extension for coc.nvim, fork of vscode-python
574 stars 51 forks source link

black format failing silently #237

Open clay-coffman opened 4 years ago

clay-coffman commented 4 years ago

Sorry not sure what the best way to describe this is...

Result from CocInfo

versions

vim version: NVIM v0.4.3 node version: v11.12.0 coc.nvim version: 0.0.78-0c973a7a47 coc.nivm directory: /Users/claycoffman/.local/share/nvim/plugged/coc.nvim term: iTerm.app platform: darwin

Output channel: Python

Starting Jedi Python language engine. ##########Linting Output - pylint########## ##########Linting Output - pylint########## Module app 345,4,error,E0001:unexpected indent (, line 345) (syntax-error) ##########Linting Output - pylint########## Module app 345,4,error,E0001:unexpected indent (, line 345) (syntax-error)

Output channel: watchman

[Info - 10:09:00 PM] watchman watching project: /Users/claycoffman/Dev/personal/repos/fyyur [Info - 10:09:00 PM] subscribing "/Users/claycoffman/Dev/personal/repos/fyyur/.env" in /Users/claycoffman/Dev/personal/repos/fyyur [Info - 10:09:01 PM] subscribing "/python" in /Users/claycoffman/Dev/personal/repos/fyyur [Info - 10:09:01 PM] subscribing "//python" in /Users/claycoffman/Dev/personal/repos/fyyur [Info - 10:09:01 PM] subscribing "/python" in /Users/claycoffman/Dev/personal/repos/fyyur [Info - 10:09:01 PM] subscribing "//python" in /Users/claycoffman/Dev/personal/repos/fyyur [Info - 10:10:06 PM] watchman watching project: /Users/claycoffman/.dotfiles [Info - 10:10:06 PM] subscribing "*/.json" in /Users/claycoffman/.dotfiles [Info - 10:11:29 PM] file change detected: { "unilateral": true, "subscription": "f7a63610-b5d8-11ea-92d8-7300e71a8e88", "root": "/Users/claycoffman/.dotfiles", "files": [ { "name": "config/nvim/coc-settings.json", "size": 568, "exists": true, "type": "f", "mtime_ms": 1592975489421, "ctime_ms": 1592975489421 } ], "version": "4.9.0", "since": "c:1591204120:1121:4:956", "clock": "c:1591204120:1121:4:957", "is_fresh_instance": false } [Info - 10:11:45 PM] file change detected: { "unilateral": true, "subscription": "f7a63610-b5d8-11ea-92d8-7300e71a8e88", "root": "/Users/claycoffman/.dotfiles", "files": [ { "name": "config/nvim/coc-settings.json", "size": 568, "exists": true, "type": "f", "mtime_ms": 1592975504964, "ctime_ms": 1592975504964 } ], "version": "4.9.0", "since": "c:1591204120:1121:4:957", "clock": "c:1591204120:1121:4:958", "is_fresh_instance": false }

Describe the bug

When I save a file, I see the Formatted with black message (verified in :messages output) but the file is not actually formatted.

Reproduce the bug

Open any python file with nvim and save (should format)

Here is my coc-settings.json (there is no coc-settings.json in project root, FYI).

    "coc.preferences.formatOnSaveFiletypes": [
        "json",
        "css",
        "Markdown",
        "javascript",
        "html",
        "scss",
        "python"
    ],
    "python.sortImports.path": "/Users/claycoffman/.pyenv/versions/3.8.3/envs/neovim3/bin/isort",
    "python.formatting.provider": "black",
    "python.formatting.blackPath": "/Users/claycoffman/.pyenv/versions/3.8.3/envs/neovim3/bin/black",
    "python.linting.pylintEnabled": true,
    "python.linting.pylintPath": "/Users/claycoffman/.pyenv/versions/3.8.3/envs/neovim3/bin/pylint"
}

pythonPath is set (via python.setInterpreter command) to /Users/claycoffman/.pyenv/versions/neovim3/bin/python

I'm guessing this is something to do with how everything is configured from an env perspective? Sorry, very new to python dev...

zstreeter commented 3 years ago

I have the same behavior... I'm thinking it is a plugin collision.

vjsingh commented 3 years ago

I also have the exact same behavior, can't seem to figure it out.

vjsingh commented 3 years ago

This seems like potentially a duplicate of, or related to these issues:

https://github.com/neoclide/coc-python/issues/122 https://github.com/neoclide/coc-python/issues/63

vjsingh commented 3 years ago

@chemzqm I narrowed it down to three separate problems:

User Error In my settings I had "python.formatting.blackArgs": ["--line-length 79"]. Switching this to python.formatting.blackArgs: ["--line-length", "79"] stopped it from failing silently.

Failing Silently If there are errors, such as with the above incorrectly formatted args, there should be an error, but I don't see any in :CocInfo.

Format on save Formatting on save doesn't appear to be working. Black will format if I run :call CocAction('format'). If I enable format on save as below, upon saving it says Formatted with Black but the file doesn't change. EDIT - This one is kind of funny. It updates if you don't press any keys between saving and the file being formatted. If you navigated with jkl; it doesn't update. I don't think this is true for JS, or maybe it's just faster?


  "coc.preferences.formatOnSaveFiletypes": [
    ...
    "python"
  ],