Skip to content

Commit

Permalink
Use caret for point to look up symbol (#2440)
Browse files Browse the repository at this point in the history
* 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.

* Simplify

---------

Co-authored-by: Janos Wortmann <[email protected]>
Co-authored-by: Предраг Николић <[email protected]>
  • Loading branch information
3 people authored May 3, 2024
1 parent d5c350a commit cdb2430
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion plugin/core/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_position(view: sublime.View, event: dict | None = None, point: int | Non
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

Expand Down
11 changes: 3 additions & 8 deletions plugin/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
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
from .core.sessions import SessionBufferProtocol
from .core.settings import userprefs
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
Expand Down Expand Up @@ -115,17 +115,12 @@ def run(
point: int | None = None,
event: dict | None = None
) -> None:
temp_point = point
if temp_point is None:
region = first_selection_region(self.view)
if region is not None:
temp_point = region.begin()
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: list[tuple[Hover, MarkdownLangMap | None]] = []
self._document_links: list[DocumentLink] = []
Expand Down

0 comments on commit cdb2430

Please sign in to comment.