Closed rbhanot4739 closed 3 years ago
Any update on this issue ?
Can anyone please update on the issue ?
Looks like @chemzqm is either quite busy I suppose or this issue is at least priority since its more than 2 weeks and I haven't had any comment from him.
Is there any update on this ? As of now I am using isort
in combination with ALE
which seems to work fine but love to have this working with coc
by default.
I've gotten used to always saving immediately after organising imports. It seems that if I run twice, without saving in between, this happens. Makes me wonder if it's some caching going on?
It seems that the import-sorting is not performed on the buffer but on the actual file - adding imports without saving and running python.sortImports
duplicates some imports in the current buffer.
If you remove enough imports so that the code is now where the imports have been, do not save, and run python.sortImports
,
then parts of the code will be interleaved by formatted imports.
Adding imports using another editor while having the same file open in a buffer in vim, and then (without reloading) running python.sortImports
copies parts of the newly added imports into the vim buffer, which confirms that the actual file is read, not the buffer and not some cache.
Would love to have this changed to organizing the current buffer, as opposed to reading the file from disc.
This function is worth looking at, it is the one which calls isort, and supplies the input-file. https://github.com/neoclide/coc-python/blob/62a54c0305fd7d93cb8d4bed47d8b8e7317b54e9/src/providers/importSortProvider.ts#L29
+1. I agree it seems to work fine if you always save before calling sortImports, but would be nice if it worked on the buffer instead of the file.
@vjsingh You can try checking out my PR/branch above in your local setup. Works on the buffer. Awaiting review. Using it myself.
@alexd2580 cool thanks!
I have a simple script
test.py
with just bunch of import statementsRunning
python.sortImports
produces this output which is expectedHowever 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.
This is how my
coc-settings.json
looks likeOutput from
cocInfo
Let me know if more information is needed from myside.