Skip to content
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

Auto-import? #34

Closed
kuator opened this issue May 21, 2021 · 20 comments · Fixed by #199
Closed

Auto-import? #34

kuator opened this issue May 21, 2021 · 20 comments · Fixed by #199
Milestone

Comments

@kuator
Copy link

kuator commented May 21, 2021

jedi doesn't support auto-import: pappasam/jedi-language-server#126 (comment)
can python-lsp support it through other means?

@andfoy
Copy link
Contributor

andfoy commented May 24, 2021

@kuator, an addition in Jedi would need to be required in order to do this, there was a plan to implement a race-based completion request between Jedi and Rope, which provides auto-import and better compiled extension analysis, however it needs to be migrated to the new server

@kuator
Copy link
Author

kuator commented May 25, 2021

Quoting the original Jedi author: "Jedi does not support autoimport nor will it in the near future" davidhalter/jedi-vim#736 (comment)

@ccordoba12
Copy link
Member

I think @andfoy meant that an addition to this server is needed to support getting responses from both Jedi and Rope at the same time.

@kuator
Copy link
Author

kuator commented May 25, 2021

I think @andfoy meant that an addition to this server is needed to support getting responses from both Jedi and Rope at the same time.

Oh, I see, I'm sorry for misunderstanding

@mlucool
Copy link

mlucool commented Jun 2, 2021

As another option, try out https://github.com/deshaw/jupyterlab-pyflyby for jupyterlab auto-import

@kuator
Copy link
Author

kuator commented Jun 2, 2021

@mlucool I mostly do backend, so I think it's a no-go for me, thanks for the reply though!

@Hubro
Copy link

Hubro commented Sep 7, 2021

The language server in Pyright does this, i.e. it shows auto-complete suggestions for all functions and classes from all resolved Python modules and submodules, and if you select one it adds the import automatically. Probably a good reference point if somebody decides to implement it here.

@ccordoba12
Copy link
Member

Pyright is done in Typescript, so it doesn't offer much help to us.

@Hubro
Copy link

Hubro commented Sep 8, 2021

Pyright is done in Typescript, so it doesn't offer much help to us.

Yes, but I only meant to suggest it as a reference to learn from. Surely it must help to examine a working implementation and not have to figure out everything from scratch.

@mlucool
Copy link

mlucool commented Sep 8, 2021

@kuator pyflyby is pure python: https://github.com/deshaw/pyflyby (blog)

@Hubro
Copy link

Hubro commented Sep 8, 2021

@kuator pyflyby is pure python: https://github.com/deshaw/pyflyby (blog)

Holy shit, that repo looks friggin awesome... If the performance is good it looks like the perfect basis for an auto import feature in a language server.

Actually I could probably add a save hook to automatically add missing imports. Then I'd only be missing the auto-complete suggestions.

@Yevgnen
Copy link

Yevgnen commented Dec 8, 2021

Any update on this? pyflyby looks so great.

@bagel897
Copy link
Contributor

https://github.com/bageljrkhanofemus/pylsp-autoimport
relatively simple solution, formats entire document. Could be moved to this repo due to simplicity. A better solution would be to integrate it with Jedi or Rope somehow so we can let the user pick a module rather than retroactively adding them.

@ccordoba12
Copy link
Member

Hey @bageljrkhanofemus, that's pretty cool! You could move it to this organization, so you can maintain it yourself (we wouldn't like to maintain more plugins here).

@bagel897
Copy link
Contributor

How would I do that?

@ccordoba12
Copy link
Member

I can send you an invite so you can you our organization.

@amerlyq
Copy link

amerlyq commented Apr 16, 2022

@bageljrkhanofemus I dunno how to use your plugin, as despite "autoimport" being installed (and works manually), and plugin is enabled in config -- no imports are suggested for missing "Path" or added automatically. Even outside virtualenv.

@ccordoba12 as a general question -- how to ensure the order in which "formatting" applies?
Most likely we need "autoimport" -> "isort" -> "black".

@ccordoba12
Copy link
Member

I think we're not ensuring any order right now.

@bagel897
Copy link
Contributor

bagel897 commented Apr 16, 2022

  1. The current one corrects missing imports
  2. I could add the tryfirst order suggestion, but
    a) black does the same setting and I'm pretty sure isort may do it too, so it wouldn't work.
    b) I don't really like how the current one works, so wouldn't reccomend using it yet
  3. I'm making a new on which suggests imports as completion suggestions
    Oh also you need to install the (old) plugin, which is a pypi package into wherever you have pylsp

@bagel897
Copy link
Contributor

bagel897 commented Apr 17, 2022

image
image
Is there going to be a way to combine autoimport suggestions with Jedi suggestions?
Do you know how I'd actually insert the insert statement when the suggestion is chosen?

Is there any advice for how to format the documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants