Skip to content

Commit

Permalink
Handle basic editor commands (#1545)
Browse files Browse the repository at this point in the history
* editor.action.triggerSuggest (auto-complete)
* editor.action.triggerParameterHints (signature help)
  • Loading branch information
rwols authored Jan 18, 2021
1 parent cd1bd10 commit 2bf36ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def session_views_async(self) -> Iterable[SessionViewProtocol]:
def get_language_id(self) -> str:
raise NotImplementedError()

@abstractmethod
def do_signature_help_async(self, manual: bool) -> None:
raise NotImplementedError()


def extract_message(params: Any) -> str:
return params.get("message", "???") if isinstance(params, dict) else "???"
Expand Down
8 changes: 4 additions & 4 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def on_text_changed_async(self, change_count: int, changes: Iterable[sublime.Tex
self._when_selection_remains_stable_async(self._do_color_boxes_async, current_region,
after_ms=self.color_boxes_debounce_time)
if "signatureHelp" not in userprefs().disabled_capabilities:
self._do_signature_help(manual=False)
self.do_signature_help_async(manual=False)
if "codeLensProvider" not in userprefs().disabled_capabilities:
self._when_selection_remains_stable_async(self._do_code_lenses_async, current_region,
after_ms=self.code_lenses_debounce_time)
Expand Down Expand Up @@ -330,7 +330,7 @@ def on_query_context(self, key: str, operator: int, operand: Any, match_all: boo
elif key == "lsp.signature_help":
if not self.view.is_popup_visible():
if operand == 0:
sublime.set_timeout_async(lambda: self._do_signature_help(manual=True))
sublime.set_timeout_async(lambda: self.do_signature_help_async(manual=True))
return True
elif self._sighelp and self._sighelp.has_multiple_signatures() and not self.view.is_auto_complete_visible():
# We use the "operand" for the number -1 or +1. See the keybindings.
Expand All @@ -349,7 +349,7 @@ def on_hover(self, point: int, hover_zone: int) -> None:
def on_post_text_command(self, command_name: str, args: Optional[Dict[str, Any]]) -> None:
if command_name in ("next_field", "prev_field") and args is None:
if "signatureHelp" not in userprefs().disabled_capabilities:
sublime.set_timeout_async(lambda: self._do_signature_help(manual=True))
sublime.set_timeout_async(lambda: self.do_signature_help_async(manual=True))
if not self.view.is_popup_visible():
return
if command_name in ["hide_auto_complete", "move", "commit_completion"] or 'delete' in command_name:
Expand All @@ -370,7 +370,7 @@ def resolve(clist: sublime.CompletionList, items: List[sublime.CompletionItem],

# --- textDocument/signatureHelp -----------------------------------------------------------------------------------

def _do_signature_help(self, manual: bool) -> None:
def do_signature_help_async(self, manual: bool) -> None:
# NOTE: We take the beginning of the region to check the previous char (see last_char variable). This is for
# when a language server inserts a snippet completion.
pos = self._stored_region.a
Expand Down
13 changes: 13 additions & 0 deletions plugin/execute_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .core.protocol import Error
from .core.protocol import ExecuteCommandParams
from .core.registry import LspTextCommand
from .core.registry import windows
from .core.typing import List, Optional, Any
from .core.views import uri_from_view, offset_to_point, region_to_range, text_document_identifier

Expand All @@ -14,6 +15,18 @@ def run(self,
command_args: Optional[List[Any]] = None,
session_name: Optional[str] = None,
event: Optional[dict] = None) -> None:
# Handle VSCode-specific command for triggering AC/sighelp
if command_name == "editor.action.triggerSuggest":
# Triggered from set_timeout as suggestions popup doesn't trigger otherwise.
return sublime.set_timeout(lambda: self.view.run_command("auto_complete"))
if command_name == "editor.action.triggerParameterHints":

def run_async() -> None:
listener = windows.listener_for_view(self.view)
if listener:
listener.do_signature_help_async(manual=False)

return sublime.set_timeout_async(run_async)
session = self.session_by_name(session_name) if session_name else self.best_session(self.capability)
if session and command_name:
if command_args:
Expand Down

0 comments on commit 2bf36ca

Please sign in to comment.