Skip to content

Commit 6750527

Browse files
committed
feat: receive the image in the command
1 parent c969d2b commit 6750527

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/app/commands.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,45 +67,39 @@ impl<C> CommandExecutor<C>
6767
where
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),

src/app/lsp_server.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ async fn execute_command_scan_base_image<C: LSPClient>(
352352
return Err(Error::internal_error().with_message("line is not a u32"));
353353
};
354354

355+
let Some(image_name) = params.arguments.get(2) else {
356+
return Err(Error::internal_error().with_message("no image name was provided"));
357+
};
358+
359+
let Some(image_name) = image_name.as_str() else {
360+
return Err(Error::internal_error().with_message("image name is not a string"));
361+
};
362+
355363
let image_scanner = {
356364
let mut lock = server.component_factory.write().await;
357365
lock.image_scanner().map_err(|e| {
@@ -361,7 +369,7 @@ async fn execute_command_scan_base_image<C: LSPClient>(
361369

362370
server
363371
.command_executor
364-
.scan_image_from_file(uri, line, &image_scanner)
372+
.scan_image(uri, line, image_name, &image_scanner)
365373
.await?;
366374

367375
Ok(())

0 commit comments

Comments
 (0)