Skip to content

Commit e3499ff

Browse files
azizkprincemaple
authored andcommitted
Commands: fixed mix test and format in non-project windows.
Use window.folders() instead of extract_variables().
1 parent d23f2c1 commit e3499ff

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

commands/mix_format.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def call_mix_format(window, **kwargs):
6565
_, cmd_setting = load_mix_format_settings()
6666
cmd = (cmd_setting.get('cmd') or ['mix', 'format']) + file_path_list
6767

68-
window_vars = window.extract_variables()
69-
paths = file_path_list + [window_vars['project_path'], window_vars['folder']]
68+
paths = file_path_list + window.folders()
7069
cwd = next((reverse_find_root_folder(p) for p in paths if p), None)
7170

7271
if not (cwd or file_path):

commands/mix_test.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def description(self):
2727

2828
def run(self, **_kwargs):
2929
abs_file_path = self.window.active_view().file_name()
30-
window_vars = self.window.extract_variables()
3130
mix_settings_path = reverse_find_json_path(self.window, FILE_NAMES.SETTINGS_JSON)
3231

3332
if mix_settings_path:
@@ -198,7 +197,7 @@ def run(self, _edit, seed=None):
198197

199198
save_json_file(mix_settings_path, add_help_info(mix_params))
200199

201-
print_status_msg(msg or 'Error: cannot set mix test seed to: %s' % repr(seed))
200+
print_status_msg(msg or 'Error: cannot set mix test seed to: %r' % seed)
202201

203202
def input(self, _args):
204203
class SeedInputHandler(sublime_plugin.TextInputHandler):
@@ -421,8 +420,7 @@ def find_lines_using_test_names(file_path, test_names):
421420
def reverse_find_json_path(window, json_file_path):
422421
""" Tries to find the given JSON file by going up the folder tree
423422
and trying different starting locations. """
424-
window_vars = window.extract_variables()
425-
paths = [window.active_view().file_name(), window_vars['project_path'], window_vars['folder']]
423+
paths = [window.active_view().file_name()] + window.folders()
426424
root_dir = next((reverse_find_root_folder(p) for p in paths if p), None)
427425

428426
root_dir or print_status_msg(
@@ -497,8 +495,8 @@ def write_to_output(window, cmd_args, params, cwd, get_setting):
497495
output_view = output_file = None
498496

499497
if type(mix_test_output) != str:
500-
msg = 'Error: "mix_test_output" setting is not of type string, but: %s'
501-
print_status_msg(msg % repr(type(mix_test_output)))
498+
msg = 'Error: "output" setting is not of type string, but: %r'
499+
print_status_msg(msg % type(mix_test_output))
502500
elif mix_test_output == 'tab':
503501
output_view = window.new_file()
504502
output_view.set_scratch(True)
@@ -507,20 +505,21 @@ def write_to_output(window, cmd_args, params, cwd, get_setting):
507505
window.run_command('show_panel', {'panel': PANEL_NAME})
508506
elif mix_test_output.startswith('file://'):
509507
mode = get_setting('output_mode') or 'w'
510-
output_path = mix_test_output[7:]
511-
if not path.isabs(output_path):
512-
window_vars = window.extract_variables()
513-
output_dir = window_vars['project_path'] or window_vars['folder']
514-
output_path = path.join(output_dir, output_path)
508+
output_path = Path(mix_test_output[len('file://'):])
509+
output_path = str(
510+
output_path.is_absolute() and output_path
511+
or (window.folders() + [cwd])[0] / output_path
512+
)
513+
515514
try:
516515
output_file = open(output_path, mode)
517516
except (PermissionError, FileNotFoundError, IsADirectoryError) as e:
518-
msg = 'Error: could not open output file %s with mode %s (%s)'
519-
print_status_msg(msg % (repr(output_path), repr(mode), e))
517+
msg = 'Error: could not open output file %r with mode %r (%s)'
518+
print_status_msg(msg % (output_path, mode, e))
520519

521520
if not (output_view or output_file):
522-
msg = 'Error: cannot run `mix test`. No valid output setting ("mix_test_output": %s).'
523-
print_status_msg(msg % repr(mix_test_output))
521+
msg = 'Error: cannot run `mix test`. No valid output setting ("output": %r).'
522+
print_status_msg(msg % mix_test_output)
524523
return
525524

526525
if output_view:

0 commit comments

Comments
 (0)