Skip to content

Commit

Permalink
Keep current key bindings functional and improve item format
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann committed Sep 25, 2023
1 parent 4bc978e commit ed893aa
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions plugin/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ def symbol_to_list_input_item(
if container_name:
details.append(container_name)
region = range_to_region(item['location']['range'], view)
if SymbolTag.Deprecated in (item.get('tags') or []) or item.get('deprecated', False):
details.append("DEPRECATED")
deprecated = SymbolTag.Deprecated in (item.get('tags') or []) or item.get('deprecated', False)
return sublime.ListInputItem(
name,
{'kind': kind, 'region': [region.a, region.b]},
details=details,
{'kind': kind, 'region': [region.a, region.b], 'deprecated': deprecated},
details=" • ".join(details),
annotation=st_kind[2],
kind=st_kind
)
Expand Down Expand Up @@ -140,7 +139,7 @@ def run(self, _: sublime.Edit, regions: List[Tuple[int, int]]) -> None:
class LspDocumentSymbolsCommand(LspTextCommand):

capability = 'documentSymbolProvider'
REGIONS_KEY = 'lsp_document_symbols'
# REGIONS_KEY = 'lsp_document_symbols'

def __init__(self, view: sublime.View) -> None:
super().__init__(view)
Expand All @@ -155,7 +154,14 @@ def run(
kind: int = 0,
index: Optional[int] = None
) -> None:
pass
if index is None:
self.kind = kind
session = self.best_session(self.capability)
if session:
self.view.settings().set(SUPPRESS_INPUT_SETTING_KEY, True)
params = {"textDocument": text_document_identifier(self.view)} # type: DocumentSymbolParams
session.send_request(
Request.documentSymbols(params, self.view), self.handle_response_async, self.handle_response_error)

def input(self, args: dict) -> Optional[sublime_plugin.CommandInputHandler]:
if self.cached:
Expand All @@ -169,13 +175,6 @@ def input(self, args: dict) -> Optional[sublime_plugin.CommandInputHandler]:
self.kind,
kind=SYMBOL_KINDS.get(symbol_kind, sublime.KIND_AMBIGUOUS))
return DocumentSymbolsKindInputHandler(window, initial_value, self.view, self.items)
self.kind = args.get('kind', 0)
session = self.best_session(self.capability)
if session:
self.view.settings().set(SUPPRESS_INPUT_SETTING_KEY, True)
params = {"textDocument": text_document_identifier(self.view)} # type: DocumentSymbolParams
session.send_request(
Request.documentSymbols(params, self.view), self.handle_response_async, self.handle_response_error)
return None

def handle_response_async(self, response: Union[List[DocumentSymbol], List[SymbolInformation], None]) -> None:
Expand Down Expand Up @@ -281,10 +280,14 @@ def list_items(self) -> Tuple[List[sublime.ListInputItem], int]:
break
return items, selected_index

def preview(self, text: dict) -> Union[str, sublime.Html]:
r = text['region']
self.view.run_command('lsp_selection_set', {'regions': [(r[0], r[1])]})
self.view.show_at_center(r[0])
def preview(self, text: Any) -> Union[str, sublime.Html, None]:
if isinstance(text, dict):
r = text.get('region')
if r:
self.view.run_command('lsp_selection_set', {'regions': [(r[0], r[1])]})
self.view.show_at_center(r[0])
if text.get('deprecated'):
return "⚠ Deprecated"
return ""

def cancel(self) -> None:
Expand Down

0 comments on commit ed893aa

Please sign in to comment.