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

Automatically add parens for function completions #2371

Merged

Conversation

blink1073
Copy link
Contributor

Fixes #680. Automatically appends parens to completions that are known to be a function, method, or class, respecting the same rules as the standard auto parens in the code editor.

'method']:
return
edit = self.textedit
s_trailing_text = edit.get_text('cursor', 'eol').strip()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not rstrip instead of strip here?

@blink1073
Copy link
Contributor Author

Added the new method to handle close parens.

@blink1073
Copy link
Contributor Author

I'm not sure why the check for the other characters is there, but I'm sure someone had a valid reason. 😄

@blink1073
Copy link
Contributor Author

As a bonus, we get the calltip now!

@blink1073
Copy link
Contributor Author

Rebased after icon merge.

return
position = self.get_position('cursor')
rest = self.get_text('cursor', 'eol').rstrip()
if (len(rest) == 0 or rest[0] in (',', ')', ']', '}')):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not rest is more pythonic than len(rest) == 0.
Also the surrounding parenthesis are not necessary.

@Nodd
Copy link
Contributor

Nodd commented Jun 15, 2015

I added a few style comments.

These trailing whitespaces are really annoying...

Automatically add () for function completions

Rename variable for clarity

Create a new method to handle close parens

Revert trailing spaces

More fixes

Style fixes
@blink1073 blink1073 force-pushed the add-parens-to-function-completion branch from 69fdaec to 6ad745a Compare June 15, 2015 11:38
@blink1073
Copy link
Contributor Author

Fixed!

@ccordoba12
Copy link
Member

This is a really nice addition! And it's working as expected :-)

I just have one question: could we make this work when users press Tab and there is only one completion possible? I mean, for example, if you write:

numpy.vec<Tab>

you won't get parenthesis nicely inserted (which, by the way, also shows you the signature tooltip).

@ccordoba12
Copy link
Member

If that's not possible, we should seriously consider to tackle issue #1914 :-)

@blink1073
Copy link
Contributor Author

Works now!

@ccordoba12
Copy link
Member

I'm seeing this error in the internal console (with PyQt5 only) when pressing Tab in quick succession, and if there are no possible completions to get:

Traceback (most recent call last):
  File "/home/carlos/Projects/spyder/github-repo/spyderlib/utils/introspection/plugin_manager.py", line 56, in _handle_timeout
    debug_print('got timeout: %s' % self.plugins)
AttributeError: 'NoneType' object has no attribute 'plugins'

An example to generate this

numpy.vectorize<Tab><Tab><Tab>

After this message is shown, each time parens are introduced the same error appears again.

The error seems unrelated to this PR. So it's up to you @blink1073, if you want to fix it here or leave it for later :-)

@blink1073
Copy link
Contributor Author

I'd say leave that one for a different issue.

@ccordoba12
Copy link
Member

Ok, merging then ;-)

@ccordoba12 ccordoba12 changed the title Automatically add () for function completions Automatically add parens for function completions Jul 24, 2015
ccordoba12 added a commit that referenced this pull request Jul 24, 2015
…tion

Automatically add parens for function completions
@ccordoba12 ccordoba12 merged commit 4990dce into spyder-ide:master Jul 24, 2015
@blink1073 blink1073 deleted the add-parens-to-function-completion branch January 15, 2016 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code completion: insert automatically parentheses for functions/methods
3 participants