Skip to content

Commit

Permalink
Fix saving modified files with language setting
Browse files Browse the repository at this point in the history
  • Loading branch information
HelioGuilherme66 committed Dec 21, 2023
1 parent 8ae1481 commit 8747a6e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/robotide/controller/robotdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

def new_test_case_file(path):
datafile = robotapi.TestCaseFile(source=path)
datafile.start_table(['Test Cases'], lineno=1) # It is the unique section, so no problem
datafile.start_table(['Test Cases'], lineno=1, llang=['en']) # It is the unique section, so no problem
_create_missing_directories(datafile.directory)
return datafile

Expand Down
7 changes: 6 additions & 1 deletion src/robotide/editor/texteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,12 @@ def _show_keyword_details(self, value, coords=None):
class FromStringIOPopulator(robotapi.populators.FromFilePopulator):

def populate(self, content: [str, BytesIO], tab_size: int):
robotapi.RobotReader(spaces=tab_size).read(content, self)
try:
set_lang = shared_memory.ShareableList(name="language")
language = [set_lang[0]]
except AttributeError:
language = ['en']
robotapi.RobotReader(spaces=tab_size, lang=language).read(content, self)


class RobotStylizer(object):
Expand Down
13 changes: 6 additions & 7 deletions src/robotide/lib/robot/parsing/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,13 @@ def _get_tables(self):
for name in names:
yield name, table

def start_table(self, header_row, lineno: int):
"""
local_header = lang.get_headers_for(self.language, ('Comments',))
def start_table(self, header_row, lineno: int, llang: list):
self._language = llang
# local_header = lang.get_headers_for(llang, ('Comments',))
print(f"DEBUG: model _TestData start_table ENTER header_row[0]={ header_row[0]} lineno={lineno}\n"
f"language={self.language} local_header={local_header}")
"""
if header_row[0] in lang.get_headers_for(self.language, ('Comments',), lowercase=False):
self.comment_table = table = CommentsTable(self, self.language) # Multiple creation of table only if exists
f"language={llang}") # local_header={local_header}")
if header_row[0] in lang.get_headers_for(llang, ('Comments',), lowercase=False):
self.comment_table = table = CommentsTable(self, llang) # Multiple creation of table only if exists
self.tables.append(self.comment_table)
else:
table = self._find_table(header_row)
Expand Down
6 changes: 3 additions & 3 deletions src/robotide/lib/robot/parsing/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ def _get_reader(self, path, resource=False):
except KeyError:
raise DataError("Unsupported file format '%s'." % file_format)

def start_table(self, header, lineno: int):
def start_table(self, header, lineno: int, llang: list = None):
# DEBUG:
# print(f"DEBUG: RFLib populators FromFilePopulator ENTER start_table header={header}")
# if header[0].lower() in self._comment_table_names: # don't create a Comments section
# print(f"DEBUG: RFLib populators FromFilePopulator comments section header={header}")
# # return False
self._populator.populate()
table = self._datafile.start_table(DataRow(header).all, lineno=lineno)
table = self._datafile.start_table(DataRow(header).all, lineno=lineno, llang=llang)
# print(f"DEBUG: populators start_table header={header} got table={table} at lineno={lineno}")
if header[0] in language.get_headers_for(self._language, ('Comment', 'Comments'), lowercase=False):
if header[0] in language.get_headers_for(llang, ('Comment', 'Comments'), lowercase=False):
self._populator = self._populators['comments'](table)
else:
self._populator = self._populators[table.type](table) if table is not None else NullPopulator()
Expand Down
3 changes: 2 additions & 1 deletion src/robotide/lib/robot/parsing/robotreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def read(self, file, populator, path=None):
self.check_separator(line.rstrip())
cells = self.split_row(line.rstrip())
if cells and cells[0].strip().startswith('*') and \
populator.start_table([c.replace('*', '').strip() for c in cells], lineno=lineno):
populator.start_table([c.replace('*', '').strip() for c in cells], lineno=lineno,
llang=self.language):
process = table_start = True
preamble = False # DEBUG removed condition "and not comments" comments =
# print(f"DEBUG: RobotReader After table_start head={cells[0].replace('*', '').strip()}")
Expand Down
11 changes: 11 additions & 0 deletions utest/resources/robotdata/language/lang_pl.robot
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ Language: Polish

# A blank line

*** Variables ***
&{error} name=err

*** Comments ***
This is a comments block
Second line of comments
Maybe this block is still in preamble
One more line

*** Przypadki Testowe ***
First Test
No Operation
Expand All @@ -13,3 +22,5 @@ First Test
First Keyword
[Argumenty] ${arg}=None # This is a comment
Log To Console This is First Keyword
No Operation
Log To Console One more line
12 changes: 5 additions & 7 deletions utest/resources/robotdata/language/lang_pt.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ Language: Portuguese
# Mais uma linha em branco

*** Comentários ***
This is a comments block
Second line of comments
Maybe this block is still in preamble

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

This is a comments block
Second line of comments a
Maybe this block is still in preamble
One more line

*** Casos de Teste ***
teste primeiro
No Operation
Expand Down
3 changes: 3 additions & 0 deletions utest/resources/robotdata/language/lang_ru.robot
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ First Test
First Keyword
Log To Console Test execution with success

# comment here

*** Ключевые слова ***
First Keyword
Log To Console This is First Keyword
Log To Console Another line

0 comments on commit 8747a6e

Please sign in to comment.