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

Commit

Permalink
fix(solidity/lint/core): fixed lint and compile issues
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSwapFeeder committed Oct 9, 2023
1 parent b4da7b9 commit de513d0
Show file tree
Hide file tree
Showing 21 changed files with 542 additions and 366 deletions.
1 change: 0 additions & 1 deletion libs/ast-extractor/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub fn extract_ast_from_content(content: &str) -> Result<syn_solidity::File, Ext
Ok(ast)
}


#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion libs/ast-extractor/src/retriever.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ pub use stmts::*;

mod block;
pub use block::*;
pub use finder::*;
pub use finder::*;
2 changes: 1 addition & 1 deletion libs/ast-extractor/src/retriever/expr_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ mod tests {
let res = retrieve_expr_call_nodes(&ast);
assert_eq!(res.len(), 1);
}
}
}
289 changes: 204 additions & 85 deletions libs/ast-extractor/src/retriever/finder.rs

Large diffs are not rendered by default.

46 changes: 29 additions & 17 deletions libs/ast-extractor/src/retriever/finder/find_node.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

/**
* find_node.rs
* Enum for all possible ast types that can be found
* author: 0xMemoryGrinder
*/

use syn_solidity::{ExprNew, ItemContract, ItemEnum, ItemFunction, VariableDeclaration, ExprCall, SolIdent, VariableDefinition, Type, Expr, Variant, ItemEvent, ItemError, Modifier, EventParameter};
use syn_solidity::{
EventParameter, Expr, ExprCall, ExprNew, ItemContract, ItemEnum, ItemError, ItemEvent,
ItemFunction, Modifier, SolIdent, Type, VariableDeclaration, VariableDefinition, Variant,
};

