Implement a playground for my language #894
-
I want to implement a playground for my own language. I read the guide about generation on the web and I was checking the code for the Langium playground. The challenge I'm facing right now is that I'm not sure how I can be notified about my document being valid to render that. In the guide, if I understand it correctly, we need to get the text from the editor and send it to the language server for it to be parsed again. In the playground, it looks like a proxy is being used, but it is more complex because a new language server needs to start for the new gramar and I don't have that complexity. My question is more about, how can I have access to the parsed document in the browser after the validation so I can use it to update my ui? I don't it to be behind a button, I want to react to a valid document. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hey @luiz290788, so the easiest way to accomplish this is by simply sending a JSON-RPC notification from the language server to the language client. The language services contain a connection object at // language server/webworker
services.shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.Validated, documents => {
services.shared.lsp.Connection.sendNotification('validated', /** some data */);
});
// language client/monaco
client.onNotification('validated', someData => {
// Do whatever you want with the data
}); |
Beta Was this translation helpful? Give feedback.
-
We also have another project that we recently implemented this in, where we expected to get updates asynchronously without having to poll for that information. To that end, I created an issue eclipse-langium/langium-website#127 to incorporate a new guide/tutorial about utilizing notifications, as I think this would make a good addition to our docs. |
Beta Was this translation helpful? Give feedback.
Hey @luiz290788,
so the easiest way to accomplish this is by simply sending a JSON-RPC notification from the language server to the language client. The language services contain a connection object at
services.shared.lsp.Connection
, which you can use like this: