Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 20a839d

Browse files
committed
#60: Prevent adding the same Rosie fix more than once
1 parent b359139 commit 20a839d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/diagnostics/diagnostics.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,22 @@ const registerFixForDocument = (
6161
range: vscode.Range,
6262
fix: RosieFix
6363
): void => {
64+
// If there is no range or fix saved for this document, save the document
6465
if (!FIXES_BY_DOCUMENT.has(documentUri)) {
6566
FIXES_BY_DOCUMENT.set(documentUri, new Map());
6667
}
68+
69+
// Query the ranges saved for this document, and if the currently inspected range is not saved
70+
// associate an empty list of fixes to it. Otherwise, add the fix for this range.
6771
const fixesForDocument = FIXES_BY_DOCUMENT.get(documentUri);
6872
if (!fixesForDocument?.has(range)) {
6973
FIXES_BY_DOCUMENT.get(documentUri)?.set(range, []);
7074
}
7175

72-
FIXES_BY_DOCUMENT.get(documentUri)?.get(range)?.push(fix);
76+
// This aims to prevent adding the same fix more than once
77+
if (!FIXES_BY_DOCUMENT.get(documentUri)?.get(range)?.includes(fix)) {
78+
FIXES_BY_DOCUMENT.get(documentUri)?.get(range)?.push(fix);
79+
}
7380
};
7481

7582
/**

0 commit comments

Comments
 (0)