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

Commit

Permalink
chore(solidity/core/tests-positions): ran lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmemorygrinder committed Dec 6, 2023
1 parent 50f7a1f commit bef131d
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions toolchains/solidity/core/crates/tests-positions-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use get_tests_positions::{GetTestsPositionsParams, GetTestsPositionsResponse, TestContract};
use osmium_libs_solidity_ast_extractor::File;
use osmium_libs_solidity_ast_extractor::retriever::retrieve_functions_nodes;
use tower_lsp::jsonrpc::{Result, self};
use osmium_libs_solidity_ast_extractor::File;
use osmium_libs_solidity_ast_extractor::{
extract::extract_ast_from_content, retriever::retrieve_contract_nodes,
};
use tower_lsp::jsonrpc::{self, Result};
use tower_lsp::lsp_types::*;
use tower_lsp::{Client, LanguageServer, LspService, Server};
use osmium_libs_solidity_ast_extractor::{extract::extract_ast_from_content, retriever::retrieve_contract_nodes};

mod get_tests_positions;
mod utils;
Expand Down Expand Up @@ -37,18 +39,21 @@ impl Backend {
Self { client }
}

async fn get_tests_positions(&self, params: GetTestsPositionsParams) -> Result<GetTestsPositionsResponse> {
async fn get_tests_positions(
&self,
params: GetTestsPositionsParams,
) -> Result<GetTestsPositionsResponse> {
self.client
.log_message(MessageType::INFO, "Getting tests positions for file")
.await;
let res = extract_ast_from_content(&params.file_content);

if let Ok(ast) = res {
self.extract_tests_positions(ast)
self.extract_tests_positions(ast)
} else {
let err = res.unwrap_err();
eprintln!("Error: {:?}", err);
return Err(jsonrpc::Error::invalid_params(format!("Error: {:?}", err)));
Err(jsonrpc::Error::invalid_params(format!("Error: {:?}", err)))
}
}

Expand All @@ -58,11 +63,9 @@ impl Backend {
for contract in contracts {
let mut tests_ranges = vec![];
let mut functions = retrieve_functions_nodes(&contract);
let tests = functions
.iter_mut()
.filter(|f|
f.name.is_some() && f.name.as_ref().unwrap().as_string().starts_with("test")
);
let tests = functions.iter_mut().filter(|f| {
f.name.is_some() && f.name.as_ref().unwrap().as_string().starts_with("test")
});
for test in tests {
let name = match &test.name {
Some(name) => name,
Expand All @@ -75,9 +78,7 @@ impl Backend {
tests_ranges,
});
}
Ok(GetTestsPositionsResponse {
ranges,
})
Ok(GetTestsPositionsResponse { ranges })
}
}

Expand All @@ -90,4 +91,4 @@ async fn main() {
.custom_method("osmium/getTestsPositions", Backend::get_tests_positions)
.finish();
Server::new(stdin, stdout, socket).serve(service).await;
}
}

0 comments on commit bef131d

Please sign in to comment.