Skip to content

Commit

Permalink
Merge pull request #2624 from HelioGuilherme66/misc_fixes
Browse files Browse the repository at this point in the history
Fixes colorization of continuation arguments ...
  • Loading branch information
HelioGuilherme66 authored Aug 24, 2023
2 parents ae49ecf + 75f362c commit 25681e6
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 117 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to http://semver.org/spec/v2.0.0.html[Semantic Versioni

=== Fixed

- Colorization of Grid Editor cells after the continuation marker ``...`` and correct parsing of those lines
- Colorization of Grid Editor cells when contents is list or dictionary variables
- Validation of Grid Editor arguments types in keywords definitions. Now accepts ``@{}`` named-only marker
- Position of cursor in Text Editor auto-suggestions when line contains multibyte characters
Expand Down
76 changes: 44 additions & 32 deletions src/robotide/application/CHANGELOG.html

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/robotide/application/releasenotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ def set_content(self, html_win, content):
</ul>
<p><strong>New Features and Fixes Highlights</strong></p>
<ul class="simple">
<li>Colorization of Grid Editor cells after the continuation marker <b>…</b> and correct parsing of those lines</li>
<li>Colorization of Grid Editor cells when contents is list or dictionary variables</li>
<li>Added indication of matching brackets, <b>()</b>, <b>"""'''{}'''f"""</b>, <b>[]</b>, in Text Editor</li>
<li>Fixed non syncronized expanding/collapse of Settings panel in Grid Editor, on Linux</li>
<li>Fixed not working the deletion of cells commented with <b># </b> in Grid Editor with <b>Ctrl-Shift-D</b></li>
Expand Down Expand Up @@ -230,6 +232,6 @@ def set_content(self, html_win, content):
<pre class="literal-block">
python -m robotide.postinstall -install
</pre>
<p>RIDE {VERSION} was released on 13/Aug/2023.</p>
<p>RIDE {VERSION} was released on 23/Aug/2023.</p>
</div>
"""
15 changes: 15 additions & 0 deletions src/robotide/controller/stepcontrollers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class StepController(_BaseController):
indent = None

def __init__(self, parent, step):
self.continuing_kw = None
self._init(parent, step)
self.step_controller_step.args = self._change_last_empty_to_empty_var(
self.step_controller_step.args, self.step_controller_step.comment)
Expand Down Expand Up @@ -137,6 +138,17 @@ def _get_cell_position(self, column):
args = info.arguments
else:
args = []
value_at_col = self.get_value(col)
if self.keyword == '...' and self._index() > 0: # Any block starting with ... is in error
if value_at_col == '...':
drow = 1
self.continuing_kw = self.parent.step(self._index()-drow).keyword
while self.continuing_kw == '...' and self._index()-drow > 0:
drow += 1
self.continuing_kw = self.parent.step(self._index() - drow).keyword
info = self.get_keyword_info(self.continuing_kw) # Getting info for the previous step kw
if info:
args = info.arguments
args_amount = len(args)
if column > keyword_col and self.get_value(keyword_col) == "FOR" and self.is_assigning(value_at_col):
return CellPosition(CellType.ASSIGN, None)
Expand Down Expand Up @@ -180,6 +192,8 @@ def _number_of_mandatory_arguments(self, args, args_amount):
def _last_argument_is_varargs(args):
return args[-1].startswith('*') or args[-1].startswith('&{')

"""
# DEBUG: This is not used anywhere
def _has_list_or_dict_var_value_before(self, arg_index):
if self.args:
for idx, value in enumerate(self.args):
Expand All @@ -192,6 +206,7 @@ def _has_list_or_dict_var_value_before(self, arg_index):
not variablematcher.is_dict_var_access(value):
return True
return False
"""

def _get_content_with_type(self, col, position):
value = self.get_value(col)
Expand Down
48 changes: 27 additions & 21 deletions src/robotide/lib/robot/parsing/datarow.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ def _parse(self, row):
comments.append(cell)
else:
data.append(cell)
# if self._row_continuation_marker in data and self.source:
# self._deprecate_escaped_cells_before_continuation(data)
# return self._purge_empty_cells(data), comments # DEBUG don't self._purge_empty_cells(comments)
# print(f"DEBUG: datarow returning data={data} comments={comments}")
return data, comments # DEBUG keep empty cells

def _collapse_whitespace(self, cell):
@staticmethod
def _collapse_whitespace(cell):
if cell.startswith('#'):
return cell
return ' '.join(cell.split())
Expand All @@ -72,9 +69,6 @@ def _purge_empty_cells(self, row):

@property
def first_non_empty_cell(self):
# print(f"DEBUG: datarow enter _first_non_empty_cell")
# if self.cells:
# print(f"DEBUG: datarow _first_non_empty_cell: {self.cells[:]}")
index = 0
while index < len(self.cells) and self.cells[index] == '':
index += 1
Expand All @@ -83,8 +77,6 @@ def first_non_empty_cell(self):

@property
def head(self):
# print(f"DEBUG: datarow head={self.cells[:] if self.cells else 'NONE!!!'}")
# return self.cells[self.first_non_empty_cell] if self.cells else ''
return self.cells[0] if self.cells else ''

@property
Expand All @@ -111,22 +103,19 @@ def dedent(self):
datarow = DataRow([])
datarow.cells = self.tail
datarow.comments = self.comments
# stack = inspect.stack()
# the_class = stack[1][0].f_locals["self"].__class__.__name__
# the_method = stack[1][0].f_code.co_name
# print("DEBUG: datarow dedent called by {}.{}()".format(the_class, the_method))
# print(f"DEBUG: datarow dedent={datarow.all[:]}")
"""
stack = inspect.stack()
the_class = stack[1][0].f_locals["self"].__class__.__name__
the_method = stack[1][0].f_code.co_name
print("DEBUG: datarow dedent called by {}.{}()".format(the_class, the_method))
print(f"DEBUG: datarow dedent={datarow.all[:]}")
"""
return datarow

def starts_for_loop(self):
# head = self.head
head = self.cells[self.first_non_empty_cell]
if not self.head:
self.__setattr__(self.head, head)
# print(f"DEBUG: datarow starts_for_loop NEW CALCULATION head={head}")
# else:
# head = self.head
# print(f"DEBUG: datarow starts_for_loop head={head}")
if head.startswith(':'):
return head.replace(':', '').replace(' ', '').upper() == 'FOR'
return head == 'FOR'
Expand All @@ -141,9 +130,26 @@ def test_or_user_keyword_setting_name(self):

def is_indented(self):
return self.head == ''
# return self.first_non_empty_cell > 0

""" DEBUG
# In case we need this for the future
def add_indent(self, insert=None):
if insert:
self.cells.insert(0, insert)
self.cells.insert(0, '')
"""

@property
def starts_continuation(self):
index = self.first_non_empty_cell
if 0 <= index < len(self.cells):
return self.cells[index] == self._row_continuation_marker
else:
return False

def is_continuing(self):
if self.starts_continuation:
return False
for cell in self.cells:
if cell == self._row_continuation_marker:
return True
Expand Down
16 changes: 8 additions & 8 deletions src/robotide/lib/robot/parsing/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ class _WithSettings(object):
def get_setter(self, name):
if name[-1:] == ':':
name = name[:-1]
# Patching for ... setting, this way we don't get a Parser Error on log
if name == '...':
name = 'Documentation'
setter = self._get_setter(name)
if setter is not None:
return setter
Expand Down Expand Up @@ -657,9 +660,6 @@ def directory(self):
return self.parent.directory

def add_for_loop(self, declaration, comment=None):
# DEBUG
#self.steps.append(ForLoop(self, ['FOR'] + declaration, comment=comment))
# print(f"DEBUG: Model add_for_loop init={['FOR'] + declaration} comment:{comment}")
self.steps.append(Step(['FOR'] + declaration, comment))
# : Model add_for_loop return steps:{self.steps[-1].as_list()} comment:{comment}")
return self.steps[-1]
Expand Down Expand Up @@ -748,8 +748,7 @@ class ForLoop(_WithSteps):
:param list declaration: The literal cell values that declare the loop
(excluding ":FOR").
:param str comment: A comment, default None.
:ivar str flavor: The value of the 'IN' item, uppercased.
Typically 'IN', 'IN RANGE', 'IN ZIP', or 'IN ENUMERATE'.
:ivar str flavor: The value of the 'IN' item, uppercased, typically 'IN', 'IN RANGE', 'IN ZIP', or 'IN ENUMERATE'.
:ivar list vars: Variables set per-iteration by this loop.
:ivar list items: Loop values that come after the 'IN' item.
:ivar str comment: A comment, or None.
Expand All @@ -759,8 +758,10 @@ class ForLoop(_WithSteps):
normalized_flavors = NormalizedDict((f, f) for f in flavors)
inner_kw_pos = None

def __init__(self, parent, declaration, indentation=[], comment=None):
def __init__(self, parent, declaration, indentation=None, comment=None):
self.parent = parent
if indentation is None:
indentation = []
self.indent = indentation if isinstance(indentation, list) else [indentation]
isize = idx = 0
print(f"\nDEBUG: ForLoop init ENTER declaration={declaration[:]}")
Expand Down Expand Up @@ -810,6 +811,7 @@ def is_for_loop(self):
return True

def as_list(self, indent=True, include_comment=True):
_ = indent
comments = self.comment.as_list() if include_comment else []
# print(f"DEBUG: Model ForLoop as_list: indent={self.indent[:]} self.first_kw={self.first_kw}\n"
# f"{self.vars} + {self.flavor} + {self.items} + {comments}")
Expand Down Expand Up @@ -965,8 +967,6 @@ def as_list(self, indent=False, include_comment=True):
the_method = stack[1][0].f_code.co_name
print("DEBUG: RFLib Model Step called by {}.{}()".format(the_class, the_method))
"""
# print(f"DEBUG RFLib Model Step: as_list() ENTER assign={self.assign}\n"
# f"cells={self.cells[:]}")
_ = include_comment
if indent:
return [''] + self.cells[:]
Expand Down
11 changes: 9 additions & 2 deletions src/robotide/lib/robot/parsing/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,24 @@ def directory(self):

def populate(self, value, comment=None):
"""Mainly used at parsing time, later attributes can be set directly."""
if not self._populated:
try:
start_continuation = value[0].lstrip().startswith('\\n...') or value[0].lstrip().startswith('...')
except IndexError:
start_continuation = False
if not self._populated or start_continuation:
if start_continuation:
value[0] = value[0].replace('...', '\\n').replace('\\n\\n', '\\n')
self._populate(value)
self._set_comment(comment)
self._populated = True
else:
elif self._populated and not start_continuation:
self._set_initial_value()
self._set_comment(None)
self.report_invalid_syntax("Setting '%s' used multiple times."
% self.setting_name, 'ERROR')

def _populate(self, value):
# self.value.append(self._string_value(value))
self.value = value

def is_set(self):
Expand Down
Loading

0 comments on commit 25681e6

Please sign in to comment.