From 73c0384a6fa0ba34fd52e33c89dc5b1d2364a66c Mon Sep 17 00:00:00 2001 From: herr kaste Date: Fri, 1 Mar 2024 18:34:56 +0100 Subject: [PATCH 1/2] Do not use persistent status sections for status messages Initially the plugin used `window.status_message`s which disappear after a few seconds. A persistent message like "sublack: reformatted" which doesn't even go away when editing the file is not helpful. Persistent messages for the daemon *on the view* are also a mistake as they stick to the view although the daemon has been probably started for the window. Make them non-sticky as well. --- sublack/blacker.py | 19 ++++++------------- sublack/commands.py | 4 ++-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/sublack/blacker.py b/sublack/blacker.py index be9c7ae..f8cc9ee 100644 --- a/sublack/blacker.py +++ b/sublack/blacker.py @@ -280,12 +280,12 @@ def finalize(self, edit: sublime.Edit, extra, returncode, out, err, content, com self.log.debug(f"Black returned: {error_message}") # failure if returncode != 0: - self.view.set_status(consts.STATUS_KEY, error_message) + self.view.window().status_message(error_message) return returncode # already formated, nothing changes elif "unchanged" in error_message: - self.view.set_status(consts.STATUS_KEY, consts.ALREADY_FORMATTED_MESSAGE) + self.view.window().status_message(consts.ALREADY_FORMATTED_MESSAGE) self.add_to_cache(content, command) # diff mode @@ -311,7 +311,7 @@ def finalize(self, edit: sublime.Edit, extra, returncode, out, err, content, com self.view.sel().add(old_sel) # status and caching - self.view.set_status(consts.STATUS_KEY, consts.REFORMATTED_MESSAGE) + self.view.window().status_message(consts.REFORMATTED_MESSAGE) sublime.set_timeout_async(lambda: self.add_to_cache(new_content, command)) def format_via_precommit(self, edit: sublime.Edit, content, cwd, env): @@ -378,7 +378,7 @@ def __call__( # check the cache # cache may not be used with pre-commit if self.is_cached(content, command): - self.view.set_status(consts.STATUS_KEY, consts.ALREADY_FORMATTED_MESSAGE_CACHE) + self.view.window().status_message(consts.ALREADY_FORMATTED_MESSAGE_CACHE) return if use_blackd: @@ -500,16 +500,9 @@ def run(self, extra: list[str] = []): if success_list else consts.REFORMAT_ERRORS ) - # if success_list and error_list: - # error_message = consts.REFORMATTED_ALL_PARTIAL_MESSAGE + if window := self.view.window(): + window.status_message(error_message) - # elif success_list: - # error_message = consts.REFORMATTED_ALL_MESSAGE - - # else: - # error_message = consts.REFORMAT_ERRORS - - self.view.set_status(consts.STATUS_KEY, error_message) for result in success_list: folder, code, output = result self.log.debug( diff --git a/sublack/commands.py b/sublack/commands.py index 478b5ab..3cb5737 100644 --- a/sublack/commands.py +++ b/sublack/commands.py @@ -121,9 +121,9 @@ def run(self): view = sublime.active_window().active_view() assert view, "No view found!" if server.stop_blackd_server(): - view.set_status(consts.STATUS_KEY, consts.BLACKD_STOPPED) + sublime.active_window().status_message(consts.BLACKD_STOPPED) else: - view.set_status(consts.STATUS_KEY, consts.BLACKD_STOP_FAILED) + sublime.active_window().status_message(consts.BLACKD_STOP_FAILED) class BlackFormatAllCommand(sublime_plugin.WindowCommand): From 9b7f3842189fbb151ca56557134e20e240967b13 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Fri, 1 Mar 2024 18:36:25 +0100 Subject: [PATCH 2/2] Fix typo --- sublack/blacker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sublack/blacker.py b/sublack/blacker.py index f8cc9ee..c2c2dbe 100644 --- a/sublack/blacker.py +++ b/sublack/blacker.py @@ -283,7 +283,7 @@ def finalize(self, edit: sublime.Edit, extra, returncode, out, err, content, com self.view.window().status_message(error_message) return returncode - # already formated, nothing changes + # already formatted, nothing changes elif "unchanged" in error_message: self.view.window().status_message(consts.ALREADY_FORMATTED_MESSAGE) self.add_to_cache(content, command)