Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit aa1c508

Browse files
chore: ran lint and format
1 parent 18772ce commit aa1c508

File tree

6 files changed

+68
-36
lines changed

6 files changed

+68
-36
lines changed

libs/foundry-wrapper/src/compiler.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::{
22
error::Error,
33
types::ProjectCompileOutput,
4-
utils::{check_executable_argument, find_forge_executable, find_projects_paths, normalize_path},
4+
utils::{
5+
check_executable_argument, find_forge_executable, find_projects_paths, normalize_path,
6+
},
57
};
68
use std::process::Command;
79

libs/foundry-wrapper/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ pub struct Position {
8484
impl Position {
8585
pub fn from_index(idx: i32, source: &str) -> Option<Self> {
8686
let mut idx: usize = idx as usize;
87-
for (i, l) in source.split("\n").enumerate() {
88-
let line_length = l.len() + if l.ends_with("\r") { 2 } else { 1 };
87+
for (i, l) in source.split('\n').enumerate() {
88+
let line_length = l.len() + if l.ends_with('\r') { 2 } else { 1 };
8989
if idx < line_length {
9090
return Some(Self {
9191
line: i as u32,

libs/foundry-wrapper/src/utils/path.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ pub fn find_projects_paths(root_path: &str) -> Result<Vec<PathBuf>, glob::Patter
1515
}
1616

1717
pub fn normalize_path(path: &str) -> String {
18-
path.replace("\\", "/").replace("//", "/").replace("\\\\", "/")
18+
path.replace('\\', "/")
19+
.replace("//", "/")
20+
.replace("\\\\", "/")
1921
}

toolchains/solidity/core/crates/foundry-compiler-server/src/affected_files_store.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@ impl AffectedFilesStore {
2929
* @param {String} project_path Project path
3030
* @returns {Vec<String>} List of files that are not raising an error anymore
3131
*/
32-
pub fn fill_affected_files(&mut self, raised_files: Vec<String>, project_path: &str) -> Vec<String> {
32+
pub fn fill_affected_files(
33+
&mut self,
34+
raised_files: Vec<String>,
35+
project_path: &str,
36+
) -> Vec<String> {
3337
let mut affected_files = Vec::new();
3438
if let Some(project_files) = self.projects_files.get_mut(project_path) {
35-
project_files.retain(|file| !raised_files.contains(&file));
39+
project_files.retain(|file| !raised_files.contains(file));
3640
affected_files = project_files.clone();
3741
project_files.extend(raised_files);
3842
} else {
39-
self.projects_files.insert(project_path.to_string(), raised_files);
43+
self.projects_files
44+
.insert(project_path.to_string(), raised_files);
4045
}
4146
affected_files
4247
}

toolchains/solidity/core/crates/foundry-compiler-server/src/main.rs

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tower_lsp::jsonrpc::Result;
77
use tower_lsp::lsp_types::*;
88
use tower_lsp::{Client, LanguageServer, LspService, Server};
99
mod utils;
10-
use utils::{convert_severity, get_root_path, slashify_path, normalized_slash_path};
10+
use utils::{convert_severity, get_root_path, normalized_slash_path, slashify_path};
1111
mod affected_files_store;
1212
use affected_files_store::AffectedFilesStore;
1313

@@ -30,7 +30,7 @@ impl LanguageServer for Backend {
3030
self.client
3131
.log_message(MessageType::INFO, "Foundry server initializing!")
3232
.await;
33-
if let Some(root_path) = get_root_path(params.clone()) {
33+
if let Some(root_path) = get_root_path(params.clone()) {
3434
self.client
3535
.log_message(
3636
MessageType::INFO,
@@ -73,7 +73,8 @@ impl LanguageServer for Backend {
7373
format!("file opened!: {:}", params.text_document.uri),
7474
)
7575
.await;
76-
let _ = self.compile(normalized_slash_path(params.text_document.uri.path()))
76+
let _ = self
77+
.compile(normalized_slash_path(params.text_document.uri.path()))
7778
.await;
7879
}
7980

@@ -84,7 +85,8 @@ impl LanguageServer for Backend {
8485
format!("file changed!: {:}", params.text_document.uri),
8586
)
8687
.await;
87-
let _ = self.compile(normalized_slash_path(params.text_document.uri.path()))
88+
let _ = self
89+
.compile(normalized_slash_path(params.text_document.uri.path()))
8890
.await;
8991
}
9092

@@ -158,7 +160,7 @@ impl Backend {
158160
.unwrap()
159161
.to_string();
160162
self.load_workspace(folder_path).await?
161-
}
163+
}
162164
Ok(())
163165
}
164166

@@ -207,10 +209,11 @@ impl Backend {
207209

208210
for error in output.get_errors() {
209211
// Generate diagnostic from compilation error
210-
let (affected_file, diagnostic) = match self.extract_diagnostic(&error, &project_path).await {
211-
Some(diagnostic) => diagnostic,
212-
None => continue,
213-
};
212+
let (affected_file, diagnostic) =
213+
match self.extract_diagnostic(error, &project_path).await {
214+
Some(diagnostic) => diagnostic,
215+
None => continue,
216+
};
214217

215218
// Add diagnostic to the hashmap
216219
let url = match affected_file.to_str() {
@@ -224,14 +227,20 @@ impl Backend {
224227
}
225228
}
226229

227-
self.reset_not_affected_files(project_path, filepath, &raised_diagnostics).await;
230+
self.reset_not_affected_files(project_path, filepath, &raised_diagnostics)
231+
.await;
228232
for (uri, diags) in raised_diagnostics.iter() {
229233
if let Ok(url) = Url::parse(&format!("file://{}", &uri)) {
230234
self.client
231-
.publish_diagnostics(url, diags.clone(), None)
232-
.await;
235+
.publish_diagnostics(url, diags.clone(), None)
236+
.await;
233237
} else {
234-
self.client.log_message(MessageType::ERROR, format!("error, cannot parse file uri : {}", uri)).await;
238+
self.client
239+
.log_message(
240+
MessageType::ERROR,
241+
format!("error, cannot parse file uri : {}", uri),
242+
)
243+
.await;
235244
}
236245
}
237246
}
@@ -243,13 +252,19 @@ impl Backend {
243252
* @returns {Option<(PathBuf, Diagnostic)>} Diagnostic
244253
* @returns {None} If the diagnostic cannot be extracted
245254
*/
246-
async fn extract_diagnostic(&self, compilation_error: &CompilationError, project_path: &str) -> Option<(PathBuf, Diagnostic)> {
255+
async fn extract_diagnostic(
256+
&self,
257+
compilation_error: &CompilationError,
258+
project_path: &str,
259+
) -> Option<(PathBuf, Diagnostic)> {
247260
eprintln!("Compilation error: {:?}", compilation_error);
248-
let (source_content_filepath, range) =
249-
match self.extract_diagnostic_range(&project_path, compilation_error).await {
250-
Some((source_content_filepath, range)) => (source_content_filepath, range),
251-
None => return None,
252-
};
261+
let (source_content_filepath, range) = match self
262+
.extract_diagnostic_range(project_path, compilation_error)
263+
.await
264+
{
265+
Some((source_content_filepath, range)) => (source_content_filepath, range),
266+
None => return None,
267+
};
253268
let diagnostic = Diagnostic {
254269
range: Range {
255270
start: Position {
@@ -294,8 +309,11 @@ impl Backend {
294309
}
295310
None => {
296311
self.client
297-
.log_message(MessageType::ERROR, format!("error, cannot get filepath: {:?}", error))
298-
.await;
312+
.log_message(
313+
MessageType::ERROR,
314+
format!("error, cannot get filepath: {:?}", error),
315+
)
316+
.await;
299317
return None;
300318
}
301319
};
@@ -347,7 +365,9 @@ impl Backend {
347365
.affected_files
348366
.add_project_file(project_path.clone(), filepath.clone());
349367
let raised_files = raised_diagnostics.keys().cloned().collect::<Vec<String>>();
350-
let without_diagnostics = state.affected_files.fill_affected_files(raised_files, &project_path);
368+
let without_diagnostics = state
369+
.affected_files
370+
.fill_affected_files(raised_files, &project_path);
351371

352372
self.client
353373
.log_message(
@@ -358,15 +378,16 @@ impl Backend {
358378

359379
for file in without_diagnostics.iter() {
360380
if let Ok(url) = Url::parse(&format!("file://{}", &file)) {
381+
self.client.publish_diagnostics(url, vec![], None).await;
382+
} else {
361383
self.client
362-
.publish_diagnostics(url, vec![], None)
384+
.log_message(
385+
MessageType::ERROR,
386+
format!("error, cannot parse file uri : {}", file),
387+
)
363388
.await;
364-
} else {
365-
self.client.log_message(MessageType::ERROR, format!("error, cannot parse file uri : {}", file)).await;
366389
}
367390
}
368-
369-
370391
}
371392
}
372393

toolchains/solidity/core/crates/foundry-compiler-server/src/utils.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ pub fn normalize_path(path: &str) -> String {
5353
* @returns {String} Slashified path
5454
*/
5555
pub fn slashify_path(path: &str) -> String {
56-
path.replace("\\", "/").replace("\\\\", "/").replace("//", "/")
56+
path.replace('\\', "/")
57+
.replace("\\\\", "/")
58+
.replace("//", "/")
5759
}
5860

5961
pub fn normalized_slash_path(path: &str) -> String {
6062
slashify_path(&normalize_path(path))
61-
}
63+
}

0 commit comments

Comments
 (0)