Skip to content

refactor(macros): paths, parsing, and error handling - #66

Merged
MrRevillod merged 14 commits into
mainfrom
refactor/sword-macros
Oct 12, 2026
Merged

MrRevillod merged 14 commits into
mainfrom
refactor/sword-macros

Conversation

@MrRevillod

@MrRevillod MrRevillod commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Cleanup pass over sword-macros to make it easier to read and change:

  • Paths: generated code uses path! markers instead of hardcoded
    ::sword::internal::... paths.
  • Parsing: keyed attributes now use darling; positional ones stay on syn.
  • Errors: HttpError and GrpcError share the helpers in shared/errors.rs.
  • Layout: code is grouped by feature (web/, socketio/, grpc/, jobs/,
    events/) with short feature names, and axum is no longer a dependency.
  • Fixed a few codegen bugs (unit structs, missing semicolons, Arc::clone
    borrows) and added the tests/sword-events end-to-end test.

Port #[event], #[handle] and the EventHandler controller expansion to the
copy using darling parsing and path markers. #[event] now derives Clone and
Debug and rejects non-struct inputs; #[handle] returns a pin-annotated boxed
future instead of a cast. Switch ControllerStruct to accessors and align the
web/jobs expanders with them.
Port the SocketIo controller expansion and #[on] handler to the copy.
The controller registers a setup fn that wires connection/message handlers
from inventory and applies OnConnect interceptors; #[on] emits per-method
register/call fns and a HandlerRegistrar entry. Event names are validated
as non-empty. Reuse path markers and CMetaStack keys aligned with the other
kinds.
Port the Grpc controller expansion and the GrpcError derive to the copy.
The controller registers build/register fns, applies OnRequest interceptors
and honors the grpc-reflection descriptor set; GrpcError parses grpc/grpc_error
with darling, reuses the shared error helpers, and emits From<Self> for
tonic::Status with per-code tracing defaults. Reuse path markers, adding
Grpc-prefixed names to avoid clashing with the web OnRequest markers.
Gate the events/grpc/jobs/socketio/web modules and the GrpcError derive by
their feature, and allow dead_code crate-wide for now (to be narrowed per
item later). grpc-reflection now implies grpc. Each feature and the
web+grpc combination compile clean under -D warnings.
Swap the old `sword-macros` for the feature-first rewrite: keyed
attributes
now use `darling`, generated code emits real paths via `path!` markers,
`HttpError`/`GrpcError` share the error helpers, and the crate uses the
short
feature names (`web`, `socketio`, `grpc`, `jobs`, `events`) that all
dependent
crates now reference; the old `axum` dependency is gone. Wiring it into
the
workspace also fixed a few codegen bugs (unit structs, missing
semicolons,
`Arc::clone` borrows) and added the `tests/sword-events` end-to-end
test.
@MrRevillod
MrRevillod merged commit 6d823d7 into main Oct 12, 2026
9 checks passed
@MrRevillod
MrRevillod deleted the refactor/sword-macros branch October 12, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant