@@ -67,45 +67,39 @@ impl<C> CommandExecutor<C>
6767where
6868 C : LSPClient ,
6969{
70- pub async fn scan_image_from_file (
70+ pub async fn scan_image (
7171 & self ,
7272 uri : & str ,
7373 line : u32 ,
74+ image_name : & str ,
7475 image_scanner : & impl ImageScanner ,
7576 ) -> Result < ( ) > {
76- let document_text = self
77- . document_database
78- . read_document_text ( uri)
79- . await
80- . ok_or_else ( || {
81- Error :: internal_error ( ) . with_message ( "unable to obtain document to scan" )
82- } ) ?;
83-
84- let image_for_selected_line =
85- self . image_from_line ( line, & document_text) . ok_or_else ( || {
86- Error :: parse_error ( ) . with_message ( format ! (
87- "unable to retrieve image for the selected line: {line}"
88- ) )
89- } ) ?;
90-
9177 self . show_message (
9278 MessageType :: INFO ,
93- format ! ( "Starting scan of {image_for_selected_line }..." ) . as_str ( ) ,
79+ format ! ( "Starting scan of {image_name }..." ) . as_str ( ) ,
9480 )
9581 . await ;
9682
9783 let scan_result = image_scanner
98- . scan_image ( image_for_selected_line )
84+ . scan_image ( image_name )
9985 . await
10086 . map_err ( |e| Error :: internal_error ( ) . with_message ( e. to_string ( ) ) ) ?;
10187
10288 self . show_message (
10389 MessageType :: INFO ,
104- format ! ( "Finished scan of {image_for_selected_line }." ) . as_str ( ) ,
90+ format ! ( "Finished scan of {image_name }." ) . as_str ( ) ,
10591 )
10692 . await ;
10793
10894 let diagnostic = {
95+ let document_text = self
96+ . document_database
97+ . read_document_text ( uri)
98+ . await
99+ . ok_or_else ( || {
100+ Error :: internal_error ( ) . with_message ( "unable to obtain document to scan" )
101+ } ) ?;
102+
109103 let range_for_selected_line = Range :: new (
110104 Position :: new ( line, 0 ) ,
111105 Position :: new (
@@ -128,7 +122,7 @@ where
128122 if scan_result. has_vulnerabilities ( ) {
129123 diagnostic. message = format ! (
130124 "Vulnerabilities found for {}: {} Critical, {} High, {} Medium, {} Low, {} Negligible" ,
131- image_for_selected_line ,
125+ image_name ,
132126 scan_result. count_vulns_of_severity( VulnSeverity :: Critical ) ,
133127 scan_result. count_vulns_of_severity( VulnSeverity :: High ) ,
134128 scan_result. count_vulns_of_severity( VulnSeverity :: Medium ) ,
0 commit comments