From 3422d5021baae1e59eb89cf5ea0c49c2bb07afd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Troels=20Bj=C3=B8rnskov?= Date: Thu, 4 Apr 2024 08:55:08 +0200 Subject: [PATCH 1/2] Use caret for point to look up symbol This commit changes the hover functionality such that the caret, not the beginning of the selection, is used for the symbol lookup. --- plugin/core/registry.py | 2 +- plugin/hover.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/core/registry.py b/plugin/core/registry.py index c1708f3d9..869fa7d62 100644 --- a/plugin/core/registry.py +++ b/plugin/core/registry.py @@ -40,7 +40,7 @@ def get_position(view: sublime.View, event: Optional[dict] = None, point: Option if x is not None and y is not None: return view.window_to_text((x, y)) try: - return view.sel()[0].begin() + return view.sel()[0].b except IndexError: return None diff --git a/plugin/hover.py b/plugin/hover.py index cde9540c6..54ccd0556 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -118,7 +118,7 @@ def run( if temp_point is None: region = first_selection_region(self.view) if region is not None: - temp_point = region.begin() + temp_point = region.b if temp_point is None: return wm = windows.lookup(self.view.window()) From cc26b876229f3f4c435e6693d7da64a8bb435b38 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Mon, 22 Apr 2024 22:22:23 +0200 Subject: [PATCH 2/2] Simplify --- plugin/hover.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/plugin/hover.py b/plugin/hover.py index 54ccd0556..a7943d836 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -15,6 +15,7 @@ from .core.protocol import Position from .core.protocol import Range from .core.protocol import Request +from .core.registry import get_position from .core.registry import LspTextCommand from .core.registry import windows from .core.sessions import AbstractViewListener @@ -23,7 +24,6 @@ from .core.typing import List, Optional, Dict, Tuple, Sequence, Union from .core.url import parse_uri from .core.views import diagnostic_severity -from .core.views import first_selection_region from .core.views import format_code_actions_for_quick_panel from .core.views import format_diagnostic_for_html from .core.views import FORMAT_MARKED_STRING @@ -114,17 +114,12 @@ def run( point: Optional[int] = None, event: Optional[dict] = None ) -> None: - temp_point = point - if temp_point is None: - region = first_selection_region(self.view) - if region is not None: - temp_point = region.b - if temp_point is None: + hover_point = get_position(self.view, event, point) + if hover_point is None: return wm = windows.lookup(self.view.window()) if not wm: return - hover_point = temp_point self._base_dir = wm.get_project_path(self.view.file_name() or "") self._hover_responses = [] # type: List[Tuple[Hover, Optional[MarkdownLangMap]]] self._document_links = [] # type: List[DocumentLink]