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 on_server_notification_async API #2496

Merged
merged 3 commits into from
Jun 24, 2024

Conversation

predragnikolic
Copy link
Member

closes #2494

This API allows LSP-* to hook into when a notification is received form the language server.

First I tired to make it look like on_server_response_async
but the method argument is redundant
"""
Notifies about a notification message that has been received from the language server.

:param notification: The notification object.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... "The notification object."

I couldn't think of better 🙈

@TerminalFi
Copy link
Contributor

Although Copilot is doing some unconventional ideas. The use case is strong, in that helpers could also us it to raise information

@predragnikolic
Copy link
Member Author

Copilot is adhering to the spec here

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#progress

The base protocol offers also support to report progress in a generic fashion. This mechanism can be used to report any kind of progress including work done progress (usually used to report progress in the user interface using a progress bar) and partial result progress to support streaming of results.

interface [ProgressParams](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#progress)<T> {
	/**
	 * The progress token provided by the client or server.
	 */
	token: [ProgressToken](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#progress);

	/**
	 * The progress data.
	 */
	value: T;
}

@predragnikolic predragnikolic merged commit baa07a7 into main Jun 24, 2024
8 checks passed
@predragnikolic predragnikolic deleted the add-on_server_notification_async branch June 24, 2024 17:38
@predragnikolic
Copy link
Member Author

Just for leaving a clue on how to implement it in packages:

Here example with NpmClientHandler

from lsp_utils import NpmClientHandler

class LspMyPackage(NpmClientHandler):

    def on_server_notification_async(self, notification) -> None:
        if notification.method == '$/progress':
            print('read this notification', notification.params)

Here example with AbstractPlugin

from LSP.plugin import AbstractPlugin

class LspMyPackage(AbstractPlugin):

    def on_server_notification_async(self, notification) -> None:
        if notification.method == '$/progress':
            print('read this notification', notification.params)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow AbstractPlugin to handle $/progress notification
3 participants