-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base: master
Are you sure you want to change the base?
feat(lsp): will save #8952
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
@@ -871,6 +871,31 @@ impl Document { | |
// We encode the file according to the `Document`'s encoding. | ||
let future = async move { | ||
use tokio::{fs, fs::File}; | ||
|
||
if let Some(identifier) = &identifier { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
}; | ||
|
||
notifications.push(async move { | ||
if let Err(err) = notification.await { | ||
log::error!( | ||
"failed to send textDocument/willSave notification: {err:?}" | ||
); | ||
} | ||
}); | ||
} | ||
|
||
future::join_all(notifications).await; | ||
} | ||
}; | ||
|
||
if let Some(parent) = path.parent() { | ||
// TODO: display a prompt asking the user if the directories should be created | ||
if !parent.exists() { | ||
|
@@ -903,17 +928,27 @@ impl Document { | |
text: text.clone(), | ||
}; | ||
|
||
for (_, language_server) in language_servers { | ||
if !language_server.is_initialized() { | ||
return Ok(event); | ||
} | ||
if let Some(identifier) = &identifier { | ||
if let Some(notification) = | ||
language_server.text_document_did_save(identifier.clone(), &text) | ||
{ | ||
notification.await?; | ||
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) = | ||
language_server.text_document_did_save(identifier.clone(), &text) | ||
else { | ||
continue | ||
}; | ||
|
||
notifications.push(async move { | ||
if let Err(err) = notification.await { | ||
log::error!( | ||
"failed to send textDocument/didSave notification: {err:?}" | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
future::join_all(notifications).await; | ||
} | ||
|
||
Ok(event) | ||
|
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.
this seems unrelated