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 ;
0 commit comments