davidhalter / jedi

Awesome autocompletion, static analysis and refactoring library for python
http://jedi.readthedocs.io
Other
5.77k stars 508 forks source link

Can not auto complete for Flask-SQLAlchemy #1372

Closed archcst closed 5 years ago

archcst commented 5 years ago

Other packages can be auto complete(like render_templates): fdda30d00eb4f371a098c012209c81aa5deb5304

But SQLAlchemy can't(when I type id = db.Column): 799114b606e995561c1d003f5eb771aa2ce84e86

Here's my setup in ~/.spacemacs.d/init.el

(defun dotspacemacs/user-config ()
  ;; python configurations:
  (require 'pyvenv)
  (add-to-list 'company-backends 'company-anaconda)
  (add-to-list 'company-backends 'company-jedi)
  (add-to-list 'company-backends 'company-web)
  (add-hook 'python-mode-hook 'anaconda-mode)
  (add-hook 'python-mode-hook (lambda () (pyvenv-activate (concat (projectile-project-root) "/venv"))))
  (setq web-mode-engines-alist
        '(("django"    . "\\.html\\'")))
  (setq tab-width 4)
  (setq py-indent-offset 4)
  (setq python-spacemacs-indent-guess nil)
  (setq python-indent-guess-indent-offset nil)
  (setq org-confirm-babel-evaluate nil)
)

And here's the pipfile:

Package          Version
---------------- -------
alembic          1.0.11
argh             0.26.2
Click            7.0
Flask            1.1.0
Flask-CKEditor   0.4.3
Flask-Migrate    2.5.2
Flask-SQLAlchemy 2.4.0
Flask-WTF        0.14.2
itsdangerous     1.1.0
jedi             0.14.0
Jinja2           2.10.1
Mako             1.0.13
MarkupSafe       1.1.1
parso            0.5.0
pathtools        0.1.2
pip              19.1.1
python-dateutil  2.8.0
python-dotenv    0.10.3
python-editor    1.0.4
PyYAML           5.1.1
setuptools       39.0.1
six              1.12.0
SQLAlchemy       1.3.5
watchdog         0.9.0
Werkzeug         0.15.4
WTForms          2.2.1

Emacs version:

- OS: darwin
- Emacs: 26.1
- Spacemacs: 0.300.0
- Spacemacs branch: develop (rev. 5df46b200)
- Graphic display: t
- Distribution: spacemacs
- Editing style: vim
- Completion: helm

company-backends:

Value:
((company-anaconda . #1=(:with company-yasnippet))
 (company-semantic company-dabbrev-code company-gtags company-etags company-keywords . #1#)
 (company-files . #1#)
 (company-dabbrev . #1#))
Original value was 
(company-bbdb company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-dabbrev)
Local in buffer app.py; global value is 
(company-web company-jedi company-anaconda company-bbdb company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files
             (company-dabbrev-code company-gtags company-etags company-keywords)
             company-oddmuse company-dabbrev)
davidhalter commented 5 years ago

They are using a lot of dynamic code to make this happen: https://github.com/pallets/flask-sqlalchemy/blob/master/flask_sqlalchemy/__init__.py#L724

So this is pretty much something that won't be coming to Jedi anytime soon. So #626 might help you eventually, but this is not going to happen very soon. I'm also pretty sure that this is not going to be part of Jedi but part of an external project, if somebody ever writes one.

My suggestion for you is: Write stubs and use them. Jedi understands them and you are going to be fine. Everything else likely won't happen. You probably could also do a pull request on the flask-sqlalchemy project to add stubs.

auroraostrovica commented 9 months ago

In my experience, the most effective solution for flask sqlalchemy autocomplete is by installing flask-sqlalchemy-stubs package, a method I've found to be particularly insightful.