1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! `unitype classes` — which declarations are the same thing?
use serde_json::json;
use super::Output;
use crate::Failure;
use crate::project::Project;
/// Shows the sets of declarations the project's links say are one concept.
pub fn run(project: &Project, out: &Output) -> Result<(), Failure> {
let classes = project.workspace.equivalence_classes();
out.result(
json!(
classes
.iter()
.map(|c| json!({
"members": c.members.iter().map(ToString::to_string).collect::<Vec<_>>(),
"lossless": c.lossless,
}))
.collect::<Vec<_>>()
),
|| {
if classes.is_empty() {
out.say("Nothing here is linked to anything yet.");
out.say("Try `unitype suggest` to see what might be.");
return;
}
for class in &classes {
out.say(format!(
"{}{}",
class.members[0],
if class.lossless {
""
} else {
" (something is lost going round)"
}
));
for member in &class.members[1..] {
out.say(format!(" = {member}"));
}
out.say("");
}
},
);
Ok(())
}