Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(neon-macros): Add Channel context for async functions and this support #1075

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
# Rust
target
rls*.log

# Created by `trybuild` ui tests
wip
kjvalencik marked this conversation as resolved.
Show resolved Hide resolved
**/*~

# Node
**/node_modules
**/.DS_Store
npm-debug.log

# JS build
**/build
**/dist
cli/lib
test/cli/lib

# Neon build
**/index.node
**/artifacts.json
cli/lib
**/dist
pkgs/create-neon/create-neon-test-project
pkgs/create-neon/create-neon-manual-test-project
test/cli/lib
npm-debug.log
rls*.log

# System
**/.DS_Store
114 changes: 114 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions crates/neon-macros/src/export/function/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub(crate) struct Meta {
pub(super) name: Option<syn::LitStr>,
pub(super) json: bool,
pub(super) context: bool,
pub(super) this: bool,
}

#[derive(Default)]
Expand All @@ -28,33 +29,29 @@ impl Meta {
Ok(())
}

fn force_context(&mut self, meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
match self.kind {
Kind::Normal | Kind::AsyncFn => {}
Kind::Async => return Err(meta.error(super::ASYNC_CX_ERROR)),
Kind::Task => return Err(meta.error(super::TASK_CX_ERROR)),
}

fn force_context(&mut self, _meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
kjvalencik marked this conversation as resolved.
Show resolved Hide resolved
self.context = true;

Ok(())
}

fn force_this(&mut self, _meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
self.this = true;

Ok(())
}

fn make_async(&mut self, meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
if matches!(self.kind, Kind::AsyncFn) {
return Err(meta.error(super::ASYNC_FN_ERROR));
return Err(meta.error("`async` attribute should not be used with an `async fn`"));
}

self.kind = Kind::Async;

Ok(())
}

fn make_task(&mut self, meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
if self.context {
return Err(meta.error(super::TASK_CX_ERROR));
}

fn make_task(&mut self, _meta: syn::meta::ParseNestedMeta) -> syn::Result<()> {
self.kind = Kind::Task;

Ok(())
Expand Down Expand Up @@ -93,6 +90,10 @@ impl syn::parse::Parser for Parser {
return attr.force_context(meta);
}

if meta.path.is_ident("this") {
return attr.force_this(meta);
}

if meta.path.is_ident("async") {
return attr.make_async(meta);
}
Expand Down
Loading
Loading