-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit-id:655a951f
- Loading branch information
Showing
6 changed files
with
179 additions
and
12 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
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
20 changes: 20 additions & 0 deletions
20
crates/cairo-lang-language-server/src/lang/proc_macros/db.rs
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,7 +1,27 @@ | ||
use rustc_hash::FxHashMap; | ||
use scarb_proc_macro_server_types::methods::ProcMacroResult; | ||
use scarb_proc_macro_server_types::methods::expand::{ | ||
ExpandAttributeParams, ExpandDeriveParams, ExpandInlineMacroParams, | ||
}; | ||
|
||
use super::client::ClientStatus; | ||
|
||
#[salsa::query_group(ProcMacroDatabase)] | ||
pub trait ProcMacroGroup { | ||
#[salsa::input] | ||
fn attribute_macro_resolution(&self) -> FxHashMap<ExpandAttributeParams, ProcMacroResult>; | ||
#[salsa::input] | ||
fn derive_macro_resolution(&self) -> FxHashMap<ExpandDeriveParams, ProcMacroResult>; | ||
#[salsa::input] | ||
fn inline_macro_resolution(&self) -> FxHashMap<ExpandInlineMacroParams, ProcMacroResult>; | ||
|
||
#[salsa::input] | ||
fn proc_macro_client_status(&self) -> ClientStatus; | ||
} | ||
|
||
pub fn init_proc_macro_cache_group(db: &mut dyn ProcMacroGroup) { | ||
db.set_attribute_macro_resolution(Default::default()); | ||
db.set_derive_macro_resolution(Default::default()); | ||
db.set_inline_macro_resolution(Default::default()); | ||
db.set_proc_macro_client_status(Default::default()); | ||
} |
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,3 +1,4 @@ | ||
mod client; | ||
pub mod controller; | ||
pub mod db; | ||
mod plugins; |
63 changes: 63 additions & 0 deletions
63
crates/cairo-lang-language-server/src/lang/proc_macros/plugins/mod.rs
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,63 @@ | ||
use std::sync::Arc; | ||
|
||
use cairo_lang_defs::plugin::{InlineMacroExprPlugin, MacroPlugin}; | ||
use cairo_lang_semantic::plugin::PluginSuite; | ||
use scarb_proc_macro_server_types::methods::defined_macros::DefinedMacrosResponse; | ||
|
||
pub(crate) fn proc_macro_plugin_suite(defined_macros: DefinedMacrosResponse) -> PluginSuite { | ||
let mut plugin_suite = PluginSuite::default(); | ||
|
||
plugin_suite.add_plugin_ex(Arc::new(ProcMacroPlugin { | ||
defined_attributes: defined_macros.attributes, | ||
defined_derives: defined_macros.derives, | ||
defined_executable_attributes: defined_macros.executables, | ||
})); | ||
|
||
let inline_plugin = Arc::new(InlineProcMacroPlugin); | ||
|
||
for inline_macro in defined_macros.inline_macros { | ||
plugin_suite.add_inline_macro_plugin_ex(&inline_macro, inline_plugin.clone()); | ||
} | ||
|
||
plugin_suite | ||
} | ||
|
||
#[derive(Debug)] | ||
struct ProcMacroPlugin { | ||
defined_attributes: Vec<String>, | ||
defined_derives: Vec<String>, | ||
defined_executable_attributes: Vec<String>, | ||
} | ||
|
||
impl MacroPlugin for ProcMacroPlugin { | ||
fn generate_code( | ||
&self, | ||
_db: &dyn cairo_lang_syntax::node::db::SyntaxGroup, | ||
_item_ast: cairo_lang_syntax::node::ast::ModuleItem, | ||
_metadata: &cairo_lang_defs::plugin::MacroPluginMetadata<'_>, | ||
) -> cairo_lang_defs::plugin::PluginResult { | ||
todo!(); | ||
} | ||
|
||
fn declared_attributes(&self) -> Vec<String> { | ||
[&self.defined_attributes[..], &self.defined_executable_attributes[..]].concat() | ||
} | ||
|
||
fn declared_derives(&self) -> Vec<String> { | ||
self.defined_derives.clone() | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
struct InlineProcMacroPlugin; | ||
|
||
impl InlineMacroExprPlugin for InlineProcMacroPlugin { | ||
fn generate_code( | ||
&self, | ||
_db: &dyn cairo_lang_syntax::node::db::SyntaxGroup, | ||
_item_ast: &cairo_lang_syntax::node::ast::ExprInlineMacro, | ||
_metadata: &cairo_lang_defs::plugin::MacroPluginMetadata<'_>, | ||
) -> cairo_lang_defs::plugin::InlinePluginResult { | ||
todo!(); | ||
} | ||
} |