This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(libs/foundry-wrapper): rework of foundry wrapper library to …
…handle foundry as external executable
- Loading branch information
1 parent
258a578
commit e43be75
Showing
13 changed files
with
382 additions
and
7,607 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
use foundry_compilers::error::SolcError; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error("Config loading error: {0}")] | ||
ConfigLoading(SolcError), | ||
#[error("Project loading error: {0}")] | ||
ProjectLoading(SolcError), | ||
|
||
#[error("Workspace loading error: {0}")] | ||
InvalidRootPath(#[from] glob::PatternError), | ||
|
||
#[error("Invalid file path: {0}")] | ||
InvalidFilePath(String), | ||
#[error("Compilation error: {0}")] | ||
CompilationError(SolcError), | ||
#[error("Unkown error: {0}")] | ||
UnkownError(#[from] SolcError), | ||
|
||
#[error("Executable error: foundry executable not found")] | ||
FoundryExecutableNotFound, | ||
|
||
#[error("Invalid foundry version: does not support --format-json")] | ||
InvalidFoundryVersion, | ||
|
||
#[error("Executable error: {0}")] | ||
ExecutableError(std::io::Error), | ||
|
||
#[error("No executable build-info file: {0}")] | ||
NoExecutableBuildInfoFile(String), | ||
|
||
#[error("Invalid json output: {0}")] | ||
InvalidJsonOutput(#[from] serde_json::Error), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,122 @@ | ||
pub(crate) mod project_compile_output; | ||
pub use project_compile_output::{ProjectCompileOutput, CompilationError, Position, Range, Severity}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub(crate) mod project_config; | ||
pub use project_config::ProjectConfig; | ||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct ProjectCompileOutput { | ||
errors: Vec<CompilationError> | ||
} | ||
|
||
pub(crate) mod project; | ||
pub use project::Project; | ||
impl ProjectCompileOutput { | ||
pub fn get_errors(&self) -> &Vec<CompilationError> { | ||
self.errors.as_ref() | ||
} | ||
} | ||
|
||
pub(crate) mod workspace_config; | ||
pub use workspace_config::WorkspaceConfig; | ||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct CompilationError { | ||
#[serde(rename = "sourceLocation")] | ||
source_location: Option<SourceLocation>, | ||
#[serde(rename = "type")] | ||
typ: String, | ||
component: String, | ||
severity: String, | ||
#[serde(rename = "errorCode")] | ||
error_code: String, | ||
message: String, | ||
#[serde(rename = "formattedMessage")] | ||
formatted_message: String, | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
struct SourceLocation { | ||
file: String, | ||
start: i32, | ||
end: i32, | ||
} | ||
|
||
impl CompilationError { | ||
pub fn get_message(&self) -> String { | ||
self.message.clone() | ||
} | ||
|
||
pub fn get_file_path(&self) -> Option<String> { | ||
Some(self.source_location.clone()?.file.clone()) | ||
} | ||
|
||
pub fn get_start_idx(&self) -> Option<i32> { | ||
Some(self.source_location.clone()?.start) | ||
} | ||
|
||
pub fn get_end_idx(&self) -> Option<i32> { | ||
Some(self.source_location.clone()?.end) | ||
} | ||
|
||
pub fn get_start_position(&self, source_content: &str) -> Option<Position> { | ||
let idx = self.get_start_idx()?; | ||
Position::from_index(idx, source_content) | ||
} | ||
|
||
pub fn get_end_position(&self, source_content: &str) -> Option<Position> { | ||
let idx = self.get_end_idx()?; | ||
Position::from_index(idx, source_content) | ||
} | ||
|
||
pub fn get_range(&self, source_content: &str) -> Option<Range> { | ||
Some(Range { | ||
start: self.get_start_position(source_content)?, | ||
end: self.get_end_position(source_content)? | ||
}) | ||
} | ||
|
||
pub fn get_severity(&self) -> Severity { | ||
self.severity.clone().into() | ||
} | ||
} | ||
|
||
/** | ||
* Position of error, 0 based indexes | ||
*/ | ||
#[derive(Clone, Debug)] | ||
pub struct Position { | ||
pub line: u32, | ||
pub column: u32 | ||
} | ||
|
||
impl Position { | ||
pub fn from_index(idx: i32, source: &str) -> Option<Self> { | ||
let mut idx: usize = idx as usize; | ||
for (i, l) in source.lines().enumerate() { | ||
if idx < l.len() { | ||
return Some(Self { | ||
line: i as u32, | ||
column: idx as u32 | ||
}) | ||
} | ||
idx -= l.len() + 1; | ||
} | ||
None | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Range { | ||
pub start: Position, | ||
pub end: Position | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum Severity { | ||
Error, | ||
Warning, | ||
Info, | ||
} | ||
|
||
impl From<String> for Severity { | ||
fn from(severity: String) -> Self { | ||
match severity { | ||
s if s.to_uppercase() == "ERROR" => Self::Error, | ||
s if s.to_uppercase() == "WARNING" => Self::Warning, | ||
s if s.to_uppercase() == "INFO" => Self::Info, | ||
_ => Self::Info | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.