Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexroan committed Dec 12, 2024
2 parents 78fe9fb + 2cda3d3 commit 536d38b
Show file tree
Hide file tree
Showing 194 changed files with 7,277 additions and 8,130 deletions.
12 changes: 12 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Since version 2.23 (released in August 2019), git-blame has a feature
# to ignore or bypass certain commits.
#
# This file contains a list of commits that are not likely what you
# are looking for in a blame, such as mass reformatting or renaming.
# You can set this file as a default ignore file for blame by running
# the following command.
#
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs

# fmt: all (#3398)
748ae7fc6da5bd63f1955cb1a7b5eb6b36e0ad61
26 changes: 12 additions & 14 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ jobs:
run: |
git submodule update --init --recursive
- uses: Swatinem/rust-cache@v2
- name: Run cargo test
run: |
cargo test _by_loading_contract_directly
- uses: Swatinem/rust-cache@v2
- name: Run cargo test
run: |
Expand Down Expand Up @@ -272,23 +267,26 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
toolchain: nightly
components: rustfmt
override: true

- name: Install git submodules
- name: Run cargo fmt
run: |
git submodule update --init --recursive
cargo +nightly fmt --all --check
- name: Run cargo fmt
uses: actions-rs/cargo@v1
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
command: fmt
args: --all -- --check
profile: minimal
toolchain: stable
components: clippy
override: true


- name: Run cargo clippy
uses: actions-rs/cargo@v1
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions aderyn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aderyn"
version = "0.3.0"
version = "0.3.3"
edition = "2021"
authors = ["Cyfrin <[email protected]>"]
description = "Rust based Solidity AST analyzer"
Expand All @@ -10,7 +10,7 @@ default-run = "aderyn"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aderyn_driver = { path = "../aderyn_driver", version = "0.3.0" }
aderyn_driver = { path = "../aderyn_driver", version = "0.3.3" }
clap = { version = "4.4.6", features = ["derive"] }
reqwest = { version = "0.12.2", default-features = false, features = ["blocking", "json", "rustls-tls"] }
semver = "1.0.22"
Expand Down
29 changes: 14 additions & 15 deletions aderyn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use serde_json::Value;
use std::{fs::File, io::Write, path::PathBuf, str::FromStr};
use strum::IntoEnumIterator;

pub mod lsp;
mod panic;

