Give all threads names

This commit is contained in:
Lukas Wirth 2024-02-23 21:50:41 +01:00 committed by Lukas Wirth
parent 9efa23c4da
commit 83a1ad5bfe
4 changed files with 31 additions and 29 deletions

View file

@ -494,7 +494,7 @@ impl CommandHandle {
let (sender, receiver) = unbounded();
let actor = CargoActor::new(sender, stdout, stderr);
let thread = stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)
.name("CargoHandle".to_owned())
.name("CommandHandle".to_owned())
.spawn(move || actor.run())
.expect("failed to spawn thread");
Ok(CommandHandle { program, arguments, current_dir, child, thread, receiver })

View file

@ -82,6 +82,7 @@ pub fn parallel_prime_caches(
stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)
.allow_leak(true)
.name("PrimeCaches".to_owned())
.spawn(move || Cancelled::catch(|| worker(db)))
.expect("failed to spawn thread");
}

View file

@ -90,18 +90,13 @@ pub(crate) fn handle_did_change_text_document(
let _p = tracing::span!(tracing::Level::INFO, "handle_did_change_text_document").entered();
if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) {
let data = match state.mem_docs.get_mut(&path) {
Some(doc) => {
// The version passed in DidChangeTextDocument is the version after all edits are applied
// so we should apply it before the vfs is notified.
doc.version = params.text_document.version;
&mut doc.data
}
None => {
tracing::error!("unexpected DidChangeTextDocument: {}", path);
return Ok(());
}
let Some(DocumentData { version, data }) = state.mem_docs.get_mut(&path) else {
tracing::error!("unexpected DidChangeTextDocument: {}", path);
return Ok(());
};
// The version passed in DidChangeTextDocument is the version after all edits are applied
// so we should apply it before the vfs is notified.
*version = params.text_document.version;
let new_contents = apply_document_changes(
state.config.position_encoding(),

View file

@ -12,27 +12,33 @@ use crate::Message;
/// Creates an LSP connection via stdio.
pub(crate) fn stdio_transport() -> (Sender<Message>, Receiver<Message>, IoThreads) {
let (writer_sender, writer_receiver) = bounded::<Message>(0);
let writer = thread::spawn(move || {
let stdout = stdout();
let mut stdout = stdout.lock();
writer_receiver.into_iter().try_for_each(|it| it.write(&mut stdout))
});
let writer = thread::Builder::new()
.name("LspServerWriter".to_owned())
.spawn(move || {
let stdout = stdout();
let mut stdout = stdout.lock();
writer_receiver.into_iter().try_for_each(|it| it.write(&mut stdout))
})
.unwrap();
let (reader_sender, reader_receiver) = bounded::<Message>(0);
let reader = thread::spawn(move || {
let stdin = stdin();
let mut stdin = stdin.lock();
while let Some(msg) = Message::read(&mut stdin)? {
let is_exit = matches!(&msg, Message::Notification(n) if n.is_exit());
let reader = thread::Builder::new()
.name("LspServerReader".to_owned())
.spawn(move || {
let stdin = stdin();
let mut stdin = stdin.lock();
while let Some(msg) = Message::read(&mut stdin)? {
let is_exit = matches!(&msg, Message::Notification(n) if n.is_exit());
debug!("sending message {:#?}", msg);
reader_sender.send(msg).expect("receiver was dropped, failed to send a message");
debug!("sending message {:#?}", msg);
reader_sender.send(msg).expect("receiver was dropped, failed to send a message");
if is_exit {
break;
if is_exit {
break;
}
}
}
Ok(())
});
Ok(())
})
.unwrap();
let threads = IoThreads { reader, writer };
(writer_sender, reader_receiver, threads)
}