From e017330ac2c461c277d48339902e2916b4b3d9f9 Mon Sep 17 00:00:00 2001 From: HJX-001 <116998733+HJX-001@users.noreply.github.com> Date: Fri, 31 May 2024 19:06:36 +0530 Subject: [PATCH 1/3] feat: add option to disable/enable diagnostics in hover --- LSP.sublime-settings | 3 +++ plugin/core/types.py | 2 ++ plugin/hover.py | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/LSP.sublime-settings b/LSP.sublime-settings index 1489931cf..0bf0e6902 100644 --- a/LSP.sublime-settings +++ b/LSP.sublime-settings @@ -136,6 +136,9 @@ // The maximum number of characters (approximately) before a scrollbar appears. "popup_max_characters_height": 1000, + // Show diagnostics in hover popup if available + "show_diagnostics_in_hover": true, + // Show code actions in hover popup if available "show_code_actions_in_hover": true, diff --git a/plugin/core/types.py b/plugin/core/types.py index 901d3c565..46d7efa7b 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -227,6 +227,7 @@ class Settings: show_code_actions = cast(str, None) show_code_lens = cast(str, None) show_inlay_hints = cast(bool, None) + show_diagnostics_in_hover = cast(bool, None) 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) @@ -271,6 +272,7 @@ def r(name: str, default: bool | int | str | list | dict) -> None: r("show_code_actions", "annotation") r("show_code_lens", "annotation") r("show_inlay_hints", False) + r("show_diagnostics_in_hover", True) r("show_code_actions_in_hover", True) r("show_diagnostics_annotations_severity_level", 0) r("show_diagnostics_count_in_view_status", False) diff --git a/plugin/hover.py b/plugin/hover.py index b3d9ddae4..c9584d4a0 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -278,10 +278,11 @@ def show_hover(self, listener: AbstractViewListener, point: int, only_diagnostic def _show_hover(self, listener: AbstractViewListener, point: int, only_diagnostics: bool) -> None: hover_content = self.hover_content() - contents = self.diagnostics_content() + hover_content + code_actions_content(self._actions_by_config) + prefs = userprefs() + diagnostics_content = "" if not prefs.show_diagnostics_in_hover else self.diagnostics_content() + contents = diagnostics_content + hover_content + code_actions_content(self._actions_by_config) link_content, link_range = self.link_content_and_range() only_link_content = not bool(contents) and link_range is not None - prefs = userprefs() if prefs.show_symbol_action_links and contents and not only_diagnostics and hover_content: symbol_actions_content = self.symbol_actions_content(listener, point) if link_content: From c37b8c5765ab753cde80f80fec5721a4f3601d64 Mon Sep 17 00:00:00 2001 From: HJX-001 <116998733+HJX-001@users.noreply.github.com> Date: Sat, 1 Jun 2024 00:23:18 +0530 Subject: [PATCH 2/3] fix: fix lsp next/prev diagnostics command was not working after addition of setting 'show diagnostics in hover' --- plugin/hover.py | 4 +++- sublime-package.json | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plugin/hover.py b/plugin/hover.py index c9584d4a0..e62096c54 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -279,7 +279,9 @@ def show_hover(self, listener: AbstractViewListener, point: int, only_diagnostic def _show_hover(self, listener: AbstractViewListener, point: int, only_diagnostics: bool) -> None: hover_content = self.hover_content() prefs = userprefs() - diagnostics_content = "" if not prefs.show_diagnostics_in_hover else self.diagnostics_content() + diagnostics_content = "" + if only_diagnostics or prefs.show_diagnostics_in_hover: + diagnostics_content = self.diagnostics_content() contents = diagnostics_content + hover_content + code_actions_content(self._actions_by_config) link_content, link_range = self.link_content_and_range() only_link_content = not bool(contents) and link_range is not None diff --git a/sublime-package.json b/sublime-package.json index 81c687770..023541fe8 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -621,6 +621,11 @@ "default": "annotation", "markdownDescription": "Where to show `\"code lens\"`." }, + "show_diagnostics_in_hover": { + "type": "boolean", + "default": true, + "markdownDescription": "Show diagnostics in hover popup if available." + }, "show_code_actions_in_hover": { "type": "boolean", "default": true, From 130e40677d82d7afc55e96f4724173473a585bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ch=C5=82odnicki?= Date: Mon, 3 Jun 2024 11:39:14 +0200 Subject: [PATCH 3/3] Update plugin/hover.py --- plugin/hover.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugin/hover.py b/plugin/hover.py index e62096c54..260347192 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -279,9 +279,7 @@ def show_hover(self, listener: AbstractViewListener, point: int, only_diagnostic def _show_hover(self, listener: AbstractViewListener, point: int, only_diagnostics: bool) -> None: hover_content = self.hover_content() prefs = userprefs() - diagnostics_content = "" - if only_diagnostics or prefs.show_diagnostics_in_hover: - diagnostics_content = self.diagnostics_content() + diagnostics_content = self.diagnostics_content() if only_diagnostics or prefs.show_diagnostics_in_hover else "" contents = diagnostics_content + hover_content + code_actions_content(self._actions_by_config) link_content, link_range = self.link_content_and_range() only_link_content = not bool(contents) and link_range is not None