Skip to content

Commit 6095e00

Browse files
committed
Do not report multiple same project type multiple times for same worktree
1 parent 9097343 commit 6095e00

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

crates/client/src/telemetry.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,10 @@ impl Telemetry {
363363
updated_entries_set: &UpdatedEntriesSet,
364364
) -> Vec<String> {
365365
let mut state = self.state.lock();
366-
let mut project_names = Vec::new();
366+
let mut project_names: HashSet<String> = HashSet::new();
367367

368368
if state.worktrees_with_events_sent.contains(&worktree_id) {
369-
return project_names;
369+
return project_names.into_iter().collect();
370370
}
371371

372372
for (path, _, _) in updated_entries_set.iter() {
@@ -375,21 +375,23 @@ impl Telemetry {
375375
};
376376

377377
if file_name == "pnpm-lock.yaml" {
378-
project_names.push("pnpm".to_string());
378+
project_names.insert("pnpm".to_string());
379379
} else if file_name == "yarn.lock" {
380-
project_names.push("yarn".to_string());
380+
project_names.insert("yarn".to_string());
381381
} else if file_name == "package.json" {
382-
project_names.push("node".to_string());
382+
project_names.insert("node".to_string());
383383
} else if DOTNET_PROJECT_FILES_REGEX.is_match(file_name) {
384-
project_names.push("dotnet".to_string());
384+
project_names.insert("dotnet".to_string());
385385
}
386386
}
387387

388388
if !project_names.is_empty() {
389389
state.worktrees_with_events_sent.insert(worktree_id);
390390
}
391391

392-
project_names
392+
let mut project_names_vec: Vec<String> = project_names.into_iter().collect();
393+
project_names_vec.sort();
394+
project_names_vec
393395
}
394396

395397
fn report_event(self: &Arc<Self>, event: Event) {
@@ -753,7 +755,16 @@ mod tests {
753755
test_project_discovery_helper(telemetry.clone(), vec!["file.csproj"], vec!["dotnet"], 3);
754756
test_project_discovery_helper(telemetry.clone(), vec!["file.fsproj"], vec!["dotnet"], 4);
755757
test_project_discovery_helper(telemetry.clone(), vec!["file.vbproj"], vec!["dotnet"], 5);
756-
test_project_discovery_helper(telemetry, vec!["file.sln"], vec!["dotnet"], 6);
758+
test_project_discovery_helper(telemetry.clone(), vec!["file.sln"], vec!["dotnet"], 6);
759+
760+
// Ensure we only detect the project type once in the presence of
761+
// multiple files associated with that project type
762+
test_project_discovery_helper(
763+
telemetry,
764+
vec!["global.json", "Directory.Build.props"],
765+
vec!["dotnet"],
766+
7,
767+
);
757768
}
758769

759770
// TODO:

0 commit comments

Comments
 (0)