From 14ad348b9130429e7c95e29a9f93fc31ea91f482 Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Thu, 27 May 2021 22:31:23 +0200 Subject: [PATCH 1/2] Allow adjustable extents of the popups Fixes #1635. Fixes #1657. --- LSP.sublime-settings | 6 ++++++ plugin/core/types.py | 9 ++++++--- plugin/core/views.py | 9 +++++++-- sublime-package.json | 12 ++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/LSP.sublime-settings b/LSP.sublime-settings index 631e6b836..dcdf12c65 100644 --- a/LSP.sublime-settings +++ b/LSP.sublime-settings @@ -110,6 +110,12 @@ // Show symbol references in Sublime's quick panel instead of the bottom panel. "show_references_in_quick_panel": false, + // The maximum number of characters (approximately) before wrapping in the popup. + "popup_max_characters_width": 120, + + // The maximum number of characters (approximately) before a scrollbar appears. + "popup_max_characters_height": 1000, + // Show verbose debug messages in the sublime console. "log_debug": false, diff --git a/plugin/core/types.py b/plugin/core/types.py index 6b79221e1..8722fcb52 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -147,7 +147,6 @@ def read_list_setting(settings_obj: sublime.Settings, key: str, default: list) - class Settings: # This is only for mypy - show_diagnostics_panel_on_save = None # type: int code_action_on_save_timeout_ms = None # type: int diagnostics_additional_delay_auto_complete_ms = None # type: int diagnostics_delay_ms = None # type: int @@ -164,9 +163,12 @@ class Settings: lsp_code_actions_on_save = None # type: Dict[str, bool] lsp_format_on_save = None # type: bool only_show_lsp_completions = None # type: bool + popup_max_characters_height = None # type: int + popup_max_characters_width = None # type: int show_code_actions = None # type: bool show_diagnostics_count_in_view_status = None # type: bool show_diagnostics_in_view_status = None # type: bool + show_diagnostics_panel_on_save = None # type: int show_diagnostics_severity_level = None # type: int show_references_in_quick_panel = None # type: bool show_symbol_action_links = None # type: bool @@ -181,7 +183,6 @@ def r(name: str, default: Union[bool, int, str, list, dict]) -> None: val = s.get(name) setattr(self, name, val if isinstance(val, default.__class__) else default) - r("show_diagnostics_panel_on_save", 2) r("code_action_on_save_timeout_ms", 2000) r("diagnostics_additional_delay_auto_complete_ms", 0) r("diagnostics_delay_ms", 0) @@ -192,13 +193,15 @@ def r(name: str, default: Union[bool, int, str, list, dict]) -> None: r("document_highlight_style", "stippled") r("log_debug", False) r("log_max_size", 8 * 1024) - # r("log_server", []) r("lsp_code_actions_on_save", {}) r("lsp_format_on_save", False) r("only_show_lsp_completions", False) + r("popup_max_characters_height", 1000) + r("popup_max_characters_width", 120) r("show_code_actions", "annotation") r("show_diagnostics_count_in_view_status", False) r("show_diagnostics_in_view_status", True) + r("show_diagnostics_panel_on_save", 2) r("show_diagnostics_severity_level", 2) r("show_references_in_quick_panel", False) r("show_symbol_action_links", False) diff --git a/plugin/core/views.py b/plugin/core/views.py index ab86afffa..9beb34d51 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -10,6 +10,7 @@ from .protocol import Point from .protocol import Range from .protocol import Request +from .settings import userprefs from .typing import Callable, Optional, Dict, Any, Iterable, List, Union, Tuple, Sequence, cast from .url import filename_to_uri from .url import uri_to_filename @@ -365,6 +366,10 @@ def text_document_code_action_params( LSP_POPUP_SPACER_HTML = '
' +def _chars_to_pixels(view: sublime.View, characters: int) -> int: + return int(view.em_width() * float(characters)) + + def show_lsp_popup(view: sublime.View, contents: str, location: int = -1, md: bool = False, flags: int = 0, css: Optional[str] = None, wrapper_class: Optional[str] = None, on_navigate: Optional[Callable] = None, on_hide: Optional[Callable] = None) -> None: @@ -379,8 +384,8 @@ def show_lsp_popup(view: sublime.View, contents: str, location: int = -1, md: bo flags=flags, location=location, wrapper_class=wrapper_class, - max_width=int(view.em_width() * 120.0), # Around 120 characters per line - max_height=1000000, + max_width=_chars_to_pixels(view, userprefs().popup_max_characters_width), + max_height=_chars_to_pixels(view, userprefs().popup_max_characters_height), on_navigate=on_navigate) diff --git a/sublime-package.json b/sublime-package.json index 8eac7f569..d16cfa9ab 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -304,6 +304,18 @@ "default": false, "markdownDescription": "Show symbol references in Sublime's quick panel instead of the bottom panel." }, + "popup_max_characters_width": { + "type": "integer", + "default": 120, + "minimum": 10, + "description": "The maximum number of characters (approximately) before wrapping in the popup." + }, + "popup_max_characters_height": { + "type": "integer", + "default": 1000, + "minimum": 10, + "description": "The maximum number of characters (approximately) before a scrollbar appears." + }, "disabled_capabilities": { "type": "array", "uniqueItems": true, From 3b25f67aed097bfa0593deccbdacb7122f99fdab Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Thu, 27 May 2021 22:54:11 +0200 Subject: [PATCH 2/2] use view.line_height() for the height --- plugin/core/views.py | 8 ++------ sublime-package.json | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/plugin/core/views.py b/plugin/core/views.py index 9beb34d51..0f2088b37 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -366,10 +366,6 @@ def text_document_code_action_params( LSP_POPUP_SPACER_HTML = '
' -def _chars_to_pixels(view: sublime.View, characters: int) -> int: - return int(view.em_width() * float(characters)) - - def show_lsp_popup(view: sublime.View, contents: str, location: int = -1, md: bool = False, flags: int = 0, css: Optional[str] = None, wrapper_class: Optional[str] = None, on_navigate: Optional[Callable] = None, on_hide: Optional[Callable] = None) -> None: @@ -384,8 +380,8 @@ def show_lsp_popup(view: sublime.View, contents: str, location: int = -1, md: bo flags=flags, location=location, wrapper_class=wrapper_class, - max_width=_chars_to_pixels(view, userprefs().popup_max_characters_width), - max_height=_chars_to_pixels(view, userprefs().popup_max_characters_height), + max_width=int(view.em_width() * float(userprefs().popup_max_characters_width)), + max_height=int(view.line_height() * float(userprefs().popup_max_characters_height)), on_navigate=on_navigate) diff --git a/sublime-package.json b/sublime-package.json index d16cfa9ab..11e17da5b 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -307,13 +307,13 @@ "popup_max_characters_width": { "type": "integer", "default": 120, - "minimum": 10, + "minimum": 1, "description": "The maximum number of characters (approximately) before wrapping in the popup." }, "popup_max_characters_height": { "type": "integer", "default": 1000, - "minimum": 10, + "minimum": 1, "description": "The maximum number of characters (approximately) before a scrollbar appears." }, "disabled_capabilities": {