pappasam / coc-jedi

coc.nvim wrapper for https://github.com/pappasam/jedi-language-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expose jedi's extract_function and extract_variable

hanspinckaers opened this issue · comments

It would be really nice if this coc-plugin supported the more advanced refactoring tools in jedi:
https://jedi.readthedocs.io/en/latest/docs/api.html#jedi.Script.extract_function

I didn't even find a 'reference' implementation in jedi-vim, so I'm not sure how doable this is.

Thanks for your awesome work,

Hans

These would probably be handled as code actions. This would need to be implemented first in jedi-language-server, which would need to be responsible for most of the heavy lifting (per the lsp docs above).

I found another jedi language server that implements a code action, maybe we can use this as inspiration?

https://github.com/muffinmad/anakin-language-server/blob/4f3e01c0985111eca2dcf4df882661b80efac093/anakinls/server.py#L795

Happy to review pull requests at jedi-language-server in the meantime, and if you're not able to address, I'll implement this when I find time!

I would really like to do it, but I'm a bit short on time in the coming weeks. Maybe I will find an evening somewhere 🙂

Resolved in the latest version!

Be sure to use something like the mapping below to get CodeActions to work:

nmap     <silent>        <leader>ssa v<Plug>(coc-codeaction-selected)

Additionally, I believe I've discovered a bug in Jedi's extract variable. Pending discussion here: davidhalter/jedi#1611

Awesome! Sorry I did not have time for a PR.

However, after update the jedi-language-server and coc-jedi, I'm not seeing the code-actions with coc.nvim? I doublechecked my jls version. Any other ideas that I could try?

Use the keybinding above while your cursor is on bar:

foo = 3.1
bar = foo + 1
x = int(bar)

You should, at least, be presented with the inline code action, which will turn the code into:

foo = 3.1
x = int(foo + 1)

You won't see a code action in the menu unless one exists at your cursor location. For all other code actions supported by Jedi, please refer to jedi's docs

Hi there, I got it working with your suggestions. However, I think it would be more useful to also provide until_line to Jedi so that we can extract multiline functions. I tried to make a pull request but sadly failed (problems with the pre-commit hook and now it doesn't see the right commit history?).

I don't have time today anymore (maybe a few minutes tonight), but it's a simple change, maybe you want to take a look:

hanspinckaers@d9189f2
and
hanspinckaers@ac74493

Edit: Ha! i see what happened, i forked the wrong repository..