Skip to content

Commit

Permalink
add commands for opening "find references" in bottom or quick panel
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Jan 28, 2024
1 parent 3561214 commit 17626d5
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 16 deletions.
14 changes: 14 additions & 0 deletions Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -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…"
Expand Down
14 changes: 14 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 18 additions & 8 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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…",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/keyboard_shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Refer to the [Customization section](customization.md#keyboard-shortcuts-key-bin
| ------- | -------- | ------- |
| Auto Complete | <kbd>ctrl</kbd> <kbd>space</kbd> (also on macOS) | `auto_complete`
| Expand Selection | unbound | `lsp_expand_selection`
| Find References | <kbd>shift</kbd> <kbd>f12</kbd> | `lsp_symbol_references` (supports optional args: `{"include_declaration": true/false}`)
| Find References | <kbd>shift</kbd> <kbd>f12</kbd> | `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`
Expand Down
30 changes: 23 additions & 7 deletions plugin/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,6 +20,9 @@
import sublime


ShowInArgument = Literal['bottom_panel', 'quick_panel']


class LspSymbolReferencesCommand(LspTextCommand):

capability = 'referencesProvider'
Expand All @@ -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)

Expand All @@ -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(
Expand All @@ -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()
Expand All @@ -85,6 +98,7 @@ def run(
force_group,
fallback,
group,
show_in,
word_range.begin()
)
)
Expand All @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit 17626d5

Please sign in to comment.