From 17626d5e26373c409e3649b92048d51e429b8878 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sun, 28 Jan 2024 23:23:07 +0100 Subject: [PATCH] add commands for opening "find references" in bottom or quick panel --- Context.sublime-menu | 14 ++++++++++++++ Default.sublime-commands | 14 ++++++++++++++ Main.sublime-menu | 26 ++++++++++++++++++-------- docs/src/keyboard_shortcuts.md | 2 +- plugin/references.py | 30 +++++++++++++++++++++++------- 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/Context.sublime-menu b/Context.sublime-menu index ba686b208..925923fad 100644 --- a/Context.sublime-menu +++ b/Context.sublime-menu @@ -7,6 +7,20 @@ "command": "lsp_symbol_references", "caption": "Find References" }, + { + "command": "lsp_symbol_references", + "caption": "Find References (in bottom panel)", + "args": { + "show_in": "bottom_panel" + }, + }, + { + "command": "lsp_symbol_references", + "caption": "Find References (in quick panel)", + "args": { + "show_in": "quick_panel" + }, + }, { "command": "lsp_symbol_definition", "caption": "Goto Definition…" diff --git a/Default.sublime-commands b/Default.sublime-commands index 610d5cbab..ee307c686 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -121,6 +121,20 @@ "caption": "LSP: Find References", "command": "lsp_symbol_references" }, + { + "caption": "LSP: Find References (in bottom panel)", + "command": "lsp_symbol_references", + "args": { + "show_in": "bottom_panel" + }, + }, + { + "caption": "LSP: Find References (in quick panel)", + "command": "lsp_symbol_references", + "args": { + "show_in": "quick_panel" + }, + }, { "caption": "LSP: Follow Link", "command": "lsp_open_link" diff --git a/Main.sublime-menu b/Main.sublime-menu index 8aea68e8f..70312e37e 100644 --- a/Main.sublime-menu +++ b/Main.sublime-menu @@ -217,6 +217,16 @@ "caption": "LSP: Find References", "command": "lsp_symbol_references" }, + { + "caption": "Find References (in bottom panel)", + "command": "lsp_symbol_references", + "args": {"show_in": "bottom_panel"}, + }, + { + "caption": "Find References (in quick panel)", + "command": "lsp_symbol_references", + "args": {"show_in": "quick_panel"}, + }, { "caption": "LSP: Follow Link", "command": "lsp_open_link" @@ -255,20 +265,20 @@ "caption": "-" }, { - "caption": "Enable Language Server Globally…", - "command": "lsp_enable_language_server_globally", + "caption": "Enable Language Server Globally…", + "command": "lsp_enable_language_server_globally", }, { - "caption": "Disable Language Server Globally…", - "command": "lsp_disable_language_server_globally", + "caption": "Disable Language Server Globally…", + "command": "lsp_disable_language_server_globally", }, { - "caption": "Enable Language Server in Project…", - "command": "lsp_enable_language_server_in_project", + "caption": "Enable Language Server in Project…", + "command": "lsp_enable_language_server_in_project", }, { - "caption": "Disable Language Server in Project…", - "command": "lsp_disable_language_server_in_project", + "caption": "Disable Language Server in Project…", + "command": "lsp_disable_language_server_in_project", }, { "caption": "Troubleshoot Server Configuration…", diff --git a/docs/src/keyboard_shortcuts.md b/docs/src/keyboard_shortcuts.md index 41f0213ac..3b1e05a06 100644 --- a/docs/src/keyboard_shortcuts.md +++ b/docs/src/keyboard_shortcuts.md @@ -9,7 +9,7 @@ Refer to the [Customization section](customization.md#keyboard-shortcuts-key-bin | ------- | -------- | ------- | | Auto Complete | ctrl space (also on macOS) | `auto_complete` | Expand Selection | unbound | `lsp_expand_selection` -| Find References | shift f12 | `lsp_symbol_references` (supports optional args: `{"include_declaration": true/false}`) +| Find References | shift f12 | `lsp_symbol_references` (supports optional args: `{"include_declaration": true/false, "show_in": "bottom_panel"/"quick_panel"}`) | Fold | unbound | `lsp_fold` (supports optional args: `{"strict": true/false}` - to configure whether to fold only when the caret is contained within the folded region (`true`), or even when it is anywhere on the starting line (`false`)) | Fold All | unbound | `lsp_fold_all` (supports optional args: `{"kind": "comment" | "imports" | "region"}`) | Follow Link | unbound | `lsp_open_link` diff --git a/plugin/references.py b/plugin/references.py index df6073c79..c330451f4 100644 --- a/plugin/references.py +++ b/plugin/references.py @@ -7,7 +7,7 @@ from .core.sessions import Session from .core.settings import userprefs from .core.types import ClientConfig -from .core.typing import Dict, List, Optional, Tuple +from .core.typing import Dict, List, Literal, Optional, Tuple from .core.views import get_line from .core.views import get_symbol_kind_from_scope from .core.views import get_uri_and_position_from_location @@ -20,6 +20,9 @@ import sublime +ShowInArgument = Literal['bottom_panel', 'quick_panel'] + + class LspSymbolReferencesCommand(LspTextCommand): capability = 'referencesProvider' @@ -32,7 +35,8 @@ def is_enabled( force_group: bool = True, fallback: bool = False, group: int = -1, - include_declaration: bool = False + include_declaration: bool = False, + show_in: Optional[ShowInArgument] = None, ) -> bool: return fallback or super().is_enabled(event, point) @@ -44,10 +48,18 @@ def is_visible( force_group: bool = True, fallback: bool = False, group: int = -1, - include_declaration: bool = False + include_declaration: bool = False, + show_in: Optional[ShowInArgument] = None, ) -> bool: + # We include "in bottom panel" and "in quick panel" variants of `LSP: Find References` in the Command Palette + # but we only show the one that is not the same as the default one (per `show_references_in_quick_panel` + # setting). + if show_in == 'bottom_panel' and not userprefs().show_references_in_quick_panel or \ + show_in == 'quick_panel' and userprefs().show_references_in_quick_panel: + return False if self.applies_to_context_menu(event): - return self.is_enabled(event, point, side_by_side, fallback) + return self.is_enabled( + event, point, side_by_side, force_group, fallback, group, include_declaration, show_in) return True def run( @@ -59,7 +71,8 @@ def run( force_group: bool = True, fallback: bool = False, group: int = -1, - include_declaration: bool = False + include_declaration: bool = False, + show_in: Optional[ShowInArgument] = None, ) -> None: session = self.best_session(self.capability) file_path = self.view.file_name() @@ -85,6 +98,7 @@ def run( force_group, fallback, group, + show_in, word_range.begin() ) ) @@ -99,11 +113,12 @@ def _handle_response_async( force_group: bool, fallback: bool, group: int, + show_in: Optional[ShowInArgument], position: int, response: Optional[List[Location]] ) -> None: sublime.set_timeout(lambda: self._handle_response( - word, session, side_by_side, force_group, fallback, group, position, response)) + word, session, side_by_side, force_group, fallback, group, show_in, position, response)) def _handle_response( self, @@ -113,11 +128,12 @@ def _handle_response( force_group: bool, fallback: bool, group: int, + show_in: Optional[ShowInArgument], position: int, response: Optional[List[Location]] ) -> None: if response: - if userprefs().show_references_in_quick_panel: + if show_in == 'quick_panel' or (show_in is None and userprefs().show_references_in_quick_panel): self._show_references_in_quick_panel( word, session, response, side_by_side, force_group, group, position) else: