@@ -106,15 +106,52 @@ function processToolFile(
106106 }
107107 }
108108
109- // instantiate comments based on parsed tool findings
110- if ( toolFindings . length ) {
111- toolFindings . map ( ( result : ToolFinding ) => {
112- const newThread = commentController . createCommentThread (
113- result . uri ,
114- result . range ,
115- [ ] ,
116- ) ;
117- saveNoteComment ( newThread , result . text , true , noteList , toolName ) ;
118- } ) ;
109+ if ( ! toolFindings . length ) {
110+ vscode . window . showErrorMessage ( 'An error has ocurred while parsing the file.' ) ;
111+ return ;
112+ }
113+
114+ if ( noteList . length && identifyPotentialDuplicates ( toolName , noteList ) ) {
115+ vscode . window
116+ . showWarningMessage (
117+ `Potential duplicates. Current comments already include findings from ${ toolName } . Do you want to import findings anyway?` ,
118+ 'Yes' ,
119+ 'No' ,
120+ )
121+ . then ( ( answer ) => {
122+ if ( answer === 'Yes' ) {
123+ saveToolFindings ( toolFindings , noteList , toolName ) ;
124+ }
125+ } ) ;
126+ } else {
127+ saveToolFindings ( toolFindings , noteList , toolName ) ;
119128 }
120129}
130+
131+ function identifyPotentialDuplicates (
132+ toolName : string ,
133+ noteList : vscode . CommentThread [ ] ,
134+ ) {
135+ return noteList . some ( ( thread ) => {
136+ return thread . comments [ 0 ] . author . name === toolName ;
137+ } ) ;
138+ }
139+
140+ function saveToolFindings (
141+ toolFindings : ToolFinding [ ] ,
142+ noteList : vscode . CommentThread [ ] ,
143+ toolName : string ,
144+ ) {
145+ // instantiate comments based on parsed tool findings
146+ toolFindings . forEach ( ( toolFinding : ToolFinding ) => {
147+ const newThread = commentController . createCommentThread (
148+ toolFinding . uri ,
149+ toolFinding . range ,
150+ [ ] ,
151+ ) ;
152+ saveNoteComment ( newThread , toolFinding . text , true , noteList , toolName ) ;
153+ } ) ;
154+ vscode . window . showInformationMessage (
155+ `${ toolFindings . length } findings were imported successfully.` ,
156+ ) ;
157+ }
0 commit comments