def run(self, edit: sublime.Edit) -> None:
if self.data is not None:
self.replace(edit)
return
aggresive_level = get_settings(self.view, 'aggressive', 0)
if aggresive_level > 0:
if not sublime.ok_cancel_dialog(
'You have an aggressive level of {} this may cause '
'anaconda to change things that you don\'t really want to '
'change.\n\nAre you sure do you want to continue?'.format(
aggresive_level
)
):
return
self.code = self.view.substr(sublime.Region(0, self.view.size()))
settings = {
'aggressive': aggresive_level,
'list-fixes': get_settings(self.view, 'list-fixes', False),
'autoformat_ignore': get_settings(
self.view, 'autoformat_ignore', []
),
'autoformat_select': get_settings(
self.view, 'autoformat_select', []
),
'pep8_max_line_length': get_settings(
self.view, 'pep8_max_line_length', 79
)
}
try:
messages = {
'start': 'Autoformatting please wait... ',
'end': 'Autoformatting done!',
'fail': 'Autoformatting failed, buffer not changed.',
'timeout': 'Autoformatting failed, buffer not changed.',
}
self.pbar = ProgressBar(messages)
self.pbar.start()
self.view.set_read_only(True)
data = {
'vid': self.view.id(),
'code': self.code,
'method': 'pep8',
'settings': settings,
'handler': 'autoformat'
}
timeout = get_settings(self.view, 'auto_formatting_timeout', 1)
callback = Callback(timeout=timeout)
callback.on(success=self.get_data)
callback.on(error=self.on_failure)
callback.on(timeout=self.on_failure)
Worker().execute(callback, **data)
except:
logging.error(traceback.format_exc())
评论列表
文章目录