workspacer-syntax
workspacer-syntax is a utility crate in the Workspacer ecosystem that provides tools for processing and analyzing Rust source code at the syntax (AST) level. It enables you to:
-
Extract Documentation:
Use theextract_docsfunction to collect documentation comments (e.g.///and/** ... */) from a syntax node. -
Check Public Visibility:
Determine if an AST node is public via theis_node_publicfunction by examining its visibility modifiers and attributes. -
Generate Signatures:
Implement theGenerateSignaturetrait for common Rust items (functions, structs, enums, traits, type aliases, and macro rules) to produce standardized signature strings with optional documentation.
This crate is a core component for building automated interface extraction, documentation generation, and analysis tools for Rust projects.
Features
-
Documentation Extraction:
Theextract_docsfunction scans an AST node’s tokens and collects its doc comments into a single string. -
Public Visibility Check:
Theis_node_publicfunction checks if a syntax node is public by inspecting its children and attributes (including special handling for macros). -
Signature Generation:
TheGenerateSignaturetrait is implemented for various AST node types (e.g.ast::Fn,ast::Struct,ast::Trait, etc.) to generate human-readable signatures.
Installation
Add workspacer-syntax to your Cargo.toml dependencies:
[]
= "0.1.0"
Usage
Below is an example that demonstrates how to use workspacer-syntax to extract documentation and generate a signature from an AST node:
use ;
use ;
use ast;
This example assumes you have a valid SyntaxNode from the RA (Rust Analyzer) parser, and it demonstrates how to check for public visibility, extract documentation, and generate a signature for a function.
License
This project is dual-licensed under either the MIT license or the Apache License, Version 2.0, at your option.
Repository
For more information and to contribute, please visit the GitHub repository.