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 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 @@ enum ParallelPrimeCacheWorkerProgress {
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 => {
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,13 +12,18 @@
/// 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 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 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)? {
@ -32,7 +37,8 @@ pub(crate) fn stdio_transport() -> (Sender<Message>, Receiver<Message>, IoThread
}
}
Ok(())
});
})
.unwrap();
let threads = IoThreads { reader, writer };
(writer_sender, reader_receiver, threads)
}