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

Additional properites of MessageActionItem #518

Open
nemethf opened this issue Feb 8, 2025 · 2 comments
Open

Additional properites of MessageActionItem #518

nemethf opened this issue Feb 8, 2025 · 2 comments

Comments

@nemethf
Copy link
Contributor

nemethf commented Feb 8, 2025

ShowMessageRequestClientCapabilities of ShowMessageRequest has this:

	messageActionItem?: {
		/**
		 * Whether the client supports additional attributes which
		 * are preserved and sent back to the server in the
		 * request's response.
		 */
		additionalPropertiesSupport?: boolean;
	};

But how should I create a MessageActionItem with additional properties? I tried:

    print(types.MessageActionItem(title="title", asdf="asdf"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: MessageActionItem.__init__() got an unexpected keyword argument 'asdf'

Thanks

@alcarney
Copy link
Collaborator

alcarney commented Feb 9, 2025

It looks like the definition of MessageActionItem in lsprotocol doesn't allow for additional fields...

Does creating your own subclass of MessageActionItem work?

@attrs.define
class AsdfActionItem(types.MessageActionItem):
    asdf: str = attrs.field(default='')

print(AsdfActionItem(title="title", asdf="asdf"))

However, now that I think about it, you would probably also need to use a custom LanguageServerProtocol object so that pygls uses your custom definition when deserialsing the result

from pygls.protocol import LanguageServerProtocol
from pygls.server import LanguageServer

@attrs.define
class AsdfShowMessageResponse:
    id: Optional[Union[int, str]] = attrs.field()
    """The request id."""
    result: Optional[AsdfActionItem] = attrs.field(default=None)
    jsonrpc: str = attrs.field(default="2.0")


class AsdfServerProtocol(LanguageServerProtocol):
    def get_result_type(self, method: str) -> Optional[Type]:
        if method == types.WINDOW_SHOW_MESSAGE_REQUEST:
            return AsdfShowMessageResponse

        super().get_result_type(method)

server = LanguageServer(protocol_cls=AsdfServerProtocol)

It might also be worth opening an issue in the lsprotocol repo and see if it's possible to add support for additional fields to the MessageActionItem class

Hope that helps!

@nemethf
Copy link
Contributor Author

nemethf commented Feb 10, 2025

@alcarney, thank you for the detailed answer. I opened an issue upstream.

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

No branches or pull requests

2 participants