Skip to content
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

feat(lsp): will save #8952

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
send notifications in parallel async
  • Loading branch information
matoous committed Mar 31, 2024
commit 5390ab7644c4bdf6bd27e77f97200d30441221db
33 changes: 22 additions & 11 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{anyhow, bail, Context, Error};
use arc_swap::access::DynAccess;
use arc_swap::ArcSwap;
use futures_util::future::BoxFuture;
use futures_util::future::{self, BoxFuture};
use futures_util::FutureExt;
use helix_core::auto_pairs::AutoPairs;
use helix_core::chars::char_is_word;
Expand Down Expand Up @@ -874,19 +874,25 @@ impl Document {

if let Some(identifier) = &identifier {
Copy link
Member

Choose a reason for hiding this comment

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

this should definitly4 be handeled by the even t system and what I meant with my previous comments. We essentially want to keep LSP out of the main code and move it all behind events. So there should be a willsave event here and the lsp stuff should be moved to a hook. Same with didsave

for language_server in language_servers.values() {
let mut notifications = Vec::new();

if language_server.is_initialized() {
let Some(notification) =
language_server.text_document_will_save(identifier.clone())
else {
continue
};

if let Err(err) = helix_lsp::block_on(notification) {
log::error!(
"failed to send textDocument/willSave notification: {err:?}"
);
}
notifications.push(async move {
if let Err(err) = notification.await {
log::error!(
"failed to send textDocument/willSave notification: {err:?}"
);
}
});
}

helix_lsp::block_on(future::join_all(notifications));
matoous marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down Expand Up @@ -923,6 +929,7 @@ impl Document {
};

if let Some(identifier) = &identifier {
let mut notifications = Vec::new();
for language_server in language_servers.values() {
if language_server.is_initialized() {
let Some(notification) =
Expand All @@ -931,13 +938,17 @@ impl Document {
continue
};

if let Err(err) = helix_lsp::block_on(notification) {
log::error!(
"failed to send textDocument/didSave notification: {err:?}"
);
}
notifications.push(async move {
if let Err(err) = helix_lsp::block_on(notification) {
log::error!(
"failed to send textDocument/didSave notification: {err:?}"
);
}
});
}
}

helix_lsp::block_on(future::join_all(notifications));
matoous marked this conversation as resolved.
Show resolved Hide resolved
}

Ok(event)
Expand Down