openlawlibrary / pygls

A pythonic generic language server
https://pygls.readthedocs.io/en/latest/
Apache License 2.0
563 stars 102 forks source link

Returnning arbitrary data to the client #400

Open barkanido opened 10 months ago

barkanido commented 10 months ago

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 commented 10 months ago

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.

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!