Skip to content

Commit 655ff24

Browse files
author
Song Gao
committed
clean
1 parent d9b246d commit 655ff24

File tree

8 files changed

+9
-111
lines changed

8 files changed

+9
-111
lines changed

crates/ide/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,15 +527,6 @@ impl Analysis {
527527
self.with_db(|db| test_items::test_runnables_in_file(db, file_id))
528528
}
529529

530-
pub fn test_runnables_in_db(
531-
&self,
532-
// workspaces: &Arc<Vec<ProjectWorkspace>>,
533-
) -> Cancellable<Vec<Runnable>> {
534-
self.with_db(|db| test_items::test_runnables_in_db(db
535-
// , workspaces
536-
))
537-
}
538-
539530
/// Returns the set of tests for the given file position.
540531
pub fn related_tests(
541532
&self,

crates/ide/src/test_items.rs

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,17 @@
1-
use std::path::PathBuf;
2-
31
/// This mod is mainly to support vscode native test extension
42
/// please reference: https://code.visualstudio.com/api/extension-guides/testing
53
// It's a pretty rough implementation for now, reuse a lot of logic from runnable.
64
use ide_db::{
7-
base_db::{FileId, SourceDatabaseExt},
5+
base_db::{FileId},
86
RootDatabase,
97
};
10-
use itertools::Itertools;
118

129
use crate::{runnables::runnables, Runnable, RunnableKind};
1310

1411
pub(crate) fn test_runnables_in_file(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
1512
return test_runnables_in_file_iter(db, file_id).collect();
1613
}
1714

18-
// TODO: delete related code, for we want to do it lazily
19-
pub(crate) fn test_runnables_in_db(
20-
db: &RootDatabase,
21-
// _workspaces: &Arc<Vec<ProjectWorkspace>>,
22-
) -> Vec<Runnable> {
23-
// use workspace seems to be better, but why there are multi roots?
24-
// let workspace_roots = workspaces
25-
// .iter()
26-
// .map(|workspace| workspace.workspace_definition_path().unwrap())
27-
// .collect::<FxHashSet<_>>();
28-
// use cargo home path as a trick
29-
let cargo_home_path = home::cargo_home();
30-
let rustup_home_path = home::rustup_home();
31-
let crate_graph = ide_db::search::SearchScope::crate_graph(db);
32-
let tests = crate_graph
33-
.into_iter()
34-
// skip the module if it's dependency
35-
.filter(|(file_id, _)| match (&cargo_home_path, &rustup_home_path) {
36-
(Ok(cargo_home_path), Ok(rustup_home_path)) => {
37-
let root_id = db.file_source_root(file_id.clone());
38-
let source_root = db.source_root(root_id);
39-
let file_path: PathBuf = source_root
40-
.path_for_file(file_id)
41-
.unwrap()
42-
.as_path()
43-
.unwrap()
44-
.to_path_buf()
45-
.into();
46-
// dependency file will be downloaed to `cargo_home_path`
47-
// only find test runnables in user files
48-
let is_not_dependency = !file_path.starts_with(cargo_home_path);
49-
let is_not_standard_lib = !file_path.starts_with(rustup_home_path);
50-
return is_not_dependency && is_not_standard_lib;
51-
}
52-
// If neighther is not existed, search all.
53-
// Or assert as `never!`?
54-
_ => return true,
55-
})
56-
.flat_map(|(file_id, _)| test_runnables_in_file_iter(db, file_id))
57-
.collect_vec();
58-
return tests;
59-
}
60-
6115
fn test_runnables_in_file_iter(
6216
db: &RootDatabase,
6317
file_id: FileId,

crates/rust-analyzer/src/handlers.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -805,23 +805,6 @@ pub(crate) fn handle_runnables(
805805
Ok(res)
806806
}
807807

808-
pub(crate) fn handle_test_runnables_in_db(
809-
snap: GlobalStateSnapshot,
810-
_: (),
811-
) -> Result<Vec<lsp_ext::TestInfo2>> {
812-
let _p = profile::span("handle_test_runnables_in_db");
813-
let test_runnables = snap.analysis.test_runnables_in_db(
814-
// &snap.workspaces
815-
)?;
816-
let mut res = Vec::new();
817-
for runnable in test_runnables {
818-
let runnable = to_proto::test_info_2(&snap, runnable)?;
819-
res.push(runnable);
820-
}
821-
822-
Ok(res)
823-
}
824-
825808
pub(crate) fn handle_cargo_workspaces(
826809
snap: GlobalStateSnapshot,
827810
_: (),
@@ -844,15 +827,15 @@ pub(crate) fn handle_cargo_workspaces(
844827
pub(crate) fn handle_test_runnables_in_file(
845828
snap: GlobalStateSnapshot,
846829
params: lsp_ext::TestRunnablesInFileParams,
847-
) -> Result<Vec<lsp_ext::TestInfo2>> {
830+
) -> Result<Vec<lsp_ext::Runnable>> {
848831
let _p = profile::span("handle_test_runnables_in_file");
849832

850833
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
851834
let test_runnables = snap.analysis.test_runnables_in_file(file_id)?;
852835

853836
let mut res = Vec::new();
854837
for runnable in test_runnables {
855-
let runnable = to_proto::test_info_2(&snap, runnable)?;
838+
let runnable = to_proto::runnable(&snap, runnable)?;
856839
res.push(runnable);
857840
}
858841

crates/rust-analyzer/src/lsp_ext.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,6 @@ pub struct TestInfo {
296296
pub runnable: Runnable,
297297
}
298298

299-
pub enum TestRunnablesInDb {}
300-
301-
impl Request for TestRunnablesInDb {
302-
type Params = ();
303-
type Result = Vec<TestInfo2>;
304-
const METHOD: &'static str = "rust-analyzer/testRunnablesInDb";
305-
}
306-
307299
pub enum CargoWorkspaces{}
308300

309301
impl Request for CargoWorkspaces{
@@ -316,18 +308,10 @@ pub enum TestRunnablesInFile {}
316308

317309
impl Request for TestRunnablesInFile {
318310
type Params = TestRunnablesInFileParams;
319-
type Result = Vec<TestInfo2>;
311+
type Result = Vec<Runnable>;
320312
const METHOD: &'static str = "rust-analyzer/testRunnablesInFile";
321313
}
322314

323-
// Need to find a more proper data struct for test explorer
324-
// The main purpose of such struct is to reuse `Runnable` related resource
325-
#[derive(Debug, Deserialize, Serialize)]
326-
#[serde(rename_all = "camelCase")]
327-
pub struct TestInfo2 {
328-
pub runnable: Runnable,
329-
}
330-
331315
#[derive(Serialize, Deserialize, Debug)]
332316
#[serde(rename_all = "camelCase")]
333317
pub struct InlayHintsParams {

crates/rust-analyzer/src/main_loop.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ impl GlobalState {
673673
.on::<lsp_ext::Runnables>(handlers::handle_runnables)
674674
.on::<lsp_ext::CargoWorkspaces>(handlers:: handle_cargo_workspaces)
675675
.on::<lsp_ext::TestRunnablesInFile>(handlers::handle_test_runnables_in_file)
676-
.on::<lsp_ext::TestRunnablesInDb>(handlers::handle_test_runnables_in_db)
677676
.on::<lsp_ext::RelatedTests>(handlers::handle_related_tests)
678677
.on::<lsp_ext::CodeActionRequest>(handlers::handle_code_action)
679678
.on::<lsp_ext::CodeActionResolveRequest>(handlers::handle_code_action_resolve)

crates/rust-analyzer/src/to_proto.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,15 +1174,6 @@ pub(crate) fn runnable(
11741174
})
11751175
}
11761176

1177-
pub(crate) fn test_info_2(
1178-
snap: &GlobalStateSnapshot,
1179-
runnable_data: Runnable,
1180-
) -> Cancellable<lsp_ext::TestInfo2> {
1181-
let lsp_runnable_data = runnable(snap, runnable_data)?;
1182-
1183-
Ok(lsp_ext::TestInfo2 { runnable: lsp_runnable_data })
1184-
}
1185-
11861177
pub(crate) fn code_lens(
11871178
acc: &mut Vec<lsp_types::CodeLens>,
11881179
snap: &GlobalStateSnapshot,

editors/code/src/lsp_ext.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ export const viewMir = new lc.RequestType<lc.TextDocumentPositionParams, string,
6868
export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>(
6969
"rust-analyzer/viewItemTree"
7070
);
71-
export const testRunnablesInDb = new lc.RequestType0<TestInfo2[], void>(
72-
"rust-analyzer/testRunnablesInDb"
73-
);
71+
7472
export const cargoWorkspaces = new lc.RequestType0<CargoMetadata[], void>(
7573
"rust-analyzer/cargoWorkspaces"
7674
);
7775

78-
export const testRunnablesInFile = new lc.RequestType<TestRunnablesInFileParams, TestInfo2[], void>(
76+
export const testRunnablesInFile = new lc.RequestType<TestRunnablesInFileParams, Runnable[], void>(
7977
"rust-analyzer/testRunnablesInFile"
8078
);
8179
export type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier };
@@ -89,9 +87,7 @@ export type ExpandedMacro = {
8987
expansion: string;
9088
};
9189
export type TestInfo = { runnable: Runnable };
92-
export type TestInfo2 = {
93-
runnable: Runnable;
94-
};
90+
9591
export type SyntaxTreeParams = {
9692
textDocument: lc.TextDocumentIdentifier;
9793
range: lc.Range | null;

editors/code/src/test_explorer/discover_and_update.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ async function updateModelByChangeOfFile(uri: vscode.Uri) {
164164
}
165165

166166
// Ensure parent is created in the test-model-tree
167-
const runnables = testInfos.map(it => new RunnableFacde(it.runnable));
167+
const runnables = testInfos.map(it => new RunnableFacde(it));
168168

169169
const testModuelRunnables = runnables.filter(it =>
170170
it.testKind === NodeKind.TestModule)
@@ -262,7 +262,7 @@ async function fetchChildrenForTestModuleNode(testModuleNode: TestModuleNode) {
262262

263263
assert(!!rawRunnables);
264264

265-
const runnables = rawRunnables.map(it => new RunnableFacde(it.runnable));
265+
const runnables = rawRunnables.map(it => new RunnableFacde(it));
266266

267267
await updateModelByRunnables(testModuleNode, runnables);
268268
}

0 commit comments

Comments
 (0)