Skip to content

Commit

Permalink
feat: add await syntax support for sending edit request to client
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversen committed Sep 3, 2023
1 parent 72294ed commit 637d3fd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/source/pages/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ Workspace methods that can be used for user defined features are:
def apply_edit(self, edit: WorkspaceEdit, label: str = None) -> ApplyWorkspaceEditResponse:
# Omitted
def apply_edit_async(self, edit: WorkspaceEdit, label: str = None) -> ApplyWorkspaceEditResponse:
# Omitted
.. _pygls.lsp.methods: https://github.com/openlawlibrary/pygls/blob/master/pygls/lsp/methods.py
.. _pygls.lsp.types: https://github.com/openlawlibrary/pygls/tree/master/pygls/lsp/types
8 changes: 8 additions & 0 deletions pygls/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,14 @@ def apply_edit(
WORKSPACE_APPLY_EDIT, ApplyWorkspaceEditParams(edit=edit, label=label)
)

def apply_edit_async(
self, edit: WorkspaceEdit, label: Optional[str] = None
) -> WorkspaceApplyEditResponse:
"""Sends apply edit request to the client. Should be called with `await`"""
return self.send_request_async(
WORKSPACE_APPLY_EDIT, ApplyWorkspaceEditParams(edit=edit, label=label)
)

@lsp_method(EXIT)
def lsp_exit(self, *args) -> None:
"""Stops the server process."""
Expand Down
6 changes: 6 additions & 0 deletions pygls/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ def apply_edit(
"""Sends apply edit request to the client."""
return self.lsp.apply_edit(edit, label)

def apply_edit_async(
self, edit: WorkspaceEdit, label: Optional[str] = None
) -> WorkspaceApplyEditResponse:
"""Sends apply edit request to the client. Should be called with `await`"""
return self.lsp.apply_edit_async(edit, label)

def command(self, command_name: str) -> Callable[[F], F]:
"""Decorator used to register custom commands.
Expand Down

0 comments on commit 637d3fd

Please sign in to comment.