diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-11-06 11:53:07 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-11-06 11:53:07 +0300 |
commit | cc2476fde5f2ae4a3df625780b056580c7836712 (patch) | |
tree | dedb359a06852b2ef59cf0cbf1b20b4055bc49c2 /release/scripts/modules/console | |
parent | e1e6391a0bc23f4bfdb362b603ccc771c8c8708f (diff) |
patch from Stani, support for function arguments in autocomplete
Diffstat (limited to 'release/scripts/modules/console')
-rw-r--r-- | release/scripts/modules/console/intellisense.py | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/release/scripts/modules/console/intellisense.py b/release/scripts/modules/console/intellisense.py index eda34c9ff6b..686b3e7294b 100644 --- a/release/scripts/modules/console/intellisense.py +++ b/release/scripts/modules/console/intellisense.py @@ -16,10 +16,11 @@ """This module provides intellisense features such as: * autocompletion -* calltips (not yet implemented) +* calltips It unifies all completion plugins and only loads them on demand. """ + # TODO: file complete if startswith quotes import os import re @@ -63,6 +64,9 @@ def complete(line, cursor, namespace, private=True): :type private: bool :returns: list of completions, word :rtype: list, str + + >>> complete('re.sr', 5, {'re': re}) + (['re.sre_compile', 're.sre_parse'], 're.sr') """ re_unquoted_word = RE_UNQUOTED_WORD.search(line[:cursor]) if re_unquoted_word: @@ -99,14 +103,28 @@ def expand(line, cursor, namespace, private=True): current expanded line, updated cursor position and scrollback :rtype: str, int, str + + >>> expand('os.path.isdir(', 14, {'os': os})[-1] + 'isdir(s)\\nReturn true if the pathname refers to an existing directory.' + >>> expand('abs(', 4, {})[-1] + 'abs(number) -> number\\nReturn the absolute value of the argument.' """ - matches, word = complete(line, cursor, namespace, private) + if line[:cursor].strip().endswith('('): + import complete_calltip + matches, word, scrollback = complete_calltip.complete(line, + cursor, namespace) + no_calltip = False + else: + matches, word = complete(line, cursor, namespace, private) + if len(matches) == 1: + scrollback = '' + else: + scrollback = ' '.join([m.split('.')[-1] for m in matches]) + no_calltip = True prefix = os.path.commonprefix(matches)[len(word):] if prefix: line = line[:cursor] + prefix + line[cursor:] cursor += len(prefix) - if len(matches) == 1: - scrollback = '' - else: - scrollback = ' '.join([m.split('.')[-1] for m in matches]) + if no_calltip and prefix.endswith('('): + return expand(line, cursor, namespace, private) return line, cursor, scrollback |