Skip to content

Commit

Permalink
Add validator from RF 6.1.1 to Text Edit. WIP fails to save language …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
HelioGuilherme66 committed Dec 20, 2023
1 parent f6797ad commit b9eb911
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
36 changes: 30 additions & 6 deletions src/robotide/editor/texteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ def set_editor(self, editor):

def validate_and_update(self, data, text):
m_text = text.decode("utf-8")
if not self._sanity_check(data, m_text):
handled = self._handle_sanity_check_failure()
result = self._sanity_check(data, m_text)
if isinstance(result, tuple) :
handled = self._handle_sanity_check_failure(result)
if not handled:
return False
self._editor.reset()
Expand All @@ -303,15 +304,38 @@ def validate_and_update(self, data, text):
return True

def _sanity_check(self, data, text):
"""
# First remove all lines starting with #
for line in text.split('\n'):
comment = line.strip().startswith('#')
if comment:
text = text.replace(line, '')
"""
from robotide.lib.compat.parsing import ErrorReporter
from robot.parsing.parser.parser import get_model
from robotide.lib.robot.errors import DataError

print(f"DEBUG: textedit.py _sanity_check data is type={type(data)}")
model = get_model(text)
print(f"DEBUG: textedit.py _sanity_check model is {model}")
validator = ErrorReporter()
result = None
try:
validator.visit(model)
except DataError as err:
result = (err.message, err.details)
model.save("/tmp/model_saved_from_RIDE.robot")
print(f"DEBUG: textedit.py _sanity_check after calling validator {validator}\n"
f"Save model in /tmp/model_saved_from_RIDE.robot"
f" result={result}")
return True if not result else result

""" DEBUG
formatted_text = data.format_text(text)
c = self._normalize(formatted_text)
e = self._normalize(text)
return len(c) == len(e)
"""

@staticmethod
def _normalize(text):
Expand All @@ -320,14 +344,14 @@ def _normalize(text):
text = text.replace(item, '')
return text

def _handle_sanity_check_failure(self):
def _handle_sanity_check_failure(self, message):
if self._last_answer == wx.ID_NO and time() - self._last_answer_time <= 0.2:
# self.source_editor._mark_file_dirty(True)
return False
# DEBUG: use widgets.Dialog
dlg = wx.MessageDialog(self._editor, 'ERROR: Data sanity check failed!\n'
'Reset changes?',
'Can not apply changes from Txt Editor', style=wx.YES | wx.NO)
dlg = wx.MessageDialog(self._editor, f"ERROR: Data sanity check failed!\nError at line {message[1]}:\n"
f"{message[0]}\n\nReset changes?",
"Can not apply changes from Text Editor", style=wx.YES | wx.NO)
dlg.InheritAttributes()
did = dlg.ShowModal()
self._last_answer = did
Expand Down
1 change: 1 addition & 0 deletions src/robotide/lib/compat/parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .validator import ErrorReporter
2 changes: 1 addition & 1 deletion src/robotide/lib/robot/parsing/tablepopulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _get_populator(self, row):
class CommentsTablePopulator(_TablePopulator):

def _get_populator(self, table):
# print(f"DEBUG: CommentsTablePopulator enter _get_populator {row=}")
print(f"DEBUG: CommentsTablePopulator enter _get_populator self._table={self._table} table={table}")
return CommentsPopulator(self._table.add)


Expand Down
7 changes: 5 additions & 2 deletions src/robotide/ui/mainframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,11 @@ def _show_format_dialog_for(file_controller_without_format):

def on_exit(self, event):
_ = event
self.sharemem.shm.close()
self.sharemem.shm.unlink()
try:
self.sharemem.shm.close()
self.sharemem.shm.unlink()
except FileNotFoundError:
pass
self.Close()

def on_manage_plugins(self, event):
Expand Down
2 changes: 1 addition & 1 deletion utest/resources/robotdata/language/lang_pt.robot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Second line of comments
Maybe this block is still in preamble

*** Definições ***
Library Process
Biblioteca Process

*** Casos de Teste ***
teste primeiro
Expand Down

0 comments on commit b9eb911

Please sign in to comment.