Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add await syntax support for sending edit request to client #350

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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