Skip to content
New issue

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

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

Already on GitHub? # to your account

Returnning arbitrary data to the client #400

Open
barkanido opened this issue Oct 11, 2023 · 1 comment
Open

Returnning arbitrary data to the client #400

barkanido opened this issue Oct 11, 2023 · 1 comment

Comments

@barkanido
Copy link

Hi,
In addition to signals sent to the client like logs and notifications, I need to return some custom data to the client. What is pygls api for returning, say, a nested dict? Should i return a response or there is a wrapping api fot that?
What will the client expect then? A raw json? Or the languages specific desirialization of the related json?

@alcarney
Copy link
Collaborator

Many objects have a field like CompletionItem.data where you can store arbitrary data - which may or may not be useful to you.

Alternatively you can send custom messages to the client.

  • notify is probably the easiest to get started with as it allows you to send a one off message to the client. Here is an example of a custom notification message
  • However, if you need the client to reply to your message then send_request or send_request_async will handle waiting for the response for you. Here you can find examples of using those

What happens client side is ultimately up to the language and/or framework that the client is written in.
In VSCode/TypeScript for example I'm able to define an interface that describes the structure of the custom message coming from the server and then reference it in the handler definition - at the lowest level though it's all JSON :)

Hope that helps!

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

No branches or pull requests

2 participants