ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.66k stars 750 forks source link

[New Feature]: New lang server API to notify the text edits #42229

Open madushajg opened 8 months ago

madushajg commented 8 months ago

Description

There is a requirement to listen on bal file changes (done via VSCode editor or file system write), so that diagrams can rerender by being responsive. It seems this can be achieved by adding support for didChangeWatchedFiles[1] notification in ballerina lang server.

[1] https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeWatchedFiles

nipunayf commented 7 months ago

The current implementation of the LS supports this API, and specifically for files with a *.bal extension, we are also monitoring changes to the file, covering text edits. For the rest of the file types, we are only considering creation and deletion.

https://github.com/ballerina-platform/ballerina-lang/blob/de13d5198ce7fd11db21dbfa2d30200a4ab4cef8/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/BallerinaWorkspaceService.java#L86-L107

As of now, we are only using this API to publish diagnostics to the LS client upon changes to the file. We can refine this API to provide responses to the diagrams as well, once we know precisely the expected response structure.

madushajg commented 7 months ago

Great! For the diagrams, providing the document URI, file event type, and the changed location is sufficient

mindula commented 7 months ago

We have already implemented a Publisher-Subscriber (pub-sub) event synchronisation framework within the Ballerina Language Server. This framework enables a group of observers to monitor events related to the Language Server).

For detailed information on the design and implementation of this framework, please refer to the following documents:

  1. Document Event Sync Publisher-Subscriber Design (Link1)
  2. Document Event Sync Publisher-Subscriber Developer Guide (Link2)

As an example, we have developed a Publisher for project updates (such as didChange, etc.) named ProjectUpdateEventPublisher, which can be found here.

Additionally, an Observer named PublishDiagnosticSubscriber has been created to subscribe to events emitted by the ProjectUpdateEventPublisher. You can find the implementation of PublishDiagnosticSubscriber here.

We believe that the existing functionality provided by this framework fulfils the above mentioned requirements.