From 76420cc6013a3a9156209cd63fc5ffbb90e0abc4 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 6 Nov 2024 15:49:12 +0700 Subject: [PATCH 01/27] add 'show_ui_blocking_message' config --- LSP.sublime-settings | 2 ++ plugin/core/types.py | 2 ++ sublime-package.json | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/LSP.sublime-settings b/LSP.sublime-settings index 6cb35033c..15cace3ae 100644 --- a/LSP.sublime-settings +++ b/LSP.sublime-settings @@ -49,6 +49,8 @@ // Show errors and warnings count in the status bar "show_diagnostics_count_in_view_status": false, + "show_ui_blocking_message": true, // Show UI blocking modals or the full console message and short status notification + // Show the diagnostics description of the code // under the cursor in status bar if available. "show_diagnostics_in_view_status": true, diff --git a/plugin/core/types.py b/plugin/core/types.py index b5d5b932f..28b44341e 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -232,6 +232,7 @@ class Settings: show_code_actions_in_hover = cast(bool, None) show_diagnostics_annotations_severity_level = cast(int, None) show_diagnostics_count_in_view_status = cast(bool, None) + show_ui_blocking_message = cast(bool, None) show_multiline_diagnostics_highlights = cast(bool, None) show_multiline_document_highlights = cast(bool, None) show_diagnostics_in_view_status = cast(bool, None) @@ -278,6 +279,7 @@ def r(name: str, default: bool | int | str | list | dict) -> None: r("show_code_actions_in_hover", True) r("show_diagnostics_annotations_severity_level", 0) r("show_diagnostics_count_in_view_status", False) + r("show_ui_blocking_message", True) r("show_diagnostics_in_view_status", True) r("show_multiline_diagnostics_highlights", True) r("show_multiline_document_highlights", True) diff --git a/sublime-package.json b/sublime-package.json index f98b52c50..95e050b79 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -449,6 +449,11 @@ "default": false, "markdownDescription": "Show errors and warnings count in the status bar." }, + "show_ui_blocking_message": { + "type": "boolean", + "default": true, + "markdownDescription": "Show UI blocking modals or the full console message and short status notification." + }, "lsp_format_on_paste": { "$ref": "sublime://settings/LSP#/definitions/lsp_format_on_paste" }, From 2a92fc6a648eda45f4ddcfbd91c987e1e4ee9cbc Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 6 Nov 2024 15:49:50 +0700 Subject: [PATCH 02/27] allow replacing blocking dialog modals with a status+console message --- plugin/core/logging.py | 12 ++++++++++++ plugin/core/windows.py | 4 +++- plugin/core/workspace.py | 11 +++++++---- plugin/execute_command.py | 5 ++++- plugin/tooling.py | 4 +++- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/plugin/core/logging.py b/plugin/core/logging.py index ebaeb3629..6c8fc3102 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -39,3 +39,15 @@ def exception_log(message: str, ex: Exception) -> None: def printf(*args: Any, prefix: str = 'LSP') -> None: """Print args to the console, prefixed by the plugin name.""" print(prefix + ":", *args) + + +def notify(msg: str, status: str = '⚠️LSP: see console log…') -> None: + """Pick either of the 2 ways to show a message: + - via a blocking modal dialog + - via a detailed console message and a short status message""" + from .settings import userprefs + if userprefs().show_ui_blocking_message: + sublime.message_dialog(msg) + else: + sublime.status_message(status) + print(msg) diff --git a/plugin/core/windows.py b/plugin/core/windows.py index 9234724ef..8e0a873e6 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -7,6 +7,7 @@ from .diagnostics_storage import is_severity_included from .logging import debug from .logging import exception_log +from .logging import notify from .message_request_handler import MessageRequestHandler from .panels import LOG_LINES_LIMIT_SETTING_NAME from .panels import MAX_LOG_LINES_LIMIT_OFF @@ -295,12 +296,13 @@ def start_async(self, config: ClientConfig, initiating_view: sublime.View) -> No "Re-enable by running \"LSP: Enable Language Server In Project\" from the Command Palette.", "\n\n--- Error: ---\n{1}" )).format(config.name, str(e)) + console = f"⚠️LSP: Failed to start {config.name}…" exception_log(f"Unable to start subprocess for {config.name}", e) if isinstance(e, CalledProcessError): print("Server output:\n{}".format(e.output.decode('utf-8', 'replace'))) self._config_manager.disable_config(config.name, only_for_session=True) config.erase_view_status(initiating_view) - sublime.message_dialog(message) + notify(message, console) # Continue with handling pending listeners self._new_session = None sublime.set_timeout_async(self._dequeue_listener_async) diff --git a/plugin/core/workspace.py b/plugin/core/workspace.py index e0d2b7a10..7ef95f163 100644 --- a/plugin/core/workspace.py +++ b/plugin/core/workspace.py @@ -4,6 +4,7 @@ from .types import matches_pattern from .types import sublime_pattern_to_glob from .url import filename_to_uri +from .logging import notify from typing import Any import sublime import os @@ -146,8 +147,9 @@ def enable_in_project(window: sublime.Window, config_name: str) -> None: project_client_settings['enabled'] = True window.set_project_data(project_data) else: - sublime.message_dialog( - f"Can't enable {config_name} in the current workspace. Ensure that the project is saved first.") + msg = f"Can't enable {config_name} in the current workspace. Ensure that the project is saved first." + status = f"⚠️LSP: Can't enable {config_name} in this workspace…" + notify(msg, status) def disable_in_project(window: sublime.Window, config_name: str) -> None: @@ -159,5 +161,6 @@ def disable_in_project(window: sublime.Window, config_name: str) -> None: project_client_settings['enabled'] = False window.set_project_data(project_data) else: - sublime.message_dialog( - f"Can't disable {config_name} in the current workspace. Ensure that the project is saved first.") + msg = f"Can't disable {config_name} in the current workspace. Ensure that the project is saved first." + status = f"⚠️LSP: Can't enable {config_name} in this workspace…" + notify(msg, status) diff --git a/plugin/execute_command.py b/plugin/execute_command.py index 78253402f..8cdd31304 100644 --- a/plugin/execute_command.py +++ b/plugin/execute_command.py @@ -1,4 +1,5 @@ from __future__ import annotations +from .core.logging import notify from .core.protocol import Error from .core.protocol import ExecuteCommandParams from .core.registry import LspTextCommand @@ -58,7 +59,9 @@ def handle_error_async(self, error: Error, command_name: str) -> None: :param error: The Error object. :param command_name: The name of the command that was executed. """ - sublime.message_dialog(f"command {command_name} failed. Reason: {str(error)}") + msg = f"command {command_name} failed. Reason: {str(error)}" + status = f"⚠️LSP: {command_name} failed…" + notify(msg, status) def _expand_variables(self, command_args: list[Any]) -> list[Any]: view = self.view diff --git a/plugin/tooling.py b/plugin/tooling.py index acfb42c0b..dcee1870d 100644 --- a/plugin/tooling.py +++ b/plugin/tooling.py @@ -1,6 +1,7 @@ from __future__ import annotations from .core.css import css from .core.logging import debug +from .core.logging import notify from .core.registry import windows from .core.sessions import get_plugin from .core.transports import create_transport @@ -303,7 +304,8 @@ def run(self) -> None: return view = wm.window.active_view() if not view: - sublime.message_dialog('Troubleshooting must be run with a file opened') + msg = 'Troubleshooting must be run with a file opened' + notify(msg, msg) return active_view = view configs = wm.get_config_manager().get_configs() From 81e3567ef23a65a7299527289a3faf427c300013 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 6 Nov 2024 16:39:01 +0700 Subject: [PATCH 03/27] add 'show_ui_blocking_err_message' config --- LSP.sublime-settings | 1 + sublime-package.json | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/LSP.sublime-settings b/LSP.sublime-settings index 15cace3ae..7d104d645 100644 --- a/LSP.sublime-settings +++ b/LSP.sublime-settings @@ -50,6 +50,7 @@ "show_diagnostics_count_in_view_status": false, "show_ui_blocking_message": true, // Show UI blocking modals or the full console message and short status notification + "show_ui_blocking_err_message": true, // Show UI blocking error modals or the full console message and short status notification // Show the diagnostics description of the code // under the cursor in status bar if available. diff --git a/sublime-package.json b/sublime-package.json index 95e050b79..1c456a741 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -454,6 +454,11 @@ "default": true, "markdownDescription": "Show UI blocking modals or the full console message and short status notification." }, + "show_ui_blocking_err_message": { + "type": "boolean", + "default": true, + "markdownDescription": "Show UI blocking error modals or the full console message and short status notification." + }, "lsp_format_on_paste": { "$ref": "sublime://settings/LSP#/definitions/lsp_format_on_paste" }, From f552660118df5ca095cc4092c743a496ebb73c7f Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 6 Nov 2024 16:47:01 +0700 Subject: [PATCH 04/27] allow replacing blocking error dialog modals with a status+console message --- plugin/code_actions.py | 7 +++++-- plugin/core/logging.py | 12 ++++++++++++ plugin/core/types.py | 2 ++ plugin/rename.py | 7 +++++-- plugin/tooling.py | 24 +++++++++++++++++------- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/plugin/code_actions.py b/plugin/code_actions.py index 2056a866f..973d23d88 100644 --- a/plugin/code_actions.py +++ b/plugin/code_actions.py @@ -1,4 +1,5 @@ from __future__ import annotations +from .core.logging import notify_err from .core.promise import Promise from .core.protocol import CodeAction from .core.protocol import CodeActionKind @@ -352,7 +353,8 @@ def run_async() -> None: def _handle_response_async(self, session_name: str, response: Any) -> None: if isinstance(response, Error): - sublime.error_message(f"{session_name}: {str(response)}") + msg = f"{session_name}: {str(response)}" + notify_err(msg, msg) # This command must be a WindowCommand in order to reliably hide corresponding menu entries when no view has focus. @@ -414,7 +416,8 @@ def run_async(self, index: int, event: dict | None) -> None: def _handle_response_async(self, session_name: str, response: Any) -> None: if isinstance(response, Error): - sublime.error_message(f"{session_name}: {str(response)}") + msg = f"{session_name}: {str(response)}" + notify_err(msg, msg) def _is_cache_valid(self, event: dict | None) -> bool: view = self.view diff --git a/plugin/core/logging.py b/plugin/core/logging.py index 6c8fc3102..1461010a8 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -51,3 +51,15 @@ def notify(msg: str, status: str = '⚠️LSP: see console log…') -> None: else: sublime.status_message(status) print(msg) + + +def notify_err(msg: str, status: str = '❗LSP: see console log…') -> None: + """Pick either of the 2 ways to show a message: + - via a blocking modal dialog + - via a detailed console message and a short status message""" + from .settings import userprefs + if userprefs().show_ui_blocking_err_message: + sublime.message_dialog(msg) + else: + sublime.error_message(status) + print(msg) diff --git a/plugin/core/types.py b/plugin/core/types.py index 28b44341e..b0d136516 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -233,6 +233,7 @@ class Settings: show_diagnostics_annotations_severity_level = cast(int, None) show_diagnostics_count_in_view_status = cast(bool, None) show_ui_blocking_message = cast(bool, None) + show_ui_blocking_err_message = cast(bool, None) show_multiline_diagnostics_highlights = cast(bool, None) show_multiline_document_highlights = cast(bool, None) show_diagnostics_in_view_status = cast(bool, None) @@ -280,6 +281,7 @@ def r(name: str, default: bool | int | str | list | dict) -> None: r("show_diagnostics_annotations_severity_level", 0) r("show_diagnostics_count_in_view_status", False) r("show_ui_blocking_message", True) + r("show_ui_blocking_err_message", True) r("show_diagnostics_in_view_status", True) r("show_multiline_diagnostics_highlights", True) r("show_multiline_document_highlights", True) diff --git a/plugin/rename.py b/plugin/rename.py index bbbf82ea0..6925f1b16 100644 --- a/plugin/rename.py +++ b/plugin/rename.py @@ -2,6 +2,7 @@ from .core.edit import parse_range from .core.edit import parse_workspace_edit from .core.edit import WorkspaceChanges +from .core.logging import notify_err from .core.protocol import PrepareRenameParams from .core.protocol import PrepareRenameResult from .core.protocol import Range @@ -211,7 +212,8 @@ def _on_rename_result_async(self, session: Session, response: WorkspaceEdit | No def _on_prepare_result(self, pos: int, session_name: str | None, response: PrepareRenameResult | None) -> None: if response is None: - sublime.error_message("The current selection cannot be renamed") + msg = "The current selection cannot be renamed" + notify_err(msg, msg) return if is_range_response(response): r = range_to_region(response, self.view) @@ -226,7 +228,8 @@ def _on_prepare_result(self, pos: int, session_name: str | None, response: Prepa self.view.run_command("lsp_symbol_rename", args) def _on_prepare_error(self, error: Any) -> None: - sublime.error_message("Rename error: {}".format(error["message"])) + msg = "Rename error: {}".format(error["message"]) + notify_err(msg, msg) def _get_relative_path(self, file_path: str) -> str: wm = windows.lookup(self.view.window()) diff --git a/plugin/tooling.py b/plugin/tooling.py index dcee1870d..3643d9fd7 100644 --- a/plugin/tooling.py +++ b/plugin/tooling.py @@ -2,6 +2,7 @@ from .core.css import css from .core.logging import debug from .core.logging import notify +from .core.logging import notify_err from .core.registry import windows from .core.sessions import get_plugin from .core.transports import create_transport @@ -131,15 +132,19 @@ def run(self, base_package_name: str) -> None: try: urllib.parse.urlparse(base_url) except Exception: - sublime.error_message("The clipboard content must be a URL to a package.json file.") + msg = "The clipboard content must be a URL to a package.json file." + status = "Clipboard must be a URL to package.json" + notify_err(msg, status) return if not base_url.endswith("package.json"): - sublime.error_message("URL must end with 'package.json'") + msg = "URL must end with 'package.json'" + notify_err(msg, msg) return try: package = json.loads(urllib.request.urlopen(base_url).read().decode("utf-8")) except Exception as ex: - sublime.error_message(f'Unable to load "{base_url}": {ex}') + msg = f'Unable to load "{base_url}": {ex}' + notify_err(msg, msg) return # There might be a translations file as well. @@ -151,11 +156,13 @@ def run(self, base_package_name: str) -> None: contributes = package.get("contributes") if not isinstance(contributes, dict): - sublime.error_message('No "contributes" key found!') + msg = 'No "contributes" key found!' + notify_err(msg, msg) return configuration = contributes.get("configuration") if not isinstance(configuration, dict) and not isinstance(configuration, list): - sublime.error_message('No "contributes.configuration" key found!') + msg = 'No "contributes.configuration" key found!' + notify_err(msg, msg) return if isinstance(configuration, dict): properties = configuration.get("properties") @@ -164,7 +171,8 @@ def run(self, base_package_name: str) -> None: for configuration_item in configuration: properties.update(configuration_item.get("properties")) if not isinstance(properties, dict): - sublime.error_message('No "contributes.configuration.properties" key found!') + msg = 'No "contributes.configuration.properties" key found!' + notify_err(msg, msg) return # Process each key-value pair of the server settings. @@ -459,7 +467,9 @@ def run(self, edit: sublime.Edit) -> None: return listener = wm.listener_for_view(self.view) if not listener or not any(listener.session_views_async()): - sublime.error_message("There is no language server running for this view.") + msg = "There is no language server running for this view." + status = "No language server for this view" + notify_err(msg, status) return v = wm.window.new_file() v.set_scratch(True) From 1bbcef429cb30d837adfc1b535d28b5c9e5d151d Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 00:36:12 +0700 Subject: [PATCH 05/27] add "see console" --- plugin/core/windows.py | 4 ++-- plugin/core/workspace.py | 4 ++-- plugin/execute_command.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin/core/windows.py b/plugin/core/windows.py index 8e0a873e6..0ef8dc321 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -296,13 +296,13 @@ def start_async(self, config: ClientConfig, initiating_view: sublime.View) -> No "Re-enable by running \"LSP: Enable Language Server In Project\" from the Command Palette.", "\n\n--- Error: ---\n{1}" )).format(config.name, str(e)) - console = f"⚠️LSP: Failed to start {config.name}…" + status = f"⚠️LSP: Failed to start {config.name}… See console" exception_log(f"Unable to start subprocess for {config.name}", e) if isinstance(e, CalledProcessError): print("Server output:\n{}".format(e.output.decode('utf-8', 'replace'))) self._config_manager.disable_config(config.name, only_for_session=True) config.erase_view_status(initiating_view) - notify(message, console) + notify(message, status) # Continue with handling pending listeners self._new_session = None sublime.set_timeout_async(self._dequeue_listener_async) diff --git a/plugin/core/workspace.py b/plugin/core/workspace.py index 7ef95f163..e8af61c1b 100644 --- a/plugin/core/workspace.py +++ b/plugin/core/workspace.py @@ -148,7 +148,7 @@ def enable_in_project(window: sublime.Window, config_name: str) -> None: window.set_project_data(project_data) else: msg = f"Can't enable {config_name} in the current workspace. Ensure that the project is saved first." - status = f"⚠️LSP: Can't enable {config_name} in this workspace…" + status = f"⚠️LSP: Can't enable {config_name} in this workspace… See console" notify(msg, status) @@ -162,5 +162,5 @@ def disable_in_project(window: sublime.Window, config_name: str) -> None: window.set_project_data(project_data) else: msg = f"Can't disable {config_name} in the current workspace. Ensure that the project is saved first." - status = f"⚠️LSP: Can't enable {config_name} in this workspace…" + status = f"⚠️LSP: Can't enable {config_name} in this workspace… See console" notify(msg, status) diff --git a/plugin/execute_command.py b/plugin/execute_command.py index 8cdd31304..ad744efe7 100644 --- a/plugin/execute_command.py +++ b/plugin/execute_command.py @@ -60,7 +60,7 @@ def handle_error_async(self, error: Error, command_name: str) -> None: :param command_name: The name of the command that was executed. """ msg = f"command {command_name} failed. Reason: {str(error)}" - status = f"⚠️LSP: {command_name} failed…" + status = f"⚠️LSP: {command_name} failed… See console" notify(msg, status) def _expand_variables(self, command_args: list[Any]) -> list[Any]: From c0c9dedc911b0dec08cfd7e7c02167d7761e2777 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 00:50:20 +0700 Subject: [PATCH 06/27] use window instead of sublime for message dialogs --- plugin/core/logging.py | 6 +++--- plugin/core/windows.py | 2 +- plugin/core/workspace.py | 4 ++-- plugin/execute_command.py | 2 +- plugin/tooling.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugin/core/logging.py b/plugin/core/logging.py index 1461010a8..6a1d63595 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -41,15 +41,15 @@ def printf(*args: Any, prefix: str = 'LSP') -> None: print(prefix + ":", *args) -def notify(msg: str, status: str = '⚠️LSP: see console log…') -> None: +def notify(win: sublime.Window, msg: str, status: str = '⚠️LSP: see console log…') -> None: """Pick either of the 2 ways to show a message: - via a blocking modal dialog - via a detailed console message and a short status message""" from .settings import userprefs if userprefs().show_ui_blocking_message: - sublime.message_dialog(msg) + win.message_dialog(msg) else: - sublime.status_message(status) + win.status_message(status) print(msg) diff --git a/plugin/core/windows.py b/plugin/core/windows.py index 0ef8dc321..b68b609d2 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -302,7 +302,7 @@ def start_async(self, config: ClientConfig, initiating_view: sublime.View) -> No print("Server output:\n{}".format(e.output.decode('utf-8', 'replace'))) self._config_manager.disable_config(config.name, only_for_session=True) config.erase_view_status(initiating_view) - notify(message, status) + notify(self._window, message, status) # Continue with handling pending listeners self._new_session = None sublime.set_timeout_async(self._dequeue_listener_async) diff --git a/plugin/core/workspace.py b/plugin/core/workspace.py index e8af61c1b..a7ead4fbc 100644 --- a/plugin/core/workspace.py +++ b/plugin/core/workspace.py @@ -149,7 +149,7 @@ def enable_in_project(window: sublime.Window, config_name: str) -> None: else: msg = f"Can't enable {config_name} in the current workspace. Ensure that the project is saved first." status = f"⚠️LSP: Can't enable {config_name} in this workspace… See console" - notify(msg, status) + notify(window, msg, status) def disable_in_project(window: sublime.Window, config_name: str) -> None: @@ -163,4 +163,4 @@ def disable_in_project(window: sublime.Window, config_name: str) -> None: else: msg = f"Can't disable {config_name} in the current workspace. Ensure that the project is saved first." status = f"⚠️LSP: Can't enable {config_name} in this workspace… See console" - notify(msg, status) + notify(window, msg, status) diff --git a/plugin/execute_command.py b/plugin/execute_command.py index ad744efe7..e6e42057a 100644 --- a/plugin/execute_command.py +++ b/plugin/execute_command.py @@ -61,7 +61,7 @@ def handle_error_async(self, error: Error, command_name: str) -> None: """ msg = f"command {command_name} failed. Reason: {str(error)}" status = f"⚠️LSP: {command_name} failed… See console" - notify(msg, status) + notify(self.view.window(), msg, status) def _expand_variables(self, command_args: list[Any]) -> list[Any]: view = self.view diff --git a/plugin/tooling.py b/plugin/tooling.py index 3643d9fd7..156dc4aed 100644 --- a/plugin/tooling.py +++ b/plugin/tooling.py @@ -313,7 +313,7 @@ def run(self) -> None: view = wm.window.active_view() if not view: msg = 'Troubleshooting must be run with a file opened' - notify(msg, msg) + notify(self.window, msg, msg) return active_view = view configs = wm.get_config_manager().get_configs() From 3747b4684c028b8d68e87d712bd62bf410de8bcd Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 01:30:24 +0700 Subject: [PATCH 07/27] use window instead of sublime for error dialogs --- plugin/core/logging.py | 6 +++--- plugin/tooling.py | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/plugin/core/logging.py b/plugin/core/logging.py index 6a1d63595..ee4a9302b 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -53,13 +53,13 @@ def notify(win: sublime.Window, msg: str, status: str = '⚠️LSP: see console print(msg) -def notify_err(msg: str, status: str = '❗LSP: see console log…') -> None: +def notify_err(win: sublime.Window, msg: str, status: str = '❗LSP: see console log…') -> None: """Pick either of the 2 ways to show a message: - via a blocking modal dialog - via a detailed console message and a short status message""" from .settings import userprefs if userprefs().show_ui_blocking_err_message: - sublime.message_dialog(msg) + sublime.error_message(msg) else: - sublime.error_message(status) + win.status_message(status) print(msg) diff --git a/plugin/tooling.py b/plugin/tooling.py index 156dc4aed..3f5fd09e9 100644 --- a/plugin/tooling.py +++ b/plugin/tooling.py @@ -134,17 +134,17 @@ def run(self, base_package_name: str) -> None: except Exception: msg = "The clipboard content must be a URL to a package.json file." status = "Clipboard must be a URL to package.json" - notify_err(msg, status) + notify_err(sublime.active_window(), msg, status) return if not base_url.endswith("package.json"): msg = "URL must end with 'package.json'" - notify_err(msg, msg) + notify_err(sublime.active_window(), msg, msg) return try: package = json.loads(urllib.request.urlopen(base_url).read().decode("utf-8")) except Exception as ex: msg = f'Unable to load "{base_url}": {ex}' - notify_err(msg, msg) + notify_err(sublime.active_window(), msg, msg) return # There might be a translations file as well. @@ -157,12 +157,12 @@ def run(self, base_package_name: str) -> None: contributes = package.get("contributes") if not isinstance(contributes, dict): msg = 'No "contributes" key found!' - notify_err(msg, msg) + notify_err(sublime.active_window(), msg, msg) return configuration = contributes.get("configuration") if not isinstance(configuration, dict) and not isinstance(configuration, list): msg = 'No "contributes.configuration" key found!' - notify_err(msg, msg) + notify_err(sublime.active_window(), msg, msg) return if isinstance(configuration, dict): properties = configuration.get("properties") @@ -172,7 +172,7 @@ def run(self, base_package_name: str) -> None: properties.update(configuration_item.get("properties")) if not isinstance(properties, dict): msg = 'No "contributes.configuration.properties" key found!' - notify_err(msg, msg) + notify_err(sublime.active_window(), msg, msg) return # Process each key-value pair of the server settings. @@ -469,7 +469,7 @@ def run(self, edit: sublime.Edit) -> None: if not listener or not any(listener.session_views_async()): msg = "There is no language server running for this view." status = "No language server for this view" - notify_err(msg, status) + notify_err(wm.window, msg, status) return v = wm.window.new_file() v.set_scratch(True) From 74c0af3d0973154bcd77b925d81d3fa13807e903 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 14:51:24 +0700 Subject: [PATCH 08/27] =?UTF-8?q?remove=20=E2=9A=A0=EF=B8=8F=20for=20messa?= =?UTF-8?q?ges=20(leave=20=E2=9D=97=20for=20errors)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/core/logging.py | 2 +- plugin/core/windows.py | 2 +- plugin/core/workspace.py | 4 ++-- plugin/execute_command.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin/core/logging.py b/plugin/core/logging.py index ee4a9302b..d86124296 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -41,7 +41,7 @@ def printf(*args: Any, prefix: str = 'LSP') -> None: print(prefix + ":", *args) -def notify(win: sublime.Window, msg: str, status: str = '⚠️LSP: see console log…') -> None: +def notify(win: sublime.Window, msg: str, status: str = 'LSP: see console log…') -> None: """Pick either of the 2 ways to show a message: - via a blocking modal dialog - via a detailed console message and a short status message""" diff --git a/plugin/core/windows.py b/plugin/core/windows.py index b68b609d2..6e5cb3d69 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -296,7 +296,7 @@ def start_async(self, config: ClientConfig, initiating_view: sublime.View) -> No "Re-enable by running \"LSP: Enable Language Server In Project\" from the Command Palette.", "\n\n--- Error: ---\n{1}" )).format(config.name, str(e)) - status = f"⚠️LSP: Failed to start {config.name}… See console" + status = f"LSP: Failed to start {config.name}… See console" exception_log(f"Unable to start subprocess for {config.name}", e) if isinstance(e, CalledProcessError): print("Server output:\n{}".format(e.output.decode('utf-8', 'replace'))) diff --git a/plugin/core/workspace.py b/plugin/core/workspace.py index a7ead4fbc..8a7dcc9c4 100644 --- a/plugin/core/workspace.py +++ b/plugin/core/workspace.py @@ -148,7 +148,7 @@ def enable_in_project(window: sublime.Window, config_name: str) -> None: window.set_project_data(project_data) else: msg = f"Can't enable {config_name} in the current workspace. Ensure that the project is saved first." - status = f"⚠️LSP: Can't enable {config_name} in this workspace… See console" + status = f"LSP: Can't enable {config_name} in this workspace… See console" notify(window, msg, status) @@ -162,5 +162,5 @@ def disable_in_project(window: sublime.Window, config_name: str) -> None: window.set_project_data(project_data) else: msg = f"Can't disable {config_name} in the current workspace. Ensure that the project is saved first." - status = f"⚠️LSP: Can't enable {config_name} in this workspace… See console" + status = f"LSP: Can't enable {config_name} in this workspace… See console" notify(window, msg, status) diff --git a/plugin/execute_command.py b/plugin/execute_command.py index e6e42057a..fea7e8ca6 100644 --- a/plugin/execute_command.py +++ b/plugin/execute_command.py @@ -60,7 +60,7 @@ def handle_error_async(self, error: Error, command_name: str) -> None: :param command_name: The name of the command that was executed. """ msg = f"command {command_name} failed. Reason: {str(error)}" - status = f"⚠️LSP: {command_name} failed… See console" + status = f"LSP: {command_name} failed… See console" notify(self.view.window(), msg, status) def _expand_variables(self, command_args: list[Any]) -> list[Any]: From d78e13960a701da86ba95264397b7c79a4ce7773 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 14:55:48 +0700 Subject: [PATCH 09/27] combine two blocking options into one suppress_error_dialogs --- LSP.sublime-settings | 3 +-- plugin/core/logging.py | 4 ++-- plugin/core/types.py | 6 ++---- sublime-package.json | 9 ++------- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/LSP.sublime-settings b/LSP.sublime-settings index 7d104d645..e2d880d07 100644 --- a/LSP.sublime-settings +++ b/LSP.sublime-settings @@ -49,8 +49,7 @@ // Show errors and warnings count in the status bar "show_diagnostics_count_in_view_status": false, - "show_ui_blocking_message": true, // Show UI blocking modals or the full console message and short status notification - "show_ui_blocking_err_message": true, // Show UI blocking error modals or the full console message and short status notification + "suppress_error_dialogs": false, // Replace UI blocking modals with the full console message and a short status notification // Show the diagnostics description of the code // under the cursor in status bar if available. diff --git a/plugin/core/logging.py b/plugin/core/logging.py index d86124296..d2e23e67e 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -46,7 +46,7 @@ def notify(win: sublime.Window, msg: str, status: str = 'LSP: see console log… - via a blocking modal dialog - via a detailed console message and a short status message""" from .settings import userprefs - if userprefs().show_ui_blocking_message: + if userprefs().suppress_error_dialogs: win.message_dialog(msg) else: win.status_message(status) @@ -58,7 +58,7 @@ def notify_err(win: sublime.Window, msg: str, status: str = '❗LSP: see console - via a blocking modal dialog - via a detailed console message and a short status message""" from .settings import userprefs - if userprefs().show_ui_blocking_err_message: + if userprefs().suppress_error_dialogs: sublime.error_message(msg) else: win.status_message(status) diff --git a/plugin/core/types.py b/plugin/core/types.py index b0d136516..608b1e9c3 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -232,8 +232,7 @@ class Settings: show_code_actions_in_hover = cast(bool, None) show_diagnostics_annotations_severity_level = cast(int, None) show_diagnostics_count_in_view_status = cast(bool, None) - show_ui_blocking_message = cast(bool, None) - show_ui_blocking_err_message = cast(bool, None) + suppress_error_dialogs = cast(bool, None) show_multiline_diagnostics_highlights = cast(bool, None) show_multiline_document_highlights = cast(bool, None) show_diagnostics_in_view_status = cast(bool, None) @@ -280,8 +279,7 @@ def r(name: str, default: bool | int | str | list | dict) -> None: r("show_code_actions_in_hover", True) r("show_diagnostics_annotations_severity_level", 0) r("show_diagnostics_count_in_view_status", False) - r("show_ui_blocking_message", True) - r("show_ui_blocking_err_message", True) + r("suppress_error_dialogs", False) r("show_diagnostics_in_view_status", True) r("show_multiline_diagnostics_highlights", True) r("show_multiline_document_highlights", True) diff --git a/sublime-package.json b/sublime-package.json index 1c456a741..e04e0fc66 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -449,14 +449,9 @@ "default": false, "markdownDescription": "Show errors and warnings count in the status bar." }, - "show_ui_blocking_message": { + "suppress_error_dialogs": { "type": "boolean", - "default": true, - "markdownDescription": "Show UI blocking modals or the full console message and short status notification." - }, - "show_ui_blocking_err_message": { - "type": "boolean", - "default": true, + "default": false, "markdownDescription": "Show UI blocking error modals or the full console message and short status notification." }, "lsp_format_on_paste": { From 96884ff8939d2468cd498ebcebed7acd83c7d877 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 14:57:17 +0700 Subject: [PATCH 10/27] suppress dialogs by default --- LSP.sublime-settings | 2 +- plugin/core/types.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LSP.sublime-settings b/LSP.sublime-settings index e2d880d07..29476b7e6 100644 --- a/LSP.sublime-settings +++ b/LSP.sublime-settings @@ -49,7 +49,7 @@ // Show errors and warnings count in the status bar "show_diagnostics_count_in_view_status": false, - "suppress_error_dialogs": false, // Replace UI blocking modals with the full console message and a short status notification + "suppress_error_dialogs": true, // Replace UI blocking modals with the full console message and a short status notification // Show the diagnostics description of the code // under the cursor in status bar if available. diff --git a/plugin/core/types.py b/plugin/core/types.py index 608b1e9c3..9b4cb1de7 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -279,7 +279,7 @@ def r(name: str, default: bool | int | str | list | dict) -> None: r("show_code_actions_in_hover", True) r("show_diagnostics_annotations_severity_level", 0) r("show_diagnostics_count_in_view_status", False) - r("suppress_error_dialogs", False) + r("suppress_error_dialogs", True) r("show_diagnostics_in_view_status", True) r("show_multiline_diagnostics_highlights", True) r("show_multiline_document_highlights", True) From a2743ce5b045fa28816d1b14cc63325a575a4b9c Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 14:58:47 +0700 Subject: [PATCH 11/27] swap logging logick to reflect the settings change show became suppress, so dialogs reversed with status messages --- plugin/core/logging.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/core/logging.py b/plugin/core/logging.py index d2e23e67e..bbd337a14 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -47,10 +47,10 @@ def notify(win: sublime.Window, msg: str, status: str = 'LSP: see console log… - via a detailed console message and a short status message""" from .settings import userprefs if userprefs().suppress_error_dialogs: - win.message_dialog(msg) - else: win.status_message(status) print(msg) + else: + win.message_dialog(msg) def notify_err(win: sublime.Window, msg: str, status: str = '❗LSP: see console log…') -> None: @@ -59,7 +59,7 @@ def notify_err(win: sublime.Window, msg: str, status: str = '❗LSP: see console - via a detailed console message and a short status message""" from .settings import userprefs if userprefs().suppress_error_dialogs: - sublime.error_message(msg) - else: win.status_message(status) print(msg) + else: + sublime.error_message(msg) From 39f64292aa2082335719392db14c8738ce62d358 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 15:10:42 +0700 Subject: [PATCH 12/27] move setting to other --- LSP.sublime-settings | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/LSP.sublime-settings b/LSP.sublime-settings index 29476b7e6..b4ba10752 100644 --- a/LSP.sublime-settings +++ b/LSP.sublime-settings @@ -49,8 +49,6 @@ // Show errors and warnings count in the status bar "show_diagnostics_count_in_view_status": false, - "suppress_error_dialogs": true, // Replace UI blocking modals with the full console message and a short status notification - // Show the diagnostics description of the code // under the cursor in status bar if available. "show_diagnostics_in_view_status": true, @@ -165,6 +163,9 @@ // --- Other -------------------------------------------------------------------------- + // Replace UI blocking modals with the full console message and a short status notification + "suppress_error_dialogs": true, + // Show symbol references in Sublime's quick panel instead of the output panel. "show_references_in_quick_panel": true, From 9d40852d9f8243af2898006b3125e7b9b53fd9ef Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 15:19:56 +0700 Subject: [PATCH 13/27] use longer names --- plugin/code_actions.py | 10 +++++----- plugin/core/logging.py | 16 ++++++++-------- plugin/core/workspace.py | 8 ++++---- plugin/execute_command.py | 4 ++-- plugin/rename.py | 10 +++++----- plugin/tooling.py | 34 +++++++++++++++++----------------- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/plugin/code_actions.py b/plugin/code_actions.py index 973d23d88..74e720388 100644 --- a/plugin/code_actions.py +++ b/plugin/code_actions.py @@ -1,5 +1,5 @@ from __future__ import annotations -from .core.logging import notify_err +from .core.logging import notify_error from .core.promise import Promise from .core.protocol import CodeAction from .core.protocol import CodeActionKind @@ -353,8 +353,8 @@ def run_async() -> None: def _handle_response_async(self, session_name: str, response: Any) -> None: if isinstance(response, Error): - msg = f"{session_name}: {str(response)}" - notify_err(msg, msg) + message = f"{session_name}: {str(response)}" + notify_error(message, message) # This command must be a WindowCommand in order to reliably hide corresponding menu entries when no view has focus. @@ -416,8 +416,8 @@ def run_async(self, index: int, event: dict | None) -> None: def _handle_response_async(self, session_name: str, response: Any) -> None: if isinstance(response, Error): - msg = f"{session_name}: {str(response)}" - notify_err(msg, msg) + message = f"{session_name}: {str(response)}" + notify_error(message, message) def _is_cache_valid(self, event: dict | None) -> bool: view = self.view diff --git a/plugin/core/logging.py b/plugin/core/logging.py index bbd337a14..2c0b24d9e 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -41,25 +41,25 @@ def printf(*args: Any, prefix: str = 'LSP') -> None: print(prefix + ":", *args) -def notify(win: sublime.Window, msg: str, status: str = 'LSP: see console log…') -> None: +def notify(window: sublime.Window, message: str, status: str = 'LSP: see console log…') -> None: """Pick either of the 2 ways to show a message: - via a blocking modal dialog - via a detailed console message and a short status message""" from .settings import userprefs if userprefs().suppress_error_dialogs: - win.status_message(status) - print(msg) + window.status_message(status) + print(message) else: - win.message_dialog(msg) + window.message_dialog(message) -def notify_err(win: sublime.Window, msg: str, status: str = '❗LSP: see console log…') -> None: +def notify_error(window: sublime.Window, message: str, status: str = '❗LSP: see console log…') -> None: """Pick either of the 2 ways to show a message: - via a blocking modal dialog - via a detailed console message and a short status message""" from .settings import userprefs if userprefs().suppress_error_dialogs: - win.status_message(status) - print(msg) + window.status_message(status) + print(message) else: - sublime.error_message(msg) + sublime.error_message(message) diff --git a/plugin/core/workspace.py b/plugin/core/workspace.py index 8a7dcc9c4..cc87dd070 100644 --- a/plugin/core/workspace.py +++ b/plugin/core/workspace.py @@ -147,9 +147,9 @@ def enable_in_project(window: sublime.Window, config_name: str) -> None: project_client_settings['enabled'] = True window.set_project_data(project_data) else: - msg = f"Can't enable {config_name} in the current workspace. Ensure that the project is saved first." + message = f"Can't enable {config_name} in the current workspace. Ensure that the project is saved first." status = f"LSP: Can't enable {config_name} in this workspace… See console" - notify(window, msg, status) + notify(window, message, status) def disable_in_project(window: sublime.Window, config_name: str) -> None: @@ -161,6 +161,6 @@ def disable_in_project(window: sublime.Window, config_name: str) -> None: project_client_settings['enabled'] = False window.set_project_data(project_data) else: - msg = f"Can't disable {config_name} in the current workspace. Ensure that the project is saved first." + message = f"Can't disable {config_name} in the current workspace. Ensure that the project is saved first." status = f"LSP: Can't enable {config_name} in this workspace… See console" - notify(window, msg, status) + notify(window, message, status) diff --git a/plugin/execute_command.py b/plugin/execute_command.py index fea7e8ca6..d89fe4e65 100644 --- a/plugin/execute_command.py +++ b/plugin/execute_command.py @@ -59,9 +59,9 @@ def handle_error_async(self, error: Error, command_name: str) -> None: :param error: The Error object. :param command_name: The name of the command that was executed. """ - msg = f"command {command_name} failed. Reason: {str(error)}" + message = f"command {command_name} failed. Reason: {str(error)}" status = f"LSP: {command_name} failed… See console" - notify(self.view.window(), msg, status) + notify(self.view.window(), message, status) def _expand_variables(self, command_args: list[Any]) -> list[Any]: view = self.view diff --git a/plugin/rename.py b/plugin/rename.py index 6925f1b16..715536af8 100644 --- a/plugin/rename.py +++ b/plugin/rename.py @@ -2,7 +2,7 @@ from .core.edit import parse_range from .core.edit import parse_workspace_edit from .core.edit import WorkspaceChanges -from .core.logging import notify_err +from .core.logging import notify_error from .core.protocol import PrepareRenameParams from .core.protocol import PrepareRenameResult from .core.protocol import Range @@ -212,8 +212,8 @@ def _on_rename_result_async(self, session: Session, response: WorkspaceEdit | No def _on_prepare_result(self, pos: int, session_name: str | None, response: PrepareRenameResult | None) -> None: if response is None: - msg = "The current selection cannot be renamed" - notify_err(msg, msg) + message = "The current selection cannot be renamed" + notify_error(message, message) return if is_range_response(response): r = range_to_region(response, self.view) @@ -228,8 +228,8 @@ def _on_prepare_result(self, pos: int, session_name: str | None, response: Prepa self.view.run_command("lsp_symbol_rename", args) def _on_prepare_error(self, error: Any) -> None: - msg = "Rename error: {}".format(error["message"]) - notify_err(msg, msg) + message = "Rename error: {}".format(error["message"]) + notify_error(message, message) def _get_relative_path(self, file_path: str) -> str: wm = windows.lookup(self.view.window()) diff --git a/plugin/tooling.py b/plugin/tooling.py index 3f5fd09e9..aa1a982fd 100644 --- a/plugin/tooling.py +++ b/plugin/tooling.py @@ -2,7 +2,7 @@ from .core.css import css from .core.logging import debug from .core.logging import notify -from .core.logging import notify_err +from .core.logging import notify_error from .core.registry import windows from .core.sessions import get_plugin from .core.transports import create_transport @@ -132,19 +132,19 @@ def run(self, base_package_name: str) -> None: try: urllib.parse.urlparse(base_url) except Exception: - msg = "The clipboard content must be a URL to a package.json file." + message = "The clipboard content must be a URL to a package.json file." status = "Clipboard must be a URL to package.json" - notify_err(sublime.active_window(), msg, status) + notify_error(sublime.active_window(), message, status) return if not base_url.endswith("package.json"): - msg = "URL must end with 'package.json'" - notify_err(sublime.active_window(), msg, msg) + message = "URL must end with 'package.json'" + notify_error(sublime.active_window(), message, message) return try: package = json.loads(urllib.request.urlopen(base_url).read().decode("utf-8")) except Exception as ex: - msg = f'Unable to load "{base_url}": {ex}' - notify_err(sublime.active_window(), msg, msg) + message = f'Unable to load "{base_url}": {ex}' + notify_error(sublime.active_window(), message, message) return # There might be a translations file as well. @@ -156,13 +156,13 @@ def run(self, base_package_name: str) -> None: contributes = package.get("contributes") if not isinstance(contributes, dict): - msg = 'No "contributes" key found!' - notify_err(sublime.active_window(), msg, msg) + message = 'No "contributes" key found!' + notify_error(sublime.active_window(), message, message) return configuration = contributes.get("configuration") if not isinstance(configuration, dict) and not isinstance(configuration, list): - msg = 'No "contributes.configuration" key found!' - notify_err(sublime.active_window(), msg, msg) + message = 'No "contributes.configuration" key found!' + notify_error(sublime.active_window(), message, message) return if isinstance(configuration, dict): properties = configuration.get("properties") @@ -171,8 +171,8 @@ def run(self, base_package_name: str) -> None: for configuration_item in configuration: properties.update(configuration_item.get("properties")) if not isinstance(properties, dict): - msg = 'No "contributes.configuration.properties" key found!' - notify_err(sublime.active_window(), msg, msg) + message = 'No "contributes.configuration.properties" key found!' + notify_error(sublime.active_window(), message, message) return # Process each key-value pair of the server settings. @@ -312,8 +312,8 @@ def run(self) -> None: return view = wm.window.active_view() if not view: - msg = 'Troubleshooting must be run with a file opened' - notify(self.window, msg, msg) + message = 'Troubleshooting must be run with a file opened' + notify(self.window, message, message) return active_view = view configs = wm.get_config_manager().get_configs() @@ -467,9 +467,9 @@ def run(self, edit: sublime.Edit) -> None: return listener = wm.listener_for_view(self.view) if not listener or not any(listener.session_views_async()): - msg = "There is no language server running for this view." + message = "There is no language server running for this view." status = "No language server for this view" - notify_err(wm.window, msg, status) + notify_error(wm.window, message, status) return v = wm.window.new_file() v.set_scratch(True) From 987ce91a35ba70836e22fc0c3780fa7ff21223d3 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 18:53:55 +0700 Subject: [PATCH 14/27] add missing window arg --- plugin/code_actions.py | 4 ++-- plugin/rename.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/code_actions.py b/plugin/code_actions.py index 74e720388..e9f3a19c5 100644 --- a/plugin/code_actions.py +++ b/plugin/code_actions.py @@ -354,7 +354,7 @@ def run_async() -> None: def _handle_response_async(self, session_name: str, response: Any) -> None: if isinstance(response, Error): message = f"{session_name}: {str(response)}" - notify_error(message, message) + notify_error(self.view.window(), message, message) # This command must be a WindowCommand in order to reliably hide corresponding menu entries when no view has focus. @@ -417,7 +417,7 @@ def run_async(self, index: int, event: dict | None) -> None: def _handle_response_async(self, session_name: str, response: Any) -> None: if isinstance(response, Error): message = f"{session_name}: {str(response)}" - notify_error(message, message) + notify_error(self.window, message, message) def _is_cache_valid(self, event: dict | None) -> bool: view = self.view diff --git a/plugin/rename.py b/plugin/rename.py index 715536af8..183a87b2d 100644 --- a/plugin/rename.py +++ b/plugin/rename.py @@ -213,7 +213,7 @@ def _on_rename_result_async(self, session: Session, response: WorkspaceEdit | No def _on_prepare_result(self, pos: int, session_name: str | None, response: PrepareRenameResult | None) -> None: if response is None: message = "The current selection cannot be renamed" - notify_error(message, message) + notify_error(self.view.window(), message, message) return if is_range_response(response): r = range_to_region(response, self.view) @@ -229,7 +229,7 @@ def _on_prepare_result(self, pos: int, session_name: str | None, response: Prepa def _on_prepare_error(self, error: Any) -> None: message = "Rename error: {}".format(error["message"]) - notify_error(message, message) + notify_error(self.view.window(), message, message) def _get_relative_path(self, file_path: str) -> str: wm = windows.lookup(self.view.window()) From 5b9904030fd45a582624fed68ebc56ba97b4df65 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 18:52:25 +0700 Subject: [PATCH 15/27] accept optional sublime Window in notify functions fallback sublime functions --- plugin/core/logging.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/plugin/core/logging.py b/plugin/core/logging.py index 2c0b24d9e..982e59483 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -1,5 +1,5 @@ from __future__ import annotations -from typing import Any +from typing import Any, Optional import traceback import inspect import sublime @@ -41,25 +41,33 @@ def printf(*args: Any, prefix: str = 'LSP') -> None: print(prefix + ":", *args) -def notify(window: sublime.Window, message: str, status: str = 'LSP: see console log…') -> None: - """Pick either of the 2 ways to show a message: - - via a blocking modal dialog - - via a detailed console message and a short status message""" +def notify(window: Optional[sublime.Window], message: str, + status: str = 'LSP: see console log…') -> None: + """Pick either of the 2 ways to show a user notification message: + - via a detailed console message and a short status message + - via a blocking modal dialog""" from .settings import userprefs if userprefs().suppress_error_dialogs: - window.status_message(status) - print(message) + if window: + window.status_message(status) # print short message to statusbar + else: + sublime.status_message(status) + print(message) # print full message to console log else: - window.message_dialog(message) + sublime.message_dialog(message) -def notify_error(window: sublime.Window, message: str, status: str = '❗LSP: see console log…') -> None: - """Pick either of the 2 ways to show a message: - - via a blocking modal dialog - - via a detailed console message and a short status message""" +def notify_error(window: Optional[sublime.Window], message: str, + status: str = '❗LSP: see console log…') -> None: + """Pick either of the 2 ways to show a user error notification message: + - via a detailed console message and a short status message + - via a blocking error modal dialog""" from .settings import userprefs if userprefs().suppress_error_dialogs: - window.status_message(status) - print(message) + if window: + window.status_message(status) # print short message to statusbar + else: + sublime.status_message(status) + print(message) # print full message to console log else: sublime.error_message(message) From 33ab71fbfbe63f40ed453d90cc959225fbc13cfd Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Thu, 7 Nov 2024 19:18:43 +0700 Subject: [PATCH 16/27] fix style --- plugin/core/logging.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugin/core/logging.py b/plugin/core/logging.py index 982e59483..29072b3b3 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -41,33 +41,31 @@ def printf(*args: Any, prefix: str = 'LSP') -> None: print(prefix + ":", *args) -def notify(window: Optional[sublime.Window], message: str, - status: str = 'LSP: see console log…') -> None: +def notify(window: Optional[sublime.Window], message: str, status: str = 'LSP: see console log…') -> None: """Pick either of the 2 ways to show a user notification message: - via a detailed console message and a short status message - via a blocking modal dialog""" from .settings import userprefs if userprefs().suppress_error_dialogs: if window: - window.status_message(status) # print short message to statusbar + window.status_message(status) # print short message to statusbar else: sublime.status_message(status) - print(message) # print full message to console log + print(message) # print full message to console log else: sublime.message_dialog(message) -def notify_error(window: Optional[sublime.Window], message: str, - status: str = '❗LSP: see console log…') -> None: +def notify_error(window: Optional[sublime.Window], message: str, status: str = '❗LSP: see console log…') -> None: """Pick either of the 2 ways to show a user error notification message: - via a detailed console message and a short status message - via a blocking error modal dialog""" from .settings import userprefs if userprefs().suppress_error_dialogs: if window: - window.status_message(status) # print short message to statusbar + window.status_message(status) # print short message to statusbar else: sublime.status_message(status) - print(message) # print full message to console log + print(message) # print full message to console log else: sublime.error_message(message) From 27aa18084b3b96ff2de186492a0404318e4e1564 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 12:52:51 +0700 Subject: [PATCH 17/27] remove comments --- plugin/core/logging.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/core/logging.py b/plugin/core/logging.py index 29072b3b3..ff0687e09 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -48,10 +48,10 @@ def notify(window: Optional[sublime.Window], message: str, status: str = 'LSP: s from .settings import userprefs if userprefs().suppress_error_dialogs: if window: - window.status_message(status) # print short message to statusbar + window.status_message(status) else: sublime.status_message(status) - print(message) # print full message to console log + print(message) else: sublime.message_dialog(message) @@ -63,9 +63,9 @@ def notify_error(window: Optional[sublime.Window], message: str, status: str = ' from .settings import userprefs if userprefs().suppress_error_dialogs: if window: - window.status_message(status) # print short message to statusbar + window.status_message(status) else: sublime.status_message(status) - print(message) # print full message to console log + print(message) else: sublime.error_message(message) From d61affa2538ca03d63cee73775adc09eb194198b Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 12:57:32 +0700 Subject: [PATCH 18/27] update type/var name --- plugin/core/logging.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugin/core/logging.py b/plugin/core/logging.py index ff0687e09..223a1a510 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -41,31 +41,31 @@ def printf(*args: Any, prefix: str = 'LSP') -> None: print(prefix + ":", *args) -def notify(window: Optional[sublime.Window], message: str, status: str = 'LSP: see console log…') -> None: +def notify(window: sublime.Window | None, message: str, status_message: str = 'LSP: see console log…') -> None: """Pick either of the 2 ways to show a user notification message: - via a detailed console message and a short status message - via a blocking modal dialog""" from .settings import userprefs if userprefs().suppress_error_dialogs: if window: - window.status_message(status) + window.status_message(status_message) else: - sublime.status_message(status) + sublime.status_message(status_message) print(message) else: sublime.message_dialog(message) -def notify_error(window: Optional[sublime.Window], message: str, status: str = '❗LSP: see console log…') -> None: +def notify_error(window: sublime.Window | None, message: str, status_message: str = '❗LSP: see console log…') -> None: """Pick either of the 2 ways to show a user error notification message: - via a detailed console message and a short status message - via a blocking error modal dialog""" from .settings import userprefs if userprefs().suppress_error_dialogs: if window: - window.status_message(status) + window.status_message(status_message) else: - sublime.status_message(status) + sublime.status_message(status_message) print(message) else: sublime.error_message(message) From 726a7816595788d5db6869d79b0f386712de684a Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 13:02:32 +0700 Subject: [PATCH 19/27] return if no window --- plugin/core/logging.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugin/core/logging.py b/plugin/core/logging.py index 223a1a510..0fbf7006e 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -46,11 +46,10 @@ def notify(window: sublime.Window | None, message: str, status_message: str = 'L - via a detailed console message and a short status message - via a blocking modal dialog""" from .settings import userprefs + if not window: + return if userprefs().suppress_error_dialogs: - if window: - window.status_message(status_message) - else: - sublime.status_message(status_message) + window.status_message(status_message) print(message) else: sublime.message_dialog(message) @@ -61,11 +60,10 @@ def notify_error(window: sublime.Window | None, message: str, status_message: st - via a detailed console message and a short status message - via a blocking error modal dialog""" from .settings import userprefs + if not window: + return if userprefs().suppress_error_dialogs: - if window: - window.status_message(status_message) - else: - sublime.status_message(status_message) + window.status_message(status_message) print(message) else: sublime.error_message(message) From 8595bf22165a5b887a892363e8cded8383cd9108 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 13:08:12 +0700 Subject: [PATCH 20/27] shorten status message to remove LSP --- plugin/core/windows.py | 2 +- plugin/core/workspace.py | 4 ++-- plugin/execute_command.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/core/windows.py b/plugin/core/windows.py index 6e5cb3d69..d7a8aaf88 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -296,7 +296,7 @@ def start_async(self, config: ClientConfig, initiating_view: sublime.View) -> No "Re-enable by running \"LSP: Enable Language Server In Project\" from the Command Palette.", "\n\n--- Error: ---\n{1}" )).format(config.name, str(e)) - status = f"LSP: Failed to start {config.name}… See console" + status = f"Failed to start {config.name}… See console" exception_log(f"Unable to start subprocess for {config.name}", e) if isinstance(e, CalledProcessError): print("Server output:\n{}".format(e.output.decode('utf-8', 'replace'))) diff --git a/plugin/core/workspace.py b/plugin/core/workspace.py index cc87dd070..b63cdf6b3 100644 --- a/plugin/core/workspace.py +++ b/plugin/core/workspace.py @@ -148,7 +148,7 @@ def enable_in_project(window: sublime.Window, config_name: str) -> None: window.set_project_data(project_data) else: message = f"Can't enable {config_name} in the current workspace. Ensure that the project is saved first." - status = f"LSP: Can't enable {config_name} in this workspace… See console" + status = f"Can't enable {config_name} in this workspace… See console" notify(window, message, status) @@ -162,5 +162,5 @@ def disable_in_project(window: sublime.Window, config_name: str) -> None: window.set_project_data(project_data) else: message = f"Can't disable {config_name} in the current workspace. Ensure that the project is saved first." - status = f"LSP: Can't enable {config_name} in this workspace… See console" + status = f"Can't enable {config_name} in this workspace… See console" notify(window, message, status) diff --git a/plugin/execute_command.py b/plugin/execute_command.py index d89fe4e65..50c456ee8 100644 --- a/plugin/execute_command.py +++ b/plugin/execute_command.py @@ -60,7 +60,7 @@ def handle_error_async(self, error: Error, command_name: str) -> None: :param command_name: The name of the command that was executed. """ message = f"command {command_name} failed. Reason: {str(error)}" - status = f"LSP: {command_name} failed… See console" + status = f"{command_name} failed… See console" notify(self.view.window(), message, status) def _expand_variables(self, command_args: list[Any]) -> list[Any]: From 5ab0e73a8616c43d7b595c6d7578e3faf403dd04 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 13:25:07 +0700 Subject: [PATCH 21/27] moved notification logging functions to a separate file to avoid circular imports --- plugin/code_actions.py | 2 +- plugin/core/logging.py | 30 +----------------------------- plugin/core/logging_notify.py | 29 +++++++++++++++++++++++++++++ plugin/core/windows.py | 2 +- plugin/core/workspace.py | 2 +- plugin/execute_command.py | 2 +- plugin/rename.py | 2 +- plugin/tooling.py | 4 ++-- 8 files changed, 37 insertions(+), 36 deletions(-) create mode 100644 plugin/core/logging_notify.py diff --git a/plugin/code_actions.py b/plugin/code_actions.py index e9f3a19c5..86bd87db4 100644 --- a/plugin/code_actions.py +++ b/plugin/code_actions.py @@ -1,5 +1,5 @@ from __future__ import annotations -from .core.logging import notify_error +from .core.logging_notify import notify_error from .core.promise import Promise from .core.protocol import CodeAction from .core.protocol import CodeActionKind diff --git a/plugin/core/logging.py b/plugin/core/logging.py index 0fbf7006e..ebaeb3629 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -1,5 +1,5 @@ from __future__ import annotations -from typing import Any, Optional +from typing import Any import traceback import inspect import sublime @@ -39,31 +39,3 @@ def exception_log(message: str, ex: Exception) -> None: def printf(*args: Any, prefix: str = 'LSP') -> None: """Print args to the console, prefixed by the plugin name.""" print(prefix + ":", *args) - - -def notify(window: sublime.Window | None, message: str, status_message: str = 'LSP: see console log…') -> None: - """Pick either of the 2 ways to show a user notification message: - - via a detailed console message and a short status message - - via a blocking modal dialog""" - from .settings import userprefs - if not window: - return - if userprefs().suppress_error_dialogs: - window.status_message(status_message) - print(message) - else: - sublime.message_dialog(message) - - -def notify_error(window: sublime.Window | None, message: str, status_message: str = '❗LSP: see console log…') -> None: - """Pick either of the 2 ways to show a user error notification message: - - via a detailed console message and a short status message - - via a blocking error modal dialog""" - from .settings import userprefs - if not window: - return - if userprefs().suppress_error_dialogs: - window.status_message(status_message) - print(message) - else: - sublime.error_message(message) diff --git a/plugin/core/logging_notify.py b/plugin/core/logging_notify.py new file mode 100644 index 000000000..746391814 --- /dev/null +++ b/plugin/core/logging_notify.py @@ -0,0 +1,29 @@ +from __future__ import annotations +import sublime +from .settings import userprefs + + +def notify(window: sublime.Window | None, message: str, status_message: str = 'LSP: see console log…') -> None: + """Pick either of the 2 ways to show a user notification message: + - via a detailed console message and a short status message + - via a blocking modal dialog""" + if not window: + return + if userprefs().suppress_error_dialogs: + window.status_message(status_message) + print(message) + else: + sublime.message_dialog(message) + + +def notify_error(window: sublime.Window | None, message: str, status_message: str = '❗LSP: see console log…') -> None: + """Pick either of the 2 ways to show a user error notification message: + - via a detailed console message and a short status message + - via a blocking error modal dialog""" + if not window: + return + if userprefs().suppress_error_dialogs: + window.status_message(status_message) + print(message) + else: + sublime.error_message(message) diff --git a/plugin/core/windows.py b/plugin/core/windows.py index d7a8aaf88..adb7ff7af 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -7,7 +7,7 @@ from .diagnostics_storage import is_severity_included from .logging import debug from .logging import exception_log -from .logging import notify +from .logging_notify import notify from .message_request_handler import MessageRequestHandler from .panels import LOG_LINES_LIMIT_SETTING_NAME from .panels import MAX_LOG_LINES_LIMIT_OFF diff --git a/plugin/core/workspace.py b/plugin/core/workspace.py index b63cdf6b3..31d7b92c7 100644 --- a/plugin/core/workspace.py +++ b/plugin/core/workspace.py @@ -4,7 +4,7 @@ from .types import matches_pattern from .types import sublime_pattern_to_glob from .url import filename_to_uri -from .logging import notify +from .logging_notify import notify from typing import Any import sublime import os diff --git a/plugin/execute_command.py b/plugin/execute_command.py index 50c456ee8..89cb2393a 100644 --- a/plugin/execute_command.py +++ b/plugin/execute_command.py @@ -1,5 +1,5 @@ from __future__ import annotations -from .core.logging import notify +from .core.logging_notify import notify from .core.protocol import Error from .core.protocol import ExecuteCommandParams from .core.registry import LspTextCommand diff --git a/plugin/rename.py b/plugin/rename.py index 183a87b2d..7bc16bd76 100644 --- a/plugin/rename.py +++ b/plugin/rename.py @@ -2,7 +2,7 @@ from .core.edit import parse_range from .core.edit import parse_workspace_edit from .core.edit import WorkspaceChanges -from .core.logging import notify_error +from .core.logging_notify import notify_error from .core.protocol import PrepareRenameParams from .core.protocol import PrepareRenameResult from .core.protocol import Range diff --git a/plugin/tooling.py b/plugin/tooling.py index aa1a982fd..617ff7317 100644 --- a/plugin/tooling.py +++ b/plugin/tooling.py @@ -1,8 +1,8 @@ from __future__ import annotations from .core.css import css from .core.logging import debug -from .core.logging import notify -from .core.logging import notify_error +from .core.logging_notify import notify +from .core.logging_notify import notify_error from .core.registry import windows from .core.sessions import get_plugin from .core.transports import create_transport From 546a8df5abfebcf67b37c5c83ee0c8773bc4e8e0 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 13:28:37 +0700 Subject: [PATCH 22/27] consolidate error notification into 1 function with an extra severe argument to downgrade to a non-error modal dialog if needed --- plugin/core/logging_notify.py | 24 +++++++----------------- plugin/core/windows.py | 4 ++-- plugin/core/workspace.py | 6 +++--- plugin/execute_command.py | 4 ++-- plugin/tooling.py | 3 +-- 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/plugin/core/logging_notify.py b/plugin/core/logging_notify.py index 746391814..0aa29f1e4 100644 --- a/plugin/core/logging_notify.py +++ b/plugin/core/logging_notify.py @@ -2,28 +2,18 @@ import sublime from .settings import userprefs - -def notify(window: sublime.Window | None, message: str, status_message: str = 'LSP: see console log…') -> None: - """Pick either of the 2 ways to show a user notification message: - - via a detailed console message and a short status message - - via a blocking modal dialog""" - if not window: - return - if userprefs().suppress_error_dialogs: - window.status_message(status_message) - print(message) - else: - sublime.message_dialog(message) - - -def notify_error(window: sublime.Window | None, message: str, status_message: str = '❗LSP: see console log…') -> None: +def notify_error(window: sublime.Window | None, message: str, status_message: str = 'LSP: see console log…', + severe: bool = True) -> None: """Pick either of the 2 ways to show a user error notification message: - via a detailed console message and a short status message - - via a blocking error modal dialog""" + - via a blocking error modal dialog (with severe=false non-error modal dialog)""" if not window: return if userprefs().suppress_error_dialogs: window.status_message(status_message) print(message) else: - sublime.error_message(message) + if severe: + sublime.error_message(message) + else: + sublime.message_dialog(message) diff --git a/plugin/core/windows.py b/plugin/core/windows.py index adb7ff7af..60c13444a 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -7,7 +7,7 @@ from .diagnostics_storage import is_severity_included from .logging import debug from .logging import exception_log -from .logging_notify import notify +from .logging_notify import notify_error from .message_request_handler import MessageRequestHandler from .panels import LOG_LINES_LIMIT_SETTING_NAME from .panels import MAX_LOG_LINES_LIMIT_OFF @@ -302,7 +302,7 @@ def start_async(self, config: ClientConfig, initiating_view: sublime.View) -> No print("Server output:\n{}".format(e.output.decode('utf-8', 'replace'))) self._config_manager.disable_config(config.name, only_for_session=True) config.erase_view_status(initiating_view) - notify(self._window, message, status) + notify_error(self._window, message, status) # Continue with handling pending listeners self._new_session = None sublime.set_timeout_async(self._dequeue_listener_async) diff --git a/plugin/core/workspace.py b/plugin/core/workspace.py index 31d7b92c7..8ca1ea865 100644 --- a/plugin/core/workspace.py +++ b/plugin/core/workspace.py @@ -4,7 +4,7 @@ from .types import matches_pattern from .types import sublime_pattern_to_glob from .url import filename_to_uri -from .logging_notify import notify +from .logging_notify import notify_error from typing import Any import sublime import os @@ -149,7 +149,7 @@ def enable_in_project(window: sublime.Window, config_name: str) -> None: else: message = f"Can't enable {config_name} in the current workspace. Ensure that the project is saved first." status = f"Can't enable {config_name} in this workspace… See console" - notify(window, message, status) + notify_error(window, message, status) def disable_in_project(window: sublime.Window, config_name: str) -> None: @@ -163,4 +163,4 @@ def disable_in_project(window: sublime.Window, config_name: str) -> None: else: message = f"Can't disable {config_name} in the current workspace. Ensure that the project is saved first." status = f"Can't enable {config_name} in this workspace… See console" - notify(window, message, status) + notify_error(window, message, status) diff --git a/plugin/execute_command.py b/plugin/execute_command.py index 89cb2393a..d8dbbca8b 100644 --- a/plugin/execute_command.py +++ b/plugin/execute_command.py @@ -1,5 +1,5 @@ from __future__ import annotations -from .core.logging_notify import notify +from .core.logging_notify import notify_error from .core.protocol import Error from .core.protocol import ExecuteCommandParams from .core.registry import LspTextCommand @@ -61,7 +61,7 @@ def handle_error_async(self, error: Error, command_name: str) -> None: """ message = f"command {command_name} failed. Reason: {str(error)}" status = f"{command_name} failed… See console" - notify(self.view.window(), message, status) + notify_error(self.view.window(), message, status) def _expand_variables(self, command_args: list[Any]) -> list[Any]: view = self.view diff --git a/plugin/tooling.py b/plugin/tooling.py index 617ff7317..e6427f47e 100644 --- a/plugin/tooling.py +++ b/plugin/tooling.py @@ -1,7 +1,6 @@ from __future__ import annotations from .core.css import css from .core.logging import debug -from .core.logging_notify import notify from .core.logging_notify import notify_error from .core.registry import windows from .core.sessions import get_plugin @@ -313,7 +312,7 @@ def run(self) -> None: view = wm.window.active_view() if not view: message = 'Troubleshooting must be run with a file opened' - notify(self.window, message, message) + notify_error(self.window, message, message) return active_view = view configs = wm.get_config_manager().get_configs() From 6bdb715297b45bd02dee9e3dbaf17149cc014d06 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 13:41:48 +0700 Subject: [PATCH 23/27] fix flake8 style --- plugin/core/logging_notify.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/core/logging_notify.py b/plugin/core/logging_notify.py index 0aa29f1e4..6466f4ca7 100644 --- a/plugin/core/logging_notify.py +++ b/plugin/core/logging_notify.py @@ -2,6 +2,7 @@ import sublime from .settings import userprefs + def notify_error(window: sublime.Window | None, message: str, status_message: str = 'LSP: see console log…', severe: bool = True) -> None: """Pick either of the 2 ways to show a user error notification message: From 76a222ed9ebd8bcbb387dd75d2de2f9418408ab9 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 15:26:52 +0700 Subject: [PATCH 24/27] add LSP prefix to console log messages --- plugin/core/logging_notify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/core/logging_notify.py b/plugin/core/logging_notify.py index 6466f4ca7..8075ddf8d 100644 --- a/plugin/core/logging_notify.py +++ b/plugin/core/logging_notify.py @@ -12,7 +12,7 @@ def notify_error(window: sublime.Window | None, message: str, status_message: st return if userprefs().suppress_error_dialogs: window.status_message(status_message) - print(message) + print("LSP: " + message) else: if severe: sublime.error_message(message) From 52d5ee72196422cbe103d0a35043d1a1ddd90d1d Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 15:30:41 +0700 Subject: [PATCH 25/27] make status message optional --- plugin/code_actions.py | 4 ++-- plugin/core/logging_notify.py | 4 +++- plugin/rename.py | 4 ++-- plugin/tooling.py | 12 ++++++------ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/plugin/code_actions.py b/plugin/code_actions.py index 86bd87db4..9c0eaed4f 100644 --- a/plugin/code_actions.py +++ b/plugin/code_actions.py @@ -354,7 +354,7 @@ def run_async() -> None: def _handle_response_async(self, session_name: str, response: Any) -> None: if isinstance(response, Error): message = f"{session_name}: {str(response)}" - notify_error(self.view.window(), message, message) + notify_error(self.view.window(), message) # This command must be a WindowCommand in order to reliably hide corresponding menu entries when no view has focus. @@ -417,7 +417,7 @@ def run_async(self, index: int, event: dict | None) -> None: def _handle_response_async(self, session_name: str, response: Any) -> None: if isinstance(response, Error): message = f"{session_name}: {str(response)}" - notify_error(self.window, message, message) + notify_error(self.window, message) def _is_cache_valid(self, event: dict | None) -> bool: view = self.view diff --git a/plugin/core/logging_notify.py b/plugin/core/logging_notify.py index 8075ddf8d..4a2084126 100644 --- a/plugin/core/logging_notify.py +++ b/plugin/core/logging_notify.py @@ -3,13 +3,15 @@ from .settings import userprefs -def notify_error(window: sublime.Window | None, message: str, status_message: str = 'LSP: see console log…', +def notify_error(window: sublime.Window | None, message: str, status_message: str | None = None, severe: bool = True) -> None: """Pick either of the 2 ways to show a user error notification message: - via a detailed console message and a short status message - via a blocking error modal dialog (with severe=false non-error modal dialog)""" if not window: return + if status_message is None: + status_message = message if userprefs().suppress_error_dialogs: window.status_message(status_message) print("LSP: " + message) diff --git a/plugin/rename.py b/plugin/rename.py index 7bc16bd76..8d784dba3 100644 --- a/plugin/rename.py +++ b/plugin/rename.py @@ -213,7 +213,7 @@ def _on_rename_result_async(self, session: Session, response: WorkspaceEdit | No def _on_prepare_result(self, pos: int, session_name: str | None, response: PrepareRenameResult | None) -> None: if response is None: message = "The current selection cannot be renamed" - notify_error(self.view.window(), message, message) + notify_error(self.view.window(), message) return if is_range_response(response): r = range_to_region(response, self.view) @@ -229,7 +229,7 @@ def _on_prepare_result(self, pos: int, session_name: str | None, response: Prepa def _on_prepare_error(self, error: Any) -> None: message = "Rename error: {}".format(error["message"]) - notify_error(self.view.window(), message, message) + notify_error(self.view.window(), message) def _get_relative_path(self, file_path: str) -> str: wm = windows.lookup(self.view.window()) diff --git a/plugin/tooling.py b/plugin/tooling.py index e6427f47e..df5e77b9c 100644 --- a/plugin/tooling.py +++ b/plugin/tooling.py @@ -137,13 +137,13 @@ def run(self, base_package_name: str) -> None: return if not base_url.endswith("package.json"): message = "URL must end with 'package.json'" - notify_error(sublime.active_window(), message, message) + notify_error(sublime.active_window(), message) return try: package = json.loads(urllib.request.urlopen(base_url).read().decode("utf-8")) except Exception as ex: message = f'Unable to load "{base_url}": {ex}' - notify_error(sublime.active_window(), message, message) + notify_error(sublime.active_window(), message) return # There might be a translations file as well. @@ -156,12 +156,12 @@ def run(self, base_package_name: str) -> None: contributes = package.get("contributes") if not isinstance(contributes, dict): message = 'No "contributes" key found!' - notify_error(sublime.active_window(), message, message) + notify_error(sublime.active_window(), message) return configuration = contributes.get("configuration") if not isinstance(configuration, dict) and not isinstance(configuration, list): message = 'No "contributes.configuration" key found!' - notify_error(sublime.active_window(), message, message) + notify_error(sublime.active_window(), message) return if isinstance(configuration, dict): properties = configuration.get("properties") @@ -171,7 +171,7 @@ def run(self, base_package_name: str) -> None: properties.update(configuration_item.get("properties")) if not isinstance(properties, dict): message = 'No "contributes.configuration.properties" key found!' - notify_error(sublime.active_window(), message, message) + notify_error(sublime.active_window(), message) return # Process each key-value pair of the server settings. @@ -312,7 +312,7 @@ def run(self) -> None: view = wm.window.active_view() if not view: message = 'Troubleshooting must be run with a file opened' - notify_error(self.window, message, message) + notify_error(self.window, message) return active_view = view configs = wm.get_config_manager().get_configs() From 89c4bd9542f29ea58c442506353e95d22b66dc0c Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 15:40:21 +0700 Subject: [PATCH 26/27] remove severity level from log messages --- plugin/core/logging_notify.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/plugin/core/logging_notify.py b/plugin/core/logging_notify.py index 4a2084126..09d26f0b3 100644 --- a/plugin/core/logging_notify.py +++ b/plugin/core/logging_notify.py @@ -3,11 +3,10 @@ from .settings import userprefs -def notify_error(window: sublime.Window | None, message: str, status_message: str | None = None, - severe: bool = True) -> None: +def notify_error(window: sublime.Window | None, message: str, status_message: str | None = None) -> None: """Pick either of the 2 ways to show a user error notification message: - via a detailed console message and a short status message - - via a blocking error modal dialog (with severe=false non-error modal dialog)""" + - via a blocking error modal dialog""" if not window: return if status_message is None: @@ -16,7 +15,4 @@ def notify_error(window: sublime.Window | None, message: str, status_message: st window.status_message(status_message) print("LSP: " + message) else: - if severe: - sublime.error_message(message) - else: - sublime.message_dialog(message) + sublime.error_message(message) From ac0c301db0eb4d5f20948588d728cc25c8d2ef10 Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 16:16:55 +0700 Subject: [PATCH 27/27] update default config --- LSP.sublime-settings | 4 ++-- sublime-package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LSP.sublime-settings b/LSP.sublime-settings index b4ba10752..66e72025b 100644 --- a/LSP.sublime-settings +++ b/LSP.sublime-settings @@ -163,8 +163,8 @@ // --- Other -------------------------------------------------------------------------- - // Replace UI blocking modals with the full console message and a short status notification - "suppress_error_dialogs": true, + // Replace error popup windows with a console message and a short status notification. + "suppress_error_dialogs": false, // Show symbol references in Sublime's quick panel instead of the output panel. "show_references_in_quick_panel": true, diff --git a/sublime-package.json b/sublime-package.json index e04e0fc66..21b7205da 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -452,7 +452,7 @@ "suppress_error_dialogs": { "type": "boolean", "default": false, - "markdownDescription": "Show UI blocking error modals or the full console message and short status notification." + "markdownDescription": "Replace error popup windows with a console message and a short status notification." }, "lsp_format_on_paste": { "$ref": "sublime://settings/LSP#/definitions/lsp_format_on_paste"