Open namliz opened 5 years ago
"python.sortImports.path": "isort"
appears to work; which at least for me seems to be fine as I'm already used to my editor being run from inside a venv that's got isort, for it to work.
What's sort of annoying is that in order for it to pick up settings, I need to "python.sortImports.args": ["-sp", "/Users/user/.isort.cfg"],
, ~/.isort.cfg
does not work.
But even worse, isort
no config option (by default) uses isort's own config finding mechanism to find its config, which means the above wont work for projects that have their own isort config specified in the repo, for example. Ideally internally the plugin would just defer to isort for it's config location.
Well... isort doesn't work for me at all. I have to use vim-isort and run :Isort manually.
The relevant parts of my config look like:
{
"coc.preferences.rootPatterns": [".git", "pyproject.toml", "setup.py", ".env"],
"python.sortImports.path": "${workspaceFolder}/.venv/bin/isort",
"python.sortImports.args": ["-sp", "/Users/user/.isort.cfg"],
"coc.preferences.formatOnSaveFiletypes": ["python"],
}
the rootPatterns bit makes workspaceFolder
work; which allows me to target the right versions of my linters.
It just so happens that all the projects i work on have basically the same config, so I'm skating by with a global isort config (but as i said above, this is pretty poor. it should just let isort find the config).
And finally the formatOnSaveFiletypes makes it call isort on save. Those
I also got the ENOENT
error.
Instead of replacing ~
with the absolute path to $HOME
, using ${env.HOME}
works for me as well. Accessing the environment variable is more stable when you want to share the config file across platforms.
For me python.sortImports
command does not work correctly even if I specify the isort
path in coc-settings.json
. For example if I have a simple script test.py
with just bunch of import statements
import glob
import sys
import argparse
import collections
import dis
Running python.sortImports
produces this output which is expected
import argparse
import collections
import dis
import glob
import sys
However if I run the same command again, it produces the below output which is weird and removes some of the import statements and duplicates others.
import dis
import glob
import sys
import glob
import sys
coc-settings.json:
Vim command:
Replacing
~/.local/bin/isort
with/Users/Name/.local/bin/isort
works perfectly however. Black on the other hand works fine with the tilda expansion.