mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
PY-18029 do_get_completions() method added to BaseInterpreterInterface
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -55,7 +55,7 @@ class InterpreterInterface(BaseInterpreterInterface):
|
||||
self.notification_tries+=1
|
||||
if self.notification_tries>self.notification_max_tries:
|
||||
return
|
||||
completions = self.getCompletions("%", "%")
|
||||
completions = self.do_get_completions("%", "%")
|
||||
magic_commands = [x[0] for x in completions]
|
||||
|
||||
server = self.get_server()
|
||||
|
||||
@@ -74,13 +74,13 @@ class Test(unittest.TestCase):
|
||||
self.assertEqual([u'50', u'input_request'], found[1:]) # IPython 5.1
|
||||
self.assertTrue(found[0].startswith(u'Out'))
|
||||
|
||||
comps = interpreter.getCompletions('foo.', 'foo.')
|
||||
comps = interpreter.do_get_completions('foo.', 'foo.')
|
||||
self.assertTrue(
|
||||
('CONSTANT', '', '', '3') in comps or ('CONSTANT', '', '', '4') in comps, \
|
||||
'Found: %s' % comps
|
||||
)
|
||||
|
||||
comps = interpreter.getCompletions('"".', '"".')
|
||||
comps = interpreter.do_get_completions('"".', '"".')
|
||||
self.assertTrue(
|
||||
('__add__', 'x.__add__(y) <==> x+y', '', '3') in comps or
|
||||
('__add__', '', '', '4') in comps or
|
||||
@@ -90,21 +90,21 @@ class Test(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
completions = interpreter.getCompletions('', '')
|
||||
completions = interpreter.do_get_completions('', '')
|
||||
for c in completions:
|
||||
if c[0] == 'AssertionError':
|
||||
break
|
||||
else:
|
||||
self.fail('Could not find AssertionError')
|
||||
|
||||
completions = interpreter.getCompletions('Assert', 'Assert')
|
||||
completions = interpreter.do_get_completions('Assert', 'Assert')
|
||||
for c in completions:
|
||||
if c[0] == 'RuntimeError':
|
||||
self.fail('Did not expect to find RuntimeError there')
|
||||
|
||||
self.assertTrue(('__doc__', None, '', '3') not in interpreter.getCompletions('foo.CO', 'foo.'))
|
||||
self.assertTrue(('__doc__', None, '', '3') not in interpreter.do_get_completions('foo.CO', 'foo.'))
|
||||
|
||||
comps = interpreter.getCompletions('va', 'va')
|
||||
comps = interpreter.do_get_completions('va', 'va')
|
||||
self.assertTrue(('val', '', '', '3') in comps or ('val', '', '', '4') in comps)
|
||||
|
||||
interpreter.add_exec(CodeFragment('s = "mystring"'))
|
||||
|
||||
Reference in New Issue
Block a user