Skip to content

Commit 18be55e

Browse files
feat: IssueManager
1 parent bf7eb04 commit 18be55e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/upgrade/issueManager.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
import notificationManager from "./display/notificationManager";
5+
import type { FileIssues, UpgradeIssue } from "./type";
6+
import { normalizePath } from "./utility";
7+
8+
class IssueManager {
9+
private issuesList: Record</* filePath */ string, FileIssues> = {};
10+
11+
12+
public addIssue(pomPath: string, issue: UpgradeIssue) {
13+
const { packageId } = issue;
14+
const normalizedPath = normalizePath(pomPath);
15+
if (!this.issuesList[normalizedPath]) {
16+
this.issuesList[normalizedPath] = {};
17+
}
18+
this.issuesList[normalizedPath][packageId] = issue;
19+
this.refreshDisplay(this.issuesList[normalizedPath]);
20+
}
21+
22+
public removeIssue(pomPath: string, packageId: string) {
23+
const normalizedPath = normalizePath(pomPath);
24+
if (!this.issuesList[normalizedPath] || !this.issuesList[normalizedPath][packageId]) {
25+
return;
26+
}
27+
delete this.issuesList[normalizedPath][packageId];
28+
this.refreshDisplay(this.issuesList[normalizedPath]);
29+
}
30+
31+
public getIssues(filePath: string): FileIssues {
32+
const normalizedPath = normalizePath(filePath);
33+
return this.issuesList[normalizedPath] ?? {};
34+
}
35+
36+
private refreshDisplay(issues: FileIssues) {
37+
notificationManager.refresh(issues);
38+
}
39+
}
40+
41+
const issueManager = new IssueManager();
42+
export default issueManager;

src/upgrade/utility.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Uri } from "vscode";
12
import { UpgradeReason, type UpgradeIssue } from "./type";
23

34
export function buildMessage(issue: UpgradeIssue): string {
@@ -40,4 +41,8 @@ export function buildFixPrompt(issue: UpgradeIssue): string {
4041

4142
export function buildPackageId(groupId: string, artifactId: string): string {
4243
return `${groupId}:${artifactId}`;
44+
}
45+
46+
export function normalizePath(path: string): string {
47+
return Uri.parse(path).toString();
4348
}

0 commit comments

Comments
 (0)