Skip to content

Code completion in the Editor doesn't work properly, unlike in the IPython console #2162

Open

Description

@spyder-bot

From [email protected] on 2015-02-06T08:44:55Z

Spyder Version: 2.4.0dev
Python Version: 3.4.1
Qt Version : 4.8.6, PyQt4 (API v2) 4.10.4 on Windows
pyflakes >=0.6.0: 0.7.3 (OK)
pep8 >=0.6 : 1.4.6 (OK)
IPython >=1.0 : 2.3.1 (OK)
zmq >=2.1.11 : 14.4.1 (OK)
pygments >=1.6 : 2.0.1 (OK)
pandas >=0.13.1 : 0.14.1 (OK)
sphinx >=0.6.6 : 1.2.3 (OK)
jedi >=0.8.1 : 0.8.1-final0 (OK)
rope >=0.9.2 : 0.9.4-1 (OK)
matplotlib >=1.0: 1.4.0 (OK)
sympy >=0.7.0 : 0.7.5 (OK)
pylint >=0.25 : 1.4.1 (OK)

What steps will reproduce the problem?

  1. Import module
  2. Create a local variable using class from the module
  3. Write the name of the variable, put the dot and call the autocompletion (TAB or CTRL+SPACE)

What is the expected output? What do you see instead?

In the editor:
I expected popup box with available methods and members, but it don't appear.
In the console:
All is OK.

Please provide any additional information below

I tried numpy and cv2:

import numpy as np # 'imp' completion works, 'num' completion works
arr = np.array([1,2,3,4,5]) # 'np.' completion works
arr. # completion don't work 

import cv2
cap = cv2.VideoCapture(0) # 'cv2.' completion works
cap. # completion don't work 

Same code in console work fine. I use Anaconda and last spyder version from bitbucket and run it like follow:
"python bootstrap.py --debug"
When I call completion for variable arr. or cap. I got next debug output:
completions request:
[]
completions request from jedi complete: "[]" in 0.1 sec
completions request from rope complete: "[]" in 0.2 sec
got timeout

Original issue: http://code.google.com/p/spyderlib/issues/detail?id=2162

