Hi, some times ago I wrote plugin for linting C/C++ code. But when I try to lint big projects my plugin blocks GUI of Sublime Text for few second, so I decided to run it in the background thread.
I try change code for threading like this:
class MainClanglinterCommand(sublime_plugin.TextCommand):
def run(self, edit):
clanglinter_thread = ClanglinterThread(self, edit)
clanglinter_thread.start()
class ClanglinterThread(threading.Thread):
def __init__(self, edit):
self.edit = edit
threading.Thread.__init__(self)
def run(self):
settings.update()
if settings.get('enable'):
context.update()
analyzed_file_content = utils.get_view_content(context.get('view'))
temp_file_object = utils.create_temp_file()
utils.write_temp_file(temp_file_object, analyzed_file_content)
cmd = utils.get_full_cmd(settings.get('clanglinter_cmd'),
temp_file_object.name,
settings.get('project_settings'))
clang_output = utils.clang_launch(cmd)
parser.update(clang_output)
parser_output = parser.get_format_output()
ui.regions_clear()
if parser_output:
ui.regions_create()
ui.output_panel_clear(self.edit)
ui.output_panel_insert_lines(self.edit, parser_output)
ui.output_panel_show()
else:
ui.output_panel_clear(self.edit)
ui.output_panel_hide()
But when I try to run this, I get error in the Sublime Text console:
Exception in thread Thread-3:
Traceback (most recent call last):
File "./threading.py", line 901, in _bootstrap_inner
File "C:\Program Files (x86)\sublimetext\sublimetext\Data\Packages\ClangLinter\ClangLinter.py", line 109, in run
ui.output_panel_clear(self.edit)
File "C:\Program Files (x86)\sublimetext\sublimetext\Data\Packages\ClangLinter\ClangLinter.py", line 414, in output_panel_clear
view.erase(edit, sublime.Region(0, view.size()))
File "C:\Program Files (x86)\sublimetext\sublimetext\sublime.py", line 701, in erase
raise ValueError("Edit objects may not be used after the TextCommand's run method has returned")
ValueError: Edit objects may not be used after the TextCommand's run method has returned
Question: how to implement this idea correctly? What I am doing wrong?