Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support "force_group" and "group" arguments in "lsp_symbol_references" #2186

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@
{
"keys": ["shift+f12"],
"command": "lsp_symbol_references",
"args": {"side_by_side": false, "fallback": false},
"args": {"side_by_side": false, "force_group": true, "fallback": false, "group": -1},
"context": [{"key": "lsp.session_with_capability", "operand": "referencesProvider"}]
},
// Find References (side-by-side)
// {
// "keys": ["primary+shift+f12"],
// "command": "lsp_symbol_references",
// "args": {"side_by_side": true, "fallback": false},
// "args": {"side_by_side": true, "force_group": true, "fallback": false, "group": -1},
// "context": [{"key": "lsp.session_with_capability", "operand": "referencesProvider"}]
// },
// Goto Definition
Expand Down
30 changes: 26 additions & 4 deletions plugin/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def is_enabled(
event: Optional[dict] = None,
point: Optional[int] = None,
side_by_side: bool = False,
force_group: bool = True,
fallback: bool = False,
group: int = -1
) -> bool:
return fallback or super().is_enabled(event, point)

Expand All @@ -37,7 +39,9 @@ def is_visible(
event: Optional[dict] = None,
point: Optional[int] = None,
side_by_side: bool = False,
force_group: bool = True,
fallback: bool = False,
group: int = -1
) -> bool:
if self.applies_to_context_menu(event):
return self.is_enabled(event, point, side_by_side, fallback)
Expand All @@ -49,7 +53,9 @@ def run(
event: Optional[dict] = None,
point: Optional[int] = None,
side_by_side: bool = False,
force_group: bool = True,
fallback: bool = False,
group: int = -1
) -> None:
session = self.best_session(self.capability)
file_path = self.view.file_name()
Expand All @@ -70,7 +76,9 @@ def run(
self.view.substr(word_range),
session,
side_by_side,
force_group,
fallback,
group,
word_range.begin()
)
)
Expand All @@ -82,24 +90,30 @@ def _handle_response_async(
word: str,
session: Session,
side_by_side: bool,
force_group: bool,
fallback: bool,
group: int,
position: int,
response: Optional[List[Location]]
) -> None:
sublime.set_timeout(lambda: self._handle_response(word, session, side_by_side, fallback, position, response))
sublime.set_timeout(lambda: self._handle_response(
word, session, side_by_side, force_group, fallback, group, position, response))

def _handle_response(
self,
word: str,
session: Session,
side_by_side: bool,
force_group: bool,
fallback: bool,
group: int,
position: int,
response: Optional[List[Location]]
) -> None:
if response:
if userprefs().show_references_in_quick_panel:
self._show_references_in_quick_panel(word, session, response, side_by_side, position)
self._show_references_in_quick_panel(
word, session, response, side_by_side, force_group, group, position)
else:
self._show_references_in_output_panel(word, session, response)
else:
Expand All @@ -115,11 +129,19 @@ def _handle_no_results(self, fallback: bool = False, side_by_side: bool = False)
window.status_message("No references found")

def _show_references_in_quick_panel(
self, word: str, session: Session, locations: List[Location], side_by_side: bool, position: int
self,
word: str,
session: Session,
locations: List[Location],
side_by_side: bool,
force_group: bool,
group: int,
position: int
) -> None:
self.view.run_command("add_jump_record", {"selection": [(r.a, r.b) for r in self.view.sel()]})
placeholder = "References to " + word
kind = get_symbol_kind_from_scope(self.view.scope_name(position))
LocationPicker(self.view, session, locations, side_by_side, placeholder="References to " + word, kind=kind)
LocationPicker(self.view, session, locations, side_by_side, force_group, group, placeholder, kind)

def _show_references_in_output_panel(self, word: str, session: Session, locations: List[Location]) -> None:
wm = windows.lookup(session.window)
Expand Down