diff --git a/remove-me-ba2314d8e5b1421b91ce.txt b/remove-me-ba2314d8e5b1421b91ce.txt deleted file mode 100644 index 6acda7cc..00000000 --- a/remove-me-ba2314d8e5b1421b91ce.txt +++ /dev/null @@ -1 +0,0 @@ -ba2314d8e5b1421b91ce diff --git a/toolchains/solidity/core/Cargo.lock b/toolchains/solidity/core/Cargo.lock index d9371176..49613805 100644 --- a/toolchains/solidity/core/Cargo.lock +++ b/toolchains/solidity/core/Cargo.lock @@ -955,7 +955,6 @@ version = "0.3.0" dependencies = [ "colored", "glob", - "once_cell", "os", "serde", "serde_derive", diff --git a/toolchains/solidity/core/crates/slither-server/Cargo.toml b/toolchains/solidity/core/crates/slither-server/Cargo.toml index 1ab3a487..12839a65 100644 --- a/toolchains/solidity/core/crates/slither-server/Cargo.toml +++ b/toolchains/solidity/core/crates/slither-server/Cargo.toml @@ -19,6 +19,5 @@ colored = "2.0.4" thiserror = "1.0.50" glob = "0.3.1" toml = "0.8.8" -once_cell = "1.19.0" tokio-utils = "0.1.2" tokio-util = "0.7.10" diff --git a/toolchains/solidity/core/crates/slither-server/src/error.rs b/toolchains/solidity/core/crates/slither-server/src/error.rs index dfadabd3..72df57d3 100644 --- a/toolchains/solidity/core/crates/slither-server/src/error.rs +++ b/toolchains/solidity/core/crates/slither-server/src/error.rs @@ -2,7 +2,7 @@ use thiserror::Error; #[derive(Error, Debug)] pub enum SlitherError { - #[error("Error while runing slither")] + #[error("Error while runing slither: {0}")] Unknown(String), #[error("Error while runing the slither command: {0}")] IoCommandError(#[from] std::io::Error), diff --git a/toolchains/solidity/core/crates/slither-server/src/main.rs b/toolchains/solidity/core/crates/slither-server/src/main.rs index 83d0ae9d..9d575e94 100644 --- a/toolchains/solidity/core/crates/slither-server/src/main.rs +++ b/toolchains/solidity/core/crates/slither-server/src/main.rs @@ -70,7 +70,10 @@ impl LanguageServer for Backend { } })); self.client - .log_message(MessageType::INFO, "Finished initializing diagnostic receiver!") + .log_message( + MessageType::INFO, + "Finished initializing diagnostic receiver!", + ) .await; let folders = params.workspace_folders; @@ -132,7 +135,6 @@ impl LanguageServer for Backend { ) .await; self.analyze_file(file.text_document.uri).await - } async fn did_open(&self, file: DidOpenTextDocumentParams) { @@ -160,21 +162,21 @@ impl Backend { async fn analyze_file(&self, file: Url) { if self.is_in_libs(file.path()).await - || self.is_in_tests(file.path()).await - || !self.is_in_src(file.path()).await - { - self.client - .log_message( - MessageType::INFO, - format!( - "File '{}' is not a source solidity code file, skipping analysis.", - file.path() - ), - ) - .await; - return; - } - self.launch_slither(file).await + || self.is_in_tests(file.path()).await + || !self.is_in_src(file.path()).await + { + self.client + .log_message( + MessageType::INFO, + format!( + "File '{}' is not a source solidity code file, skipping analysis.", + file.path() + ), + ) + .await; + return; + } + self.launch_slither(file).await } async fn is_in_libs(&self, path: &str) -> bool { @@ -202,9 +204,6 @@ impl Backend { } async fn is_in_tests(&self, path: &str) -> bool { - if path.ends_with(".t.sol") { - return true; - } let state = self.data.lock().await; for test in state.tests_paths.iter() { let fsrc = format!("/{}/", test.replace("\"", "")); diff --git a/toolchains/solidity/core/crates/slither-server/src/slither.rs b/toolchains/solidity/core/crates/slither-server/src/slither.rs index 384a9cbe..b3bff2b0 100644 --- a/toolchains/solidity/core/crates/slither-server/src/slither.rs +++ b/toolchains/solidity/core/crates/slither-server/src/slither.rs @@ -1,9 +1,8 @@ -use crate::{error::SlitherError, utils::normalize_slither_path, types::SlitherResult}; +use crate::{error::SlitherError, types::SlitherResult, utils::normalize_slither_path}; use std::process::Stdio; use tokio::{io::AsyncReadExt, process::Command}; use tower_lsp::lsp_types::Diagnostic; - pub async fn parse_slither_out(uri: &str) -> Result, SlitherError> { let mut results: Vec = Vec::new(); @@ -11,7 +10,11 @@ pub async fn parse_slither_out(uri: &str) -> Result, SlitherErro let mut output = exec_slither(uri)?; let out = match output.stdout.take() { Some(out) => out, - None => return Err(SlitherError::Unknown("Failed to get slither output pipe".to_string())), + None => { + return Err(SlitherError::Unknown( + "Failed to get slither output pipe".to_string(), + )) + } }; let mut buffer = tokio::io::BufReader::new(out); @@ -19,11 +22,10 @@ pub async fn parse_slither_out(uri: &str) -> Result, SlitherErro output.wait().await?; eprintln!("SLITHER FINISHED"); - + buffer.read_to_string(&mut dst).await?; - let json: Result = - serde_json::from_str(&dst); - + let json: Result = serde_json::from_str(&dst); + match json { Ok(json) => { for detector in json.results.detectors { @@ -39,16 +41,15 @@ pub async fn parse_slither_out(uri: &str) -> Result, SlitherErro Ok(results) } - fn exec_slither(uri: &str) -> Result { Command::new("slither") - .arg(normalize_slither_path(uri)) - .arg("--exclude") - .arg("naming-convention") - .arg("--json") - .arg("-") - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .stdin(Stdio::null()) - .spawn() + .arg(normalize_slither_path(uri)) + .arg("--exclude") + .arg("naming-convention") + .arg("--json") + .arg("-") + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .stdin(Stdio::null()) + .spawn() } diff --git a/toolchains/solidity/core/crates/slither-server/src/types.rs b/toolchains/solidity/core/crates/slither-server/src/types.rs index 9f5ad778..28550c6e 100644 --- a/toolchains/solidity/core/crates/slither-server/src/types.rs +++ b/toolchains/solidity/core/crates/slither-server/src/types.rs @@ -1,9 +1,9 @@ use serde::{Deserialize, Serialize}; -use tower_lsp::lsp_types::{Diagnostic, DiagnosticSeverity as Severity, Position, Range}; use std::vec; use tokio::sync::mpsc::{Receiver, Sender}; use tokio_util::sync::CancellationToken; use tower_lsp::lsp_types::*; +use tower_lsp::lsp_types::{Diagnostic, DiagnosticSeverity as Severity, Position, Range}; #[derive(Debug)] pub struct SlitherDiag { diff --git a/toolchains/solidity/core/crates/slither-server/src/utils.rs b/toolchains/solidity/core/crates/slither-server/src/utils.rs index 0a187531..425c9f1a 100644 --- a/toolchains/solidity/core/crates/slither-server/src/utils.rs +++ b/toolchains/solidity/core/crates/slither-server/src/utils.rs @@ -1,9 +1,8 @@ use crate::error::SlitherError; use crate::SlitherData; +use glob::glob; use std::error::Error; use std::process::Command as StdCommand; -use glob::glob; - pub fn is_slither_installed() -> bool { let output = StdCommand::new("slither").arg("--version").output(); @@ -84,12 +83,12 @@ pub fn find_foundry_toml_config(workspace: &str) -> Result { - foundry_toml_path = path.display().to_string(); - break; - } - Err(e) => eprintln!("{:?}", e), + Ok(path) => { + foundry_toml_path = path.display().to_string(); + break; } + Err(e) => eprintln!("{:?}", e), + } } if foundry_toml_path.is_empty() { return Err(Box::new(SlitherError::FoundryTomlNotFound));