Skip to content

Commit

Permalink
Add overridable methods to LspExecuteCommand (#2024)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Aug 21, 2022
1 parent 314ec85 commit 566a49e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .plugin.core.panels import LspUpdatePanelCommand
from .plugin.core.panels import LspUpdateServerPanelCommand
from .plugin.core.panels import WindowPanelListener
from .plugin.core.protocol import Error
from .plugin.core.protocol import Location
from .plugin.core.registry import LspRecheckSessionsCommand
from .plugin.core.registry import LspRestartServerCommand
Expand Down
33 changes: 26 additions & 7 deletions plugin/execute_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@


class LspExecuteCommand(LspTextCommand):
"""
Helper command for triggering workspace/executeCommand requests.
"""

def run(self,
edit: sublime.Edit,
Expand Down Expand Up @@ -37,17 +40,33 @@ def run_async() -> None:
def handle_response(response: Any) -> None:
assert command_name
if isinstance(response, Error):
sublime.message_dialog("command {} failed. Reason: {}".format(command_name, str(response)))
self.handle_error_async(response, command_name)
return
msg = "command {} completed".format(command_name)
if response:
msg += "with response: {}".format(response)
window = self.view.window()
if window:
window.status_message(msg)
self.handle_success_async(response, command_name)

session.execute_command(params, progress=True).then(handle_response)

def handle_success_async(self, result: Any, command_name: str) -> None:
"""
Override this method to handle successful response to workspace/executeCommand.
:param result: The result returned from the server.
:param command_name: The name of the command that was executed.
"""
msg = "command {} completed".format(command_name)
window = self.view.window()
if window:
window.status_message(msg)

def handle_error_async(self, error: Error, command_name: str) -> None:
"""
Override this method to handle failed response to workspace/executeCommand.
:param error: The Error object.
:param command_name: The name of the command that was executed.
"""
sublime.message_dialog("command {} failed. Reason: {}".format(command_name, str(error)))

def _expand_variables(self, command_args: List[Any]) -> List[Any]:
view = self.view # type: sublime.View
region = first_selection_region(view)
Expand Down

0 comments on commit 566a49e

Please sign in to comment.