Skip to content

Commit

Permalink
Merge pull request #84 from Supercolony-net/bugfix/rust-analyzer-vs-code
Browse files Browse the repository at this point in the history
Fix rust-analyser for VSCode
  • Loading branch information
xgreenx authored Mar 12, 2022
2 parents 5b2df32 + cfdde2e commit 5ba10e6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions utils/brush_lang/proc_macros/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use quote::{
use syn::Item;

pub(crate) fn generate(_attrs: TokenStream, ink_module: TokenStream) -> TokenStream {
if internal::skip() {
return (quote! {}).into()
}
let input: TokenStream2 = ink_module.into();
let attrs: TokenStream2 = _attrs.into();
let mut module = syn::parse2::<syn::ItemMod>(input.clone()).expect("Can't parse contract module");
Expand Down
7 changes: 7 additions & 0 deletions utils/brush_lang/proc_macros/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,10 @@ pub(crate) fn extract_attr(attrs: &mut Vec<syn::Attribute>, ident: &str) -> Vec<
pub(crate) fn new_attribute(attr_stream: TokenStream2) -> syn::Attribute {
syn::parse2::<Attributes>(attr_stream).unwrap().attr()[0].clone()
}

pub(crate) const INK_PREFIX: &str = "ink_lang=";

#[inline]
pub(crate) fn skip() -> bool {
std::env::args().find(|arg| arg.contains(INK_PREFIX)).is_none()
}
11 changes: 6 additions & 5 deletions utils/brush_lang/proc_macros/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,16 @@ pub(crate) enum LockType {
/// Function returns exclusively locked file for metadata.
/// It stores file in the target folder where `ink_lang` is stored.
pub(crate) fn get_locked_file(t: LockType) -> File {
const PREFIX: &str = "ink_lang=";
use crate::internal::INK_PREFIX;
const SUFFIX: &str = "target/";

let target: String = env::args()
.find(|arg| arg.contains(PREFIX))
.expect("Unable to find PREFIX");
.find(|arg| arg.contains(INK_PREFIX))
.expect(format!("Unable to find PREFIX: {:?}", env::args()).as_str());
let target: String = target
.chars()
.skip(PREFIX.len())
.take(target.find(SUFFIX).expect("Unable to find debug/deps") - PREFIX.len() + SUFFIX.len())
.skip(INK_PREFIX.len())
.take(target.find(SUFFIX).expect("Unable to find debug/deps") - INK_PREFIX.len() + SUFFIX.len())
.collect();

let target_dir = Utf8PathBuf::from_str(target.as_str()).expect("Can't generate Path from target");
Expand Down
3 changes: 3 additions & 0 deletions utils/brush_lang/proc_macros/trait_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use syn::{
};

pub(crate) fn generate(_attrs: TokenStream, _input: TokenStream) -> TokenStream {
if crate::internal::skip() {
return (quote! {}).into()
}
let attrs: proc_macro2::TokenStream = _attrs.into();
let mut trait_item = parse_macro_input!(_input as ItemTrait);
let trait_without_ink_attrs;
Expand Down

0 comments on commit 5ba10e6

Please sign in to comment.