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 side_by_side for "Go to reference" #1984

Merged
merged 1 commit into from
Jul 3, 2022
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
3 changes: 3 additions & 0 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@
// Find References
{
"command": "lsp_symbol_references",
"args": {
"side_by_side": false
},
"keys": [
"shift+f12"
],
Expand Down
23 changes: 15 additions & 8 deletions plugin/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class LspSymbolReferencesCommand(LspTextCommand):

capability = 'referencesProvider'

def run(self, _: sublime.Edit, event: Optional[dict] = None, point: Optional[int] = None) -> None:
def run(
self, _: sublime.Edit, event: Optional[dict] = None, point: Optional[int] = None, side_by_side: bool = False
) -> None:
session = self.best_session(self.capability)
file_path = self.view.file_name()
pos = get_position(self.view, event, point)
Expand All @@ -47,27 +49,32 @@ def run(self, _: sublime.Edit, event: Optional[dict] = None, point: Optional[int
functools.partial(
self._handle_response_async,
self.view.substr(self.view.word(pos)),
session
session,
side_by_side
)
)

def _handle_response_async(self, word: str, session: Session, response: Optional[List[Location]]) -> None:
sublime.set_timeout(lambda: self._handle_response(word, session, response))
def _handle_response_async(
self, word: str, session: Session, side_by_side: bool, response: Optional[List[Location]]
) -> None:
sublime.set_timeout(lambda: self._handle_response(word, session, side_by_side, response))

def _handle_response(self, word: str, session: Session, response: Optional[List[Location]]) -> None:
def _handle_response(
self, word: str, session: Session, side_by_side: bool, response: Optional[List[Location]]
) -> None:
if response:
if userprefs().show_references_in_quick_panel:
self._show_references_in_quick_panel(session, response)
self._show_references_in_quick_panel(session, response, side_by_side)
else:
self._show_references_in_output_panel(word, session, response)
else:
window = self.view.window()
if window:
window.status_message("No references found")

def _show_references_in_quick_panel(self, session: Session, locations: List[Location]) -> None:
def _show_references_in_quick_panel(self, session: Session, locations: List[Location], side_by_side: bool) -> None:
self.view.run_command("add_jump_record", {"selection": [(r.a, r.b) for r in self.view.sel()]})
LocationPicker(self.view, session, locations, side_by_side=False)
LocationPicker(self.view, session, locations, side_by_side)

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