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 @@ fn spawn(mut command: Command) -> std::io::Result<CommandHandle> {
let (sender, receiver) = unbounded(); let (sender, receiver) = unbounded();
let actor = CargoActor::new(sender, stdout, stderr); let actor = CargoActor::new(sender, stdout, stderr);
let thread = stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker) let thread = stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)
.name("CargoHandle".to_owned()) .name("CommandHandle".to_owned())
.spawn(move || actor.run()) .spawn(move || actor.run())
.expect("failed to spawn thread"); .expect("failed to spawn thread");
Ok(CommandHandle { program, arguments, current_dir, child, thread, receiver }) Ok(CommandHandle { program, arguments, current_dir, child, thread, receiver })

View File

@ -82,6 +82,7 @@ enum ParallelPrimeCacheWorkerProgress {
stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker) stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)
.allow_leak(true) .allow_leak(true)
.name("PrimeCaches".to_owned())
.spawn(move || Cancelled::catch(|| worker(db))) .spawn(move || Cancelled::catch(|| worker(db)))
.expect("failed to spawn thread"); .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(); 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) { if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) {
let data = match state.mem_docs.get_mut(&path) { let Some(DocumentData { version, data }) = state.mem_docs.get_mut(&path) else {
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); tracing::error!("unexpected DidChangeTextDocument: {}", path);
return Ok(()); 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( let new_contents = apply_document_changes(
state.config.position_encoding(), state.config.position_encoding(),

View File

@ -12,13 +12,18 @@
/// Creates an LSP connection via stdio. /// Creates an LSP connection via stdio.
pub(crate) fn stdio_transport() -> (Sender<Message>, Receiver<Message>, IoThreads) { pub(crate) fn stdio_transport() -> (Sender<Message>, Receiver<Message>, IoThreads) {
let (writer_sender, writer_receiver) = bounded::<Message>(0); let (writer_sender, writer_receiver) = bounded::<Message>(0);
let writer = thread::spawn(move || { let writer = thread::Builder::new()
.name("LspServerWriter".to_owned())
.spawn(move || {
let stdout = stdout(); let stdout = stdout();
let mut stdout = stdout.lock(); let mut stdout = stdout.lock();
writer_receiver.into_iter().try_for_each(|it| it.write(&mut stdout)) writer_receiver.into_iter().try_for_each(|it| it.write(&mut stdout))
}); })
.unwrap();
let (reader_sender, reader_receiver) = bounded::<Message>(0); let (reader_sender, reader_receiver) = bounded::<Message>(0);
let reader = thread::spawn(move || { let reader = thread::Builder::new()
.name("LspServerReader".to_owned())
.spawn(move || {
let stdin = stdin(); let stdin = stdin();
let mut stdin = stdin.lock(); let mut stdin = stdin.lock();
while let Some(msg) = Message::read(&mut stdin)? { while let Some(msg) = Message::read(&mut stdin)? {
@ -32,7 +37,8 @@ pub(crate) fn stdio_transport() -> (Sender<Message>, Receiver<Message>, IoThread
} }
} }
Ok(()) Ok(())
}); })
.unwrap();
let threads = IoThreads { reader, writer }; let threads = IoThreads { reader, writer };
(writer_sender, reader_receiver, threads) (writer_sender, reader_receiver, threads)
} }