Skip to content

Conversation

gustafbergmark
Copy link

This PR adds support for the willSave and willSaveWaitUntil requests of the LSP.

@gustafbergmark
Copy link
Author

The implementation does not handle writing to new files properly, will try to fix this later this week. The problem seem to be the workspace edit opening the soon-to-be-written file in a duplicate buffer which results in all kinds of unintended behavior.

@gustafbergmark
Copy link
Author

The implementation now uses Transactions instead of WorkspaceEdits.
One open question is whether it should instead use the private function apply_text_edits.

Currently, the Transaction is applied regardless of whether the save succeeds, which (from what I’ve gathered) is the correct behavior.

I consider the implementation complete unless there is further feedback on the code.

&self,
text_document: lsp::TextDocumentIdentifier,
reason: lsp::TextDocumentSaveReason,
) -> Option<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match other notification-style functions in the client let's not return anything here,

Suggested change
) -> Option<()> {
) {

Similarly see text_document_did_open


match &capabilities.text_document_sync.as_ref()? {
lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
will_save: enabled,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can match explicitly on will_save: Some(true) here for the same effect as the if below.


match &capabilities.text_document_sync.as_ref()? {
lsp::TextDocumentSyncCapability::Options(lsp::TextDocumentSyncOptions {
will_save_wait_until: enabled,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here about pattern matching

Comment on lines +1966 to +1968
let language_servers: Vec<_> = self
.language_servers
.iter_clients()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will send the will-saves to all language servers even if the document doesn't belong to a language server. Instead this can iterate over doc.language_servers.values()

else {
continue;
};
let edits = match helix_lsp::block_on(request) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will block the main thread and it could take a while if a language server sends edits when saving many documents with :write-all. Instead these will-save requests should be done asynchronously like formatting requests

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

Successfully merging this pull request may close these issues.

2 participants