From d1acee6b8ca4c4ff09b3f51e4d750281ed335ed6 Mon Sep 17 00:00:00 2001 From: duncan Date: Wed, 22 Jan 2025 22:14:00 +0000 Subject: [PATCH] remove hack_recover_crate_name --- .../src/hack_recover_crate_name.rs | 25 ------------------- crates/rust-analyzer/src/handlers/request.rs | 5 +--- crates/rust-analyzer/src/lib.rs | 1 - crates/rust-analyzer/src/main_loop.rs | 5 +--- 4 files changed, 2 insertions(+), 34 deletions(-) delete mode 100644 crates/rust-analyzer/src/hack_recover_crate_name.rs diff --git a/crates/rust-analyzer/src/hack_recover_crate_name.rs b/crates/rust-analyzer/src/hack_recover_crate_name.rs deleted file mode 100644 index d7285653c5fa..000000000000 --- a/crates/rust-analyzer/src/hack_recover_crate_name.rs +++ /dev/null @@ -1,25 +0,0 @@ -//! Currently cargo does not emit crate name in the `cargo test --format=json`, which needs to be changed. This -//! module contains a way to recover crate names in a very hacky and wrong way. - -// FIXME(hack_recover_crate_name): Remove this module. - -use std::sync::{Mutex, MutexGuard, OnceLock}; - -use ide_db::FxHashMap; - -static STORAGE: OnceLock>> = OnceLock::new(); - -fn get_storage() -> MutexGuard<'static, FxHashMap> { - STORAGE.get_or_init(|| Mutex::new(FxHashMap::default())).lock().unwrap() -} - -pub(crate) fn insert_name(name_with_crate: String) { - let Some((_, name_without_crate)) = name_with_crate.split_once("::") else { - return; - }; - get_storage().insert(name_without_crate.to_owned(), name_with_crate); -} - -pub(crate) fn lookup_name(name_without_crate: String) -> Option { - get_storage().get(&name_without_crate).cloned() -} diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs index 447df0379281..ac8fa6eee32f 100644 --- a/crates/rust-analyzer/src/handlers/request.rs +++ b/crates/rust-analyzer/src/handlers/request.rs @@ -36,7 +36,6 @@ use crate::{ config::{Config, RustfmtConfig, WorkspaceSymbolConfig}, diagnostics::convert_diagnostic, global_state::{FetchWorkspaceRequest, GlobalState, GlobalStateSnapshot}, - hack_recover_crate_name, line_index::LineEndings, lsp::{ ext::{ @@ -299,9 +298,7 @@ pub(crate) fn handle_discover_test( } None => (snap.analysis.discover_test_roots()?, None), }; - for t in &tests { - hack_recover_crate_name::insert_name(t.id.clone()); - } + Ok(lsp_ext::DiscoverTestResults { tests: tests .into_iter() diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs index 61ec576dd4f9..f2062ef4a21c 100644 --- a/crates/rust-analyzer/src/lib.rs +++ b/crates/rust-analyzer/src/lib.rs @@ -15,7 +15,6 @@ mod command; mod diagnostics; mod discover; mod flycheck; -mod hack_recover_crate_name; mod line_index; mod main_loop; mod mem_docs; diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 4b8164b0b8dd..4519455b9dd4 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -26,7 +26,6 @@ use crate::{ file_id_to_url, url_to_file_id, FetchBuildDataResponse, FetchWorkspaceRequest, FetchWorkspaceResponse, GlobalState, }, - hack_recover_crate_name, handlers::dispatch::{NotificationDispatcher, RequestDispatcher}, lsp::{ from_proto, to_proto, @@ -634,9 +633,7 @@ impl GlobalState { .filter_map(|f| snapshot.analysis.discover_tests_in_file(f).ok()) .flatten() .collect::>(); - for t in &tests { - hack_recover_crate_name::insert_name(t.id.clone()); - } + Task::DiscoverTest(lsp_ext::DiscoverTestResults { tests: tests .into_iter()