pub fn create_aderyn_toml_file_at(directory: String) {
let aderyn_toml_path = PathBuf::from_str(&directory).unwrap().join("aderyn.toml");
let mut file = File::create_new(aderyn_toml_path.clone()).expect("File already exists!");
Expand All @@ -12,15 +15,11 @@ pub fn create_aderyn_toml_file_at(directory: String) {
println!("Created aderyn.toml at {}", aderyn_toml_path.display());
}

mod panic;

pub fn initialize_niceties() {
// Crash with a nice message on panic
panic::add_handler()
}

pub mod lsp;

pub fn print_detail_view(detector_name: &str) {
let all_detector_names = get_all_detectors_names();
if !all_detector_names.contains(&detector_name.to_string()) {
Expand Down Expand Up @@ -88,21 +87,21 @@ fn right_pad(s: &str, by: usize) -> String {

pub static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));

pub fn aderyn_is_currently_running_newest_version() -> Result<bool, reqwest::Error> {
pub fn aderyn_is_currently_running_newest_version() -> Option<bool> {
let client = reqwest::blocking::Client::builder()
.user_agent(APP_USER_AGENT)
.build()?;
.build()
.expect("client is unable to initialize");

let latest_version_checker = client
.get("https://api.github.com/repos/Cyfrin/aderyn/releases/latest")
.send()?;
let latest_version_checker =
client.get("https://api.github.com/repos/Cyfrin/aderyn/releases/latest").send().ok()?;

let data = latest_version_checker.json::<Value>()?;
let newest =
Version::parse(data["tag_name"].as_str().unwrap().replace('v', "").as_str()).unwrap();
let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
let data = latest_version_checker.json::<Value>().ok()?;
let version_string = data["tag_name"].as_str()?;
let newest = Version::parse(version_string.replace('v', "").as_str()).ok()?;
let current = Version::parse(env!("CARGO_PKG_VERSION")).expect("Pkg version not available");

Ok(current >= newest)
Some(current >= newest)
}

#[cfg(test)]
Expand All @@ -111,6 +110,6 @@ mod latest_version_checker_tests {

#[test]
fn can_get_latest_version_from_crate_registry() {
assert!(aderyn_is_currently_running_newest_version().is_ok())
assert!(aderyn_is_currently_running_newest_version().is_some())
}
}
55 changes: 18 additions & 37 deletions aderyn/src/lsp.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use log::{info, warn};
use notify_debouncer_full::notify::{Event, RecommendedWatcher, Result as NotifyResult};
use std::collections::HashSet;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
use tokio::runtime::Builder;
use tokio::sync::mpsc::Receiver;
use tokio::sync::Mutex;
use tower_lsp::jsonrpc::Result;
use tower_lsp::{lsp_types::*, ClientSocket};
use tower_lsp::{Client, LanguageServer, LspService, Server};
use std::{collections::HashSet, path::PathBuf, sync::Arc, time::Duration};
use tokio::{
runtime::Builder,
sync::{mpsc::Receiver, Mutex},
};
use tower_lsp::{
jsonrpc::Result, lsp_types::*, Client, ClientSocket, LanguageServer, LspService, Server,
};

use aderyn_driver::driver::{self, Args};

Expand All @@ -27,10 +25,7 @@ impl LanguageServer for LanguageServerBackend {

let code_editor = self.client.lock().await;
code_editor
.log_message(
MessageType::INFO,
"Aderyn LSP received an initialization request!",
)
.log_message(MessageType::INFO, "Aderyn LSP received an initialization request!")
.await;

Ok(InitializeResult {
Expand Down Expand Up @@ -66,9 +61,7 @@ impl LanguageServer for LanguageServerBackend {
info!("TLSP shutdown");

let code_editor = self.client.lock().await;
code_editor
.log_message(MessageType::INFO, "Aderyn LSP has been shutdown")
.await;
code_editor.log_message(MessageType::INFO, "Aderyn LSP has been shutdown").await;
Ok(())
}
}
Expand All @@ -92,7 +85,8 @@ pub fn spin_up_language_server(args: Args) {

// Block on this function
async_runtime.block_on(async {
// Channel to communicate file system changes (triggered when files are added, removed, or changed)
// Channel to communicate file system changes (triggered when files are added, removed, or
// changed)
let (tx_file_change_event, rx_file_change_event) = tokio::sync::mpsc::channel(10);

// Create the async watcher
Expand All @@ -110,10 +104,7 @@ pub fn spin_up_language_server(args: Args) {

// Watch for file changes
file_system_watcher
.watch(
PathBuf::from(args.root.clone()).as_path(),
RecursiveMode::Recursive,
)
.watch(PathBuf::from(args.root.clone()).as_path(), RecursiveMode::Recursive)
.expect("unable to watch for file changes");

// Most editor's LSP clients communicate through stdout/stdin channels. Theefore use
Expand Down Expand Up @@ -169,10 +160,7 @@ fn create_lsp_service_and_react_to_file_event(
return;
};

info!(
"sending diagnostics to client {:?}",
&diagnostics_report.diagnostics
);
info!("sending diagnostics to client {:?}", &diagnostics_report.diagnostics);
let client_mutex = guarded_client.lock().await;

for (file_uri, file_diagnostics) in &diagnostics_report.diagnostics {
Expand All @@ -182,11 +170,8 @@ fn create_lsp_service_and_react_to_file_event(
}

// Clear out the diagnostics for file which had reported errors before
let current_run_file_uris = diagnostics_report
.diagnostics
.keys()
.cloned()
.collect::<HashSet<_>>();
let current_run_file_uris =
diagnostics_report.diagnostics.keys().cloned().collect::<HashSet<_>>();

let mut seen_file_uris_mutex = seen_file_uris.lock().await;
let seen_file_uris = &mut *seen_file_uris_mutex;
Expand All @@ -195,9 +180,7 @@ fn create_lsp_service_and_react_to_file_event(
if !&current_run_file_uris.contains(seen_file_uri) {
// Clear the diagnostics for this seen file uri
// It had errors in the past, but not any more
client_mutex
.publish_diagnostics(seen_file_uri.clone(), vec![], None)
.await;
client_mutex.publish_diagnostics(seen_file_uri.clone(), vec![], None).await;
}
}

Expand Down Expand Up @@ -234,9 +217,7 @@ fn create_lsp_service_and_react_to_file_event(
}
});

LanguageServerBackend {
client: guarded_client_clone,
}
LanguageServerBackend { client: guarded_client_clone }
});
(service, socket)
}
Loading

0 comments on commit 536d38b

Please sign in to comment.