Fix macros breaking auto completion in IDEs
This commit is contained in:
parent
92072ef93f
commit
3e708a0c0d
|
@ -135,7 +135,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "gmod"
|
||||
version = "12.0.0"
|
||||
version = "12.0.1"
|
||||
dependencies = [
|
||||
"cfg_table 1.0.0",
|
||||
"cstr",
|
||||
|
@ -144,7 +144,7 @@ dependencies = [
|
|||
"fn_abi",
|
||||
"fn_has_this",
|
||||
"fn_type_alias",
|
||||
"gmod-macros 2.0.0",
|
||||
"gmod-macros 2.0.1",
|
||||
"gmserverplugin",
|
||||
"lazy_static",
|
||||
"libloading",
|
||||
|
@ -165,7 +165,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "gmod-macros"
|
||||
version = "2.0.0"
|
||||
version = "2.0.1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "gmod-macros"
|
||||
version = "2.0.0"
|
||||
version = "2.0.1"
|
||||
authors = ["William Venner <william@venner.io>"]
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
|
|
@ -8,6 +8,16 @@ use proc_macro::TokenStream;
|
|||
use quote::ToTokens;
|
||||
use syn::ItemFn;
|
||||
|
||||
macro_rules! wrap_compile_error {
|
||||
($input:ident, $code:expr) => {{
|
||||
let orig_tokens = $input.clone();
|
||||
match (|| -> Result<TokenStream, syn::Error> { $code })() {
|
||||
Ok(tokens) => tokens,
|
||||
Err(_) => return orig_tokens
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
fn check_lua_function(input: &mut ItemFn) {
|
||||
assert!(input.sig.asyncness.is_none(), "Cannot be async");
|
||||
assert!(input.sig.constness.is_none(), "Cannot be const");
|
||||
|
@ -24,7 +34,8 @@ fn genericify_return(item_fn: &mut ItemFn) {
|
|||
|
||||
#[proc_macro_attribute]
|
||||
pub fn gmod13_open(_attr: TokenStream, tokens: TokenStream) -> TokenStream {
|
||||
let mut input = parse_macro_input!(tokens as ItemFn);
|
||||
wrap_compile_error!(tokens, {
|
||||
let mut input = syn::parse::<ItemFn>(tokens)?;
|
||||
|
||||
let lua_ident = format_ident!("{}", match &input.sig.inputs[0] {
|
||||
syn::FnArg::Typed(arg) => arg.pat.to_token_stream().to_string(),
|
||||
|
@ -46,12 +57,14 @@ pub fn gmod13_open(_attr: TokenStream, tokens: TokenStream) -> TokenStream {
|
|||
// Make the return type nice and dynamic
|
||||
genericify_return(&mut input);
|
||||
|
||||
input.into_token_stream().into()
|
||||
Ok(input.into_token_stream().into())
|
||||
})
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn gmod13_close(_attr: TokenStream, tokens: TokenStream) -> TokenStream {
|
||||
let mut input = parse_macro_input!(tokens as ItemFn);
|
||||
wrap_compile_error!(tokens, {
|
||||
let mut input = syn::parse::<ItemFn>(tokens)?;
|
||||
|
||||
// Make sure it's valid
|
||||
check_lua_function(&mut input);
|
||||
|
@ -72,12 +85,14 @@ pub fn gmod13_close(_attr: TokenStream, tokens: TokenStream) -> TokenStream {
|
|||
// Make the return type nice and dynamic
|
||||
genericify_return(&mut input);
|
||||
|
||||
input.into_token_stream().into()
|
||||
Ok(input.into_token_stream().into())
|
||||
})
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn lua_function(_attr: TokenStream, tokens: TokenStream) -> TokenStream {
|
||||
let mut input = parse_macro_input!(tokens as ItemFn);
|
||||
wrap_compile_error!(tokens, {
|
||||
let mut input = syn::parse::<ItemFn>(tokens)?;
|
||||
|
||||
// Make sure it's valid
|
||||
check_lua_function(&mut input);
|
||||
|
@ -85,5 +100,6 @@ pub fn lua_function(_attr: TokenStream, tokens: TokenStream) -> TokenStream {
|
|||
// Make the return type nice and dynamic
|
||||
genericify_return(&mut input);
|
||||
|
||||
input.into_token_stream().into()
|
||||
Ok(input.into_token_stream().into())
|
||||
})
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "gmod"
|
||||
version = "12.0.0"
|
||||
version = "12.0.1"
|
||||
authors = ["William Venner <william@venner.io>"]
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
@ -16,7 +16,7 @@ server-plugin = ["gmserverplugin"]
|
|||
gmcl = ["gmod-macros/gmcl"]
|
||||
|
||||
[dependencies]
|
||||
gmod-macros = { version = "2.0.0", path = "../gmod-macros" }
|
||||
gmod-macros = { version = "2.0.1", path = "../gmod-macros" }
|
||||
gmserverplugin = { version = "1", optional = true }
|
||||
|
||||
libloading = "0"
|
||||
|
|
Loading…
Reference in New Issue