Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TilakMaddy committed Feb 26, 2025
1 parent f810b5f commit 9f9682d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion aderyn_driver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn drive_and_get_results(args: Args) -> Arc<Mutex<Option<LspReport>>> {
if let Ok(report) = get_report(&cx_wrapper.contexts, &root_rel_path, detectors) {
let high_issues = report.high_issues(&file_contents);
let low_issues = report.low_issues(&file_contents);
let lsp_result = LspReport::from(low_issues, high_issues, args);
let lsp_result = LspReport::from(low_issues, high_issues, &root_rel_path);
return Arc::new(tokio::sync::Mutex::new(Some(lsp_result)));
}

Expand Down
16 changes: 6 additions & 10 deletions aderyn_driver/src/lsp_report.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::{collections::BTreeMap, path::PathBuf};

use aderyn_core::report::{HighIssues, IssueBody, IssueInstance, LowIssues};
use std::{collections::BTreeMap, path::PathBuf};
use tower_lsp::lsp_types::{Diagnostic, DiagnosticSeverity, Position, Range, Url};

use crate::driver::Args;

/// Report structure that is tailored to aid LSP
pub struct LspReport {
pub high_issues: HighIssues,
Expand All @@ -13,12 +10,12 @@ pub struct LspReport {
}

impl LspReport {
pub fn from(low_issues: LowIssues, high_issues: HighIssues, args: Args) -> Self {
pub fn from(low_issues: LowIssues, high_issues: HighIssues, root_rel_path: &PathBuf) -> Self {
fn create_diagnostic_from_issue(
args: &Args,
issue_body: &IssueBody,
instance: &IssueInstance,
severity: DiagnosticSeverity,
root_rel_path: &PathBuf,

Check failure on line 18 in aderyn_driver/src/lsp_report.rs

View workflow job for this annotation

GitHub Actions / Lints

writing `&PathBuf` instead of `&Path` involves a new object where a slice will do

Check failure on line 18 in aderyn_driver/src/lsp_report.rs

View workflow job for this annotation

GitHub Actions / Lints

writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
) -> Option<(Url, Diagnostic)> {
// Line number
let line_no = instance.line_no.checked_sub(1)?;
Expand Down Expand Up @@ -62,10 +59,9 @@ impl LspReport {
tags: None,
data: None,
};
let mut full_contract_path = PathBuf::from(args.root.clone());
let mut full_contract_path = root_rel_path.clone();
full_contract_path.push(instance.contract_path.clone());
let full_contract_path = full_contract_path.canonicalize().ok()?;

let full_contract_path_string = full_contract_path.to_string_lossy().to_string();
let file_uri = Url::parse(&format!("file://{}", &full_contract_path_string)).ok()?;

Expand All @@ -77,10 +73,10 @@ impl LspReport {
for issue_body in &high_issues.issues {
for instance in &issue_body.instances {
let Some((file_url, diagnostic)) = create_diagnostic_from_issue(
&args,
issue_body,
instance,
DiagnosticSeverity::WARNING,
root_rel_path,
) else {
continue;
};
Expand All @@ -94,10 +90,10 @@ impl LspReport {
for issue_body in &low_issues.issues {
for instance in &issue_body.instances {
let Some((file_url, diagnostic)) = create_diagnostic_from_issue(
&args,
issue_body,
instance,
DiagnosticSeverity::INFORMATION,
root_rel_path,
) else {
continue;
};
Expand Down

0 comments on commit 9f9682d

Please sign in to comment.