Commit d1bfcf98 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Autocompletion for procedure call

parent 2dcc192c
......@@ -249,7 +249,7 @@ class EditableText(QGraphicsTextItem, object):
self.try_resize()
def context_completion_list(self):
def context_completion_list(self, force=False):
''' Advanced context-dependent autocompletion '''
# Select text from the begining of a line to the cursor position
# Then keep the last word including separators ('!' and '.')
......@@ -268,8 +268,7 @@ class EditableText(QGraphicsTextItem, object):
self.context = ''
except IndexError:
pass
if context != self.context:
#print 'refreshing list with', self.context.encode('utf-8')
if (context != self.context) or force:
self.completer.set_completer_list()
......@@ -294,13 +293,10 @@ class EditableText(QGraphicsTextItem, object):
text_cursor.select(QTextCursor.WordUnderCursor)
self.completion_prefix = text_cursor.selectedText()
self.context_completion_list()
self.context_completion_list(force=(event.key()==Qt.Key_F8))
completion_count = self.completer.set_completion_prefix(
self.completion_prefix)
if event.key() in (Qt.Key_Period, Qt.Key_Exclam):
# Enable autocompletion of complex types
pass # placeholder to update autocompletion list
if(completion_count > 0 and len(self.completion_prefix) > 1) or(
event.key() == Qt.Key_F8):
# Save the position of the cursor
......
......@@ -684,10 +684,34 @@ class ProcedureCall(VerticalSymbol):
@property
def completion_list(self):
''' Set auto-completion list '''
return chain((proc.inputString for proc in CONTEXT.procedures),
variables_autocompletion(self),
CONTEXT.timers, CONTEXT.global_timers,
('set_timer', 'reset_timer', 'write', 'writeln'))
if '(' in unicode(self):
# Get the variables of the type of the current parameter
count = unicode(self).count(',')
procname = unicode(self).split('(')[0].strip().lower()
for each in (proc for proc in CONTEXT.procedures
if proc.inputString.lower() == procname):
param_types = [p['type'] for p in each.fpar]
break
else:
# Procedure not defined, check special operators
if (procname == 'set_timer' and count == 1) or (
procname == 'reset_timer' and count == 0):
return chain(CONTEXT.timers, CONTEXT.global_timers)
elif procname in ('write', 'writeln'):
# Could filter for OCTET STRINGS/Strings/Integer/Booleans
return variables_autocompletion(self)
else:
return ()
if count + 1 > len(param_types):
# User tries to set more parameters than defined
return ()
else:
# Return variables of the type of the parameter
asn1_filter = param_types[slice(count, count + 1)]
return variables_autocompletion(self, asn1_filter)
else:
return chain((proc.inputString for proc in CONTEXT.procedures),
('set_timer', 'reset_timer', 'write', 'writeln'))
# pylint: disable=R0904
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment