-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit-id:8fdc1e29
- Loading branch information
Showing
6 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "proc-macro-server-api" | ||
version.workspace = true | ||
edition.workspace = true | ||
authors.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
readme.workspace = true | ||
repository.workspace = true | ||
|
||
[dependencies] | ||
cairo-lang-macro = { path = "../../plugins/cairo-lang-macro" } | ||
serde.workspace = true | ||
serde_json.workspace = true |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use serde::{de::DeserializeOwned, Deserialize, Serialize}; | ||
|
||
pub mod methods; | ||
|
||
pub type RequestId = u64; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct RpcResponse { | ||
pub id: RequestId, | ||
pub value: serde_json::Value, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct RpcRequest { | ||
pub id: RequestId, | ||
pub method: String, | ||
pub value: serde_json::Value, | ||
} | ||
|
||
pub trait Method { | ||
const METHOD: &str; | ||
|
||
type Params: Serialize + DeserializeOwned; | ||
type Response: Serialize + DeserializeOwned; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::Method; | ||
use serde::{Deserialize, Serialize}; | ||
use std::iter::Sum; | ||
|
||
#[derive(Debug, Default, Serialize, Deserialize)] | ||
pub struct DefinedMacrosResponse { | ||
pub attributes: Vec<String>, | ||
pub inline_macros: Vec<String>, | ||
pub derives: Vec<String>, | ||
pub executables: Vec<String>, | ||
} | ||
|
||
#[derive(Debug, Default, Serialize, Deserialize)] | ||
pub struct DefinedMacrosParams {} | ||
|
||
impl Sum for DefinedMacrosResponse { | ||
fn sum<T: IntoIterator<Item = Self>>(iter: T) -> Self { | ||
let mut iter = iter.into_iter(); | ||
|
||
let first = iter.next(); | ||
|
||
let Some(mut base) = first else { | ||
return Default::default(); | ||
}; | ||
|
||
for other in iter { | ||
base.attributes.extend(other.attributes); | ||
base.inline_macros.extend(other.inline_macros); | ||
base.derives.extend(other.derives); | ||
base.executables.extend(other.executables); | ||
} | ||
|
||
base.attributes.sort(); | ||
base.attributes.dedup(); | ||
base.inline_macros.sort(); | ||
base.inline_macros.dedup(); | ||
base.derives.sort(); | ||
base.derives.dedup(); | ||
base.executables.sort(); | ||
base.executables.dedup(); | ||
|
||
base | ||
} | ||
} | ||
|
||
pub struct DefinedMacros; | ||
|
||
impl Method for DefinedMacros { | ||
const METHOD: &'static str = "defined-macros"; | ||
|
||
type Params = DefinedMacrosParams; | ||
type Response = DefinedMacrosResponse; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use super::ProcMacroResult; | ||
use crate::Method; | ||
use cairo_lang_macro::TokenStream; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] | ||
pub struct ExpandAttributeParams { | ||
pub attr: String, | ||
pub args: TokenStream, | ||
pub item: TokenStream, | ||
} | ||
|
||
pub struct ExpandAttribute; | ||
|
||
impl Method for ExpandAttribute { | ||
const METHOD: &'static str = "expand-attribute"; | ||
|
||
type Params = ExpandAttributeParams; | ||
type Response = ProcMacroResult; | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] | ||
pub struct ExpandDeriveParams { | ||
pub derives: Vec<String>, | ||
pub item: TokenStream, | ||
} | ||
|
||
pub struct ExpandDerive; | ||
|
||
impl Method for ExpandDerive { | ||
const METHOD: &'static str = "expand-derive"; | ||
|
||
type Params = ExpandDeriveParams; | ||
type Response = ProcMacroResult; | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] | ||
pub struct ExpandInlineMacroParams { | ||
pub name: String, | ||
pub item: TokenStream, | ||
} | ||
|
||
pub struct ExpandInline; | ||
|
||
impl Method for ExpandInline { | ||
const METHOD: &'static str = "expand-inline"; | ||
|
||
type Params = ExpandInlineMacroParams; | ||
type Response = ProcMacroResult; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use cairo_lang_macro::TokenStream; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub mod defined_macros; | ||
pub mod expand; | ||
|
||
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub struct ProcMacroResult { | ||
pub token_stream: TokenStream, | ||
pub diagnostics: Vec<cairo_lang_macro::Diagnostic>, | ||
} |