Activity

  1. added this to the milestone on Feb 17, 2015
  2. spyder-bot commented on Feb 17, 2015

    @spyder-bot
    CollaboratorAuthor

    From ccordoba12 on 2015-02-08T09:36:09Z

    Steven, do you think we can do something about this? I see two options here:

    1. See if Jedi supports something like type hinting that can help us in this case.
    2. I did a bit of research on the Canopy's architecture and noticed its Editor seems to do code completions using an IPython kernel in the background. Of course, the problem in this case is that code in the Editor can be syntactically incorrect, but given we can verify that by using pyflakes, it could be worth investigating this option.

    Status: Accepted
    Cc: [email protected]
    Labels: Cat-Editor MS-v2.4

  3. spyder-bot commented on Feb 17, 2015

    @spyder-bot
    CollaboratorAuthor

    From ccordoba12 on 2015-02-08T09:43:05Z

    issue #1816 has been merged into this issue.

  4. spyder-bot commented on Feb 17, 2015

    @spyder-bot
    CollaboratorAuthor

    From [email protected] on 2015-02-08T10:20:18Z

    This is a really tough one, because it is a compiled module, the best I can suggest is to try docstring typehinting: http://jedi.jedidjah.ch/en/latest/docs/features.html#type-hinting .

  5. spyder-bot commented on Feb 17, 2015

    @spyder-bot
    CollaboratorAuthor

    From ccordoba12 on 2015-02-08T11:14:02Z

    I see, but that wouldn't help for the code reported by the OP, would it?

    And what do you think about option 2? Is it feasible?

  6. spyder-bot commented on Feb 17, 2015

    @spyder-bot
    CollaboratorAuthor

    From [email protected] on 2015-02-08T11:19:39Z

    Ah, I missed the numpy.array part. There is an open issue for that: davidhalter/jedi#372 .

    As far as IPython goes, I don't think it makes sense, because you don't want your code executing behind your back. What if it is creating/deleting files or doing long-running operations?

  7. spyder-bot commented on Feb 17, 2015

    @spyder-bot
    CollaboratorAuthor

    From ccordoba12 on 2015-02-08T11:52:28Z

    Oh yeah! I missed that one, a crucial point.

    Another idea then: does Jedi support a hooks concept for completions? I mean, if jedi knows an object's type (for example, that arr's is a numpy.array), we could add a hook to show completions for it, either by passing the completion widget a list (saved somewhere in our source code) of np.array's completions, or by evaluating this simple statement in an IPython kernel

     import numpy as np
     arr = np.array
    

    then getting the list of completions the kernel returns for foo, and passing it to our widget.

    Of course, the crucial point here is that Jedi could give us the type of an introspected object.

  8. spyder-bot commented on Feb 17, 2015

    @spyder-bot
    CollaboratorAuthor

    From ccordoba12 on 2015-02-08T12:12:12Z

    Well, according to this SO answer http://stackoverflow.com/a/14710037/438386 Jedi does give completions for np.arrays, but it seems to have problems in virtualenvs. Steven, can you test it in your side?

  9. spyder-bot commented on Feb 17, 2015

    @spyder-bot
    CollaboratorAuthor

    From [email protected] on 2015-02-08T18:47:38Z

    I tried the following from IPython (Anaconda Python 3.4) and got an empty list:

    import jedi; jedi.Script('import numpy; a = numpy.array().m').completions()

  10. spyder-bot commented on Feb 17, 2015

    @spyder-bot
    CollaboratorAuthor

    From [email protected] on 2015-02-09T08:10:11Z

    Carlos, we could back-track to the object definition, then load that in IPython, but there is a snag: np.array is a function, not a class. It also requires an object as its first parameter. We could special case for np.array since it it used so often...

    d = jedi.Script('import numpy; a = numpy.array').definition()[0]
    if d.name == 'array' and d.module_name == 'numpy.core.multiarray':
       completions = [c for c in dir(np.array(1)) if c.startswith(completion_text)]
    elif d.type == 'class':
       mod = __import__(d.module_name)
       cls = getattr(mod, d.name)
       completions = [c for c in dir(cls) if c.startswith(completion_text)]
    
  11. spyder-bot commented on Feb 17, 2015

    @spyder-bot
    CollaboratorAuthor

    From ccordoba12 on 2015-02-12T08:43:41Z

    Yes, I was thinking exactly that. Could we make this mechanism extendable? I mean, we don't just need np.array, but also pyplot.figure, pd.groupby, and who knows how many others :-)

  12. 56 remaining items

  13. modified the milestones: v4.0beta2, on Mar 12, 2018
  14. changed the title [-]Code completion in editor don't work properly, unlike the Python/IPython console[/-] [+]Code completion in the Editor doesn't work properly, unlike in the IPython console[/+] on Mar 12, 2018
  15. modified the milestones: , Not sorted on Oct 11, 2018
  16. ccordoba12 commented on Nov 27, 2019

    @ccordoba12
    Member

    This can't be closed yet because we could implement a new completion client that uses an IPython kernel behind the scenes.

  17. modified the milestones: not sorted, on Nov 29, 2019
  18. removed this from the milestone on Feb 23, 2020
  19. kaleb-keny commented on May 23, 2020

    @kaleb-keny

    Hello I wanted to raise an issue on this, but I see it was raised and closed... It's the same issue that the editor doesn't provide any code completion unlike the IPython on the right...
    I uninstalled kite, because it was bugging me with notifications... Was this closed because of kite?

  20. ccordoba12 commented on May 23, 2020

    @ccordoba12
    Member

    Please see my comment immediately above yours.

  21. mauricio-fernandez-l commented on Sep 15, 2020

    @mauricio-fernandez-l

    Please forgive me, if I am in the wrong issue or if my question is trivially solved. I do not understand how I can activate default autocompletion of local project modules. Autocompletion works fine in the console, once a module is imported, but not in the editor. I found a workaround by using

    import sys
    sys.path.append('.')
    

    Do I always need to append the local project folder with sys.path.append('.') in order to allow in the editor for autocompletion of local project folders and modules or can I do this in a better manner? Its surely not a biggie, but I wanted to know if there is a better built-in way.
    Some of my system details:

    • Windows 10
    • Spyder 4.1.5 (installed through miniconda)
    • Python 3.7.9
    • IPython 7.18.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions