Skip to content

Commit f07c195

Browse files
azizkprincemaple
authored andcommitted
Commands: call mix format asynchronously.
The view locks up briefly otherwise.
1 parent fb20f3c commit f07c195

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

commands/mix_format.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def description(self):
1313
return 'Runs `mix format` on the project path or the opened folder.'
1414

1515
def run(self, **_kwargs):
16-
call_mix_format(self.window)
16+
call_mix_format_async(self.window)
1717

1818
class MixFormatFileCommand(sublime_plugin.TextCommand):
1919
def description(self):
@@ -23,7 +23,7 @@ def run(self, _edit, **kwargs):
2323
window = self.view.window()
2424
file_path = self.view.file_name()
2525
kwargs.get('save', True) and window.run_command('save')
26-
call_mix_format(window, file_path=file_path)
26+
call_mix_format_async(window, file_path=file_path)
2727

2828
def is_enabled(self):
2929
return is_formattable_syntax(self.view)
@@ -59,6 +59,11 @@ def load_mix_format_settings():
5959
package_settings = sublime.load_settings(SETTINGS_FILE_NAME)
6060
return (package_settings, package_settings.get('mix_format', {}))
6161

62+
def call_mix_format_async(window, **kwargs):
63+
file_path = kwargs.get('file_path')
64+
print_status_msg('Formatting %s!' % (file_path and repr(file_path) or 'project'))
65+
sublime.set_timeout_async(lambda: call_mix_format(window, **kwargs))
66+
6267
def call_mix_format(window, **kwargs):
6368
file_path = kwargs.get('file_path')
6469
file_path_list = file_path and [file_path] or []

0 commit comments

Comments
 (0)