-
Notifications
You must be signed in to change notification settings - Fork 74
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
Introduce DocumentUpdateHandler service #1286
Conversation
e7563f9
to
4e26797
Compare
After rethinking, I realized the workspace file operations shouldn't be used for triggering DocumentBuilder updates because they are called only before / after operations done by the user in the client (VS Code). I extracted those operations into a new service I think issues such as #1230 need to be addressed with the file system watcher, which we can control from the language server after this change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes I sense for me.
I'm just wondering whether Langium should bring a handler for didDeleteFiles
notifications by default, as that might (should) have direct impact on the content of the index, doesn't it? (didCreateFiles
is probably less critical as newly created files are probably empty initially)
By the way: I tested the |
Those events are covered by the file watcher. The only events we're currently missing are operations on the folder level (#1230). |
You can add some tests for documentation purpose: to see how these services are used. |
I don't know what to test here. The default implementation doesn't do much. Regarding documentation, we should mention the new service in https://langium.org/docs/document-lifecycle/ |
f6cd741
to
d2cfea2
Compare
I tested this: The (VS Code) language client indeed sends two independent file change events - within a single notification -, see: ![]() Wrt. to Langium's current implementation this seems to be fine, mainly because of
However, I would prefer to add a deduplication in langium/packages/langium/src/lsp/document-update-handler.ts Lines 82 to 84 in d2cfea2
|
Why add a deduplication if the URIs are already deduplicated later? Deduplicating is expensive. I'd rather document this in the CHANGELOG so users don't configure the FS watcher on the client side. |
My guess is that in a few weeks/month we'll have forgotten about that detail, and once the area in the document builder is somehow changed, potential issues pop up quickly. Another option would be to have a test enforcing the tolerance of such duplicate URIs s.t. we make sure Langium can handle such cases properly. |
I have existing adopters in mind, and testing the correct handling of file renamings is probably not considered after switching the Langium version. |
Ok I used streams so the deduplication doesn't get too verbose. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Fixes #1272.
In addition, I stumbled over this statement from the LSP specification, didChangeWatchedFiles notification:
The default implementation of the new DocumentUpdateHandler service, which listens and reacts to
didChangeWatchedFiles
notifications, takes care of registering a file watcher so this doesn't have to be done by the client. This solves the problem I described in #1230 (comment):We should test this thoroughly, and also check what happens if the client still creates a FileSystemWatcher – does the language server receive the notifications twice? In that case, this is a breaking change that should be well documented in the CHANGELOG.