PY-18029 do_get_completions() method added to BaseInterpreterInterface

This commit is contained in:
Alexander Koshevoy
2018-05-30 23:44:19 +03:00
parent 5cf8ece2cb
commit 9b99c525da
3 changed files with 49 additions and 8 deletions

View File

@@ -2,12 +2,14 @@ import os
import sys
import traceback
from _pydev_bundle import _pydev_imports_tipper
from _pydev_bundle._pydev_calltip_util import get_description
from _pydev_bundle.pydev_imports import _queue, Exec
from _pydev_imps._pydev_saved_modules import thread
from _pydevd_bundle import pydevd_thrift
from _pydevd_bundle import pydevd_vars
from _pydevd_bundle.pydevd_constants import IS_JYTHON, dict_iter_items, NEXT_VALUE_SEPARATOR
from pydev_console.thrift_communication import console_thrift
try:
import cStringIO as StringIO #may not always be available @UnusedImport
@@ -17,6 +19,23 @@ except:
except:
import io as StringIO
# translation to Thrift `CompletionOptionType` enumeration
COMPLETION_OPTION_TYPES = {
_pydev_imports_tipper.TYPE_IMPORT: console_thrift.CompletionOptionType.IMPORT,
_pydev_imports_tipper.TYPE_CLASS: console_thrift.CompletionOptionType.CLASS,
_pydev_imports_tipper.TYPE_FUNCTION: console_thrift.CompletionOptionType.FUNCTION,
_pydev_imports_tipper.TYPE_ATTR: console_thrift.CompletionOptionType.ATTR,
_pydev_imports_tipper.TYPE_BUILTIN: console_thrift.CompletionOptionType.BUILTIN,
_pydev_imports_tipper.TYPE_PARAM: console_thrift.CompletionOptionType.PARAM,
}
def _to_completion_option(word):
name, documentation, args, ret_type = word
completion_option_type = COMPLETION_OPTION_TYPES[ret_type]
return console_thrift.CompletionOption(name, documentation, args.split(), completion_option_type)
# =======================================================================================================================
# Null
# =======================================================================================================================
@@ -519,7 +538,25 @@ class BaseInterpreterInterface:
# return xml.getvalue()
return pydevd_thrift.var_to_struct(result, expression)
def getCompletions(self, text, act_tok):
def do_get_completions(self, text, act_tok):
"""Retrieves completion options.
Returns the array with completion options tuples.
:param text: the full text of the expression to complete
:param act_tok: resolved part of the expression
:return: the array of tuples `(name, documentation, args, ret_type)`
:Example:
Let us execute ``import time`` line in the Python console. Then try
to complete ``time.sle`` expression. At this point the method would
receive ``time.sle`` as ``text`` parameter and ``time.`` as
``act_tok`` parameter. The result would contain the array with the
following tuple among others: ``[..., ('sleep',
'sleep(seconds)\\n\\nDelay execution ...', '(seconds)', '2'),
...]``.
"""
try:
from _pydev_bundle._pydev_completer import Completer
@@ -531,6 +568,10 @@ class BaseInterpreterInterface:
traceback.print_exc()
return []
def getCompletions(self, text, act_tok):
words = self.do_get_completions(text, act_tok)
return [_to_completion_option(word) for word in words]
def loadFullValue(self, seq, scope_attrs):
"""
Evaluate full value for async Console variables in a separate thread and send results to IDE side