#[derive(Debug)]
pub enum FoundNode {
Expand All @@ -14,21 +15,39 @@ pub enum FoundNode {
ContractDefInheritance(ItemContract, Modifier),
ContractInstantiation(ItemContract, Option<ItemFunction>, ExprNew),


// Functions
FunctionDefName(ItemContract, ItemFunction),
FunctionDefParameterName(ItemContract, ItemFunction, VariableDeclaration, Option<SolIdent>),
FunctionDefParameterName(
ItemContract,
ItemFunction,
VariableDeclaration,
Option<SolIdent>,
),

// Properties/Variables/Constants
PropertyDefName(ItemContract, VariableDefinition, SolIdent),
ConstantVariableDefName(VariableDefinition, SolIdent),
VariableDefName(Option<ItemContract>, Option<ItemFunction>, VariableDeclaration, Option<SolIdent>),
VariableDefName(
Option<ItemContract>,
Option<ItemFunction>,
VariableDeclaration,
Option<SolIdent>,
),

// Types and Identifiers
TypeUsage(Option<ItemContract>, Option<ItemFunction>, Option<Expr>, Type),
TypeUsage(
Option<ItemContract>,
Option<ItemFunction>,
Option<Expr>,
Type,
),
IdentUsageCall(Option<ItemContract>, Option<ItemFunction>, ExprCall),
IdentUsageName(Option<ItemContract>, Option<ItemFunction>, Option<Expr>, SolIdent),

IdentUsageName(
Option<ItemContract>,
Option<ItemFunction>,
Option<Expr>,
SolIdent,
),

// Structs
StructDefName(Option<ItemContract>, SolIdent),
Expand All @@ -42,13 +61,9 @@ pub enum FoundNode {
ErrorDefName(Option<ItemContract>, ItemError, SolIdent),
ErrorDefParameter(Option<ItemContract>, ItemError, VariableDeclaration),



// Events
EventDefName(ItemContract, ItemEvent, SolIdent),
EventDefParameter(ItemContract, ItemEvent, EventParameter),


// Contracts
//ContractScope(ItemContract, Option<ItemFunction>, SolPath),

Expand All @@ -65,15 +80,12 @@ pub enum FoundNode {
//StructUsageName(ItemContract, Option<ItemFunction>, Expr, Type),
//StructUsageProperty(ItemContract, Option<ItemFunction>, Expr, SolIdent, Type),


// Errors
//ErrorUsageName(ItemContract, Option<ItemFunction>, ExprCall, SolIdent),


// Events
//EventUsageName(ItemContract, Option<ItemFunction>, Expr, SolIdent),


//TODO type cast
// TODO super ast node
}
}
4 changes: 1 addition & 3 deletions libs/ast-extractor/src/retriever/stmts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ struct SmtsVisitor {

impl SmtsVisitor {
pub fn new() -> Self {
Self {
stmts: Vec::new(),
}
Self { stmts: Vec::new() }
}
}

Expand Down
92 changes: 46 additions & 46 deletions libs/lsp-server-wrapper/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use std::cell::RefCell;
use crate::jsonrpc::{self};
use lsp_server::{Message, RequestId};
use lsp_types::notification::*;
use lsp_types::request::*;
use lsp_types::*;
use crate::jsonrpc::{self,};
use std::fmt::Display;
use std::rc::Weak;
use lsp_server::{Message, RequestId};
use serde::Serialize;
use serde_json::Value;
use std::cell::RefCell;
use std::fmt::Display;
use std::rc::Weak;
use tracing::error;

use crate::server::LspServer;

#[derive(Clone)]
pub(crate) struct ClientInner {
pub(crate) struct ClientInner {
server: Option<Weak<dyn LspServer>>,
id: RefCell<u32>,
}
Expand Down Expand Up @@ -60,10 +60,7 @@ impl Client {
/// immediately return `Err` with JSON-RPC error code `-32002` ([read more]).
///
/// [read more]: https://microsoft.github.io/language-server-protocol/specification#initialize
pub fn register_capability(
&self,
registrations: Vec<Registration>,
) -> jsonrpc::Result<()> {
pub fn register_capability(&self, registrations: Vec<Registration>) -> jsonrpc::Result<()> {
self.send_request::<RegisterCapability>(RegistrationParams { registrations })
}

Expand Down Expand Up @@ -311,12 +308,7 @@ impl Client {
/// # Initialization
///
/// This notification will only be sent if the server is initialized.
pub fn publish_diagnostics(
&self,
uri: Url,
diags: Vec<Diagnostic>,
version: Option<i32>,
) {
pub fn publish_diagnostics(&self, uri: Url, diags: Vec<Diagnostic>, version: Option<i32>) {
self.send_notification::<PublishDiagnostics>(PublishDiagnosticsParams::new(
uri, diags, version,
));
Expand Down Expand Up @@ -345,10 +337,7 @@ impl Client {
/// # Compatibility
///
/// This request was introduced in specification version 3.6.0.
pub fn configuration(
&self,
items: Vec<ConfigurationItem>,
) -> jsonrpc::Result<Vec<Value>> {
pub fn configuration(&self, items: Vec<ConfigurationItem>) -> jsonrpc::Result<Vec<Value>> {
self.send_request::<WorkspaceConfiguration>(ConfigurationParams { items })
}

Expand Down Expand Up @@ -388,10 +377,7 @@ impl Client {
/// immediately return `Err` with JSON-RPC error code `-32002` ([read more]).
///
/// [read more]: https://microsoft.github.io/language-server-protocol/specification#initialize
pub fn apply_edit(
&self,
edit: WorkspaceEdit,
) -> jsonrpc::Result<ApplyWorkspaceEditResponse> {
pub fn apply_edit(&self, edit: WorkspaceEdit) -> jsonrpc::Result<ApplyWorkspaceEditResponse> {
self.send_request::<ApplyWorkspaceEdit>(ApplyWorkspaceEditParams { edit, label: None })
}

Expand All @@ -401,31 +387,37 @@ impl Client {
///
/// This notification will only be sent if the server is initialized.
pub fn send_notification<N>(&self, params: N::Params)
where
N: lsp_types::notification::Notification,
where
N: lsp_types::notification::Notification,
{
let server_opt = self.inner.server.clone().unwrap().upgrade();
if server_opt.is_none() {
eprintln!("Cannot send request, server is not initialized");
return;
}
server_opt.unwrap().send(Message::Notification(
lsp_server::Notification::new(N::METHOD.to_string(), params),
));
server_opt
.unwrap()
.send(Message::Notification(lsp_server::Notification::new(
N::METHOD.to_string(),
params,
)));
}

fn send_notification_unchecked<N>(&self, params: N::Params)
where
N: lsp_types::notification::Notification,
where
N: lsp_types::notification::Notification,
{
let server_opt = self.inner.server.clone().unwrap().upgrade();
if server_opt.is_none() {
eprintln!("Cannot send request, server is not initialized");
return;
}
server_opt.unwrap().send(Message::Notification(
lsp_server::Notification::new(N::METHOD.to_string(), params),
));
server_opt
.unwrap()
.send(Message::Notification(lsp_server::Notification::new(
N::METHOD.to_string(),
params,
)));
}

/// Sends a custom request to the client.
Expand All @@ -437,32 +429,41 @@ impl Client {
///
/// [read more]: https://microsoft.github.io/language-server-protocol/specification#initialize
pub fn send_request<R>(&self, params: R::Params) -> jsonrpc::Result<R::Result>
where
R: lsp_types::request::Request,
where
R: lsp_types::request::Request,
{
let server_opt = self.inner.server.clone().unwrap().upgrade();
if server_opt.is_none() {
eprintln!("Cannot send request, server is not initialized");
return Err(jsonrpc::not_initialized_error());
}
server_opt.as_ref().unwrap().send(Message::Request(
lsp_server::Request::new(RequestId::from(self.next_request_id().to_string()), R::METHOD.to_string(), params),
));
server_opt
.as_ref()
.unwrap()
.send(Message::Request(lsp_server::Request::new(
RequestId::from(self.next_request_id().to_string()),
R::METHOD.to_string(),
params,
)));
Err(jsonrpc::not_initialized_error())
}

fn send_request_unchecked<R>(&self, params: R::Params) -> jsonrpc::Result<R::Result>
where
R: lsp_types::request::Request,
where
R: lsp_types::request::Request,
{
let server_opt = self.inner.server.clone().unwrap().upgrade();
if server_opt.is_none() {
eprintln!("Cannot send request, server is not initialized");
return Err(jsonrpc::not_initialized_error());
}
server_opt.unwrap().send(Message::Request(
lsp_server::Request::new(RequestId::from(self.next_request_id().to_string()), R::METHOD.to_string(), params),
));
server_opt
.unwrap()
.send(Message::Request(lsp_server::Request::new(
RequestId::from(self.next_request_id().to_string()),
R::METHOD.to_string(),
params,
)));
Err(jsonrpc::not_initialized_error())
}
}
Expand All @@ -477,5 +478,4 @@ impl Client {
}
id
}

}
}
2 changes: 1 addition & 1 deletion libs/lsp-server-wrapper/src/jsonrpc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod error;

pub(crate) use self::error::not_initialized_error;
pub use self::error::{Error, ErrorCode, Result};
pub use self::error::{Error, ErrorCode, Result};
6 changes: 3 additions & 3 deletions libs/lsp-server-wrapper/src/jsonrpc/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl Error {

/// Creates a new "invalid params" error (`-32602`).
pub fn invalid_params<M>(message: M) -> Self
where
M: Into<Cow<'static, str>>,
where
M: Into<Cow<'static, str>>,
{
Error {
code: ErrorCode::InvalidParams,
Expand Down Expand Up @@ -214,4 +214,4 @@ mod tests {
let deserialized: ErrorCode = serde_json::from_str("-12345").unwrap();
assert_eq!(deserialized, ErrorCode::ServerError(-12345));
}
}
}
Loading

0 comments on commit de513d0

Please sign in to comment.