-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance documentation extraction capabilities for code-parser #2
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,144 @@ | ||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||
| name: parse-docs | ||||||||||||||||||||||||||||||
| description: Extract and display documentation (docstrings, JSDoc, Dart doc comments) from classes and methods using code-parser. Returns structured documentation without code bodies. | ||||||||||||||||||||||||||||||
| argument-hint: [path] [ClassName] [MethodName] | ||||||||||||||||||||||||||||||
| allowed-tools: Bash(code-parser *), Bash(jq *), Bash(ls *) | ||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Extract documentation from the codebase at `$ARGUMENTS` using code-parser. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## Parse the arguments | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| - **No arguments**: Extract all docs from current directory | ||||||||||||||||||||||||||||||
| - **One argument (path)**: Extract all docs from specified path | ||||||||||||||||||||||||||||||
| - **Two arguments (path ClassName)**: Extract docs for specific class | ||||||||||||||||||||||||||||||
| - **Three arguments (path ClassName MethodName)**: Extract docs for specific method | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## Steps | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ### 1. Run code-parser and extract docs | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||
| # All docs from path | ||||||||||||||||||||||||||||||
| code-parser ${PATH:-.} --format json | jq ' | ||||||||||||||||||||||||||||||
| .[] | { | ||||||||||||||||||||||||||||||
| file: .file, | ||||||||||||||||||||||||||||||
| language: .language, | ||||||||||||||||||||||||||||||
| classes: [.classes[] | select(.doc != null) | { | ||||||||||||||||||||||||||||||
| name: .name, | ||||||||||||||||||||||||||||||
| kind: .kind, | ||||||||||||||||||||||||||||||
| doc: .doc, | ||||||||||||||||||||||||||||||
| methods: [.methods[] | select(.doc != null) | {name, doc}] | ||||||||||||||||||||||||||||||
| }] | ||||||||||||||||||||||||||||||
| } | select(.classes | length > 0) | ||||||||||||||||||||||||||||||
| ' | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Specific class docs | ||||||||||||||||||||||||||||||
| code-parser FILE --format json | jq --arg class "$CLASSNAME" ' | ||||||||||||||||||||||||||||||
| .[0] | { | ||||||||||||||||||||||||||||||
| file: .file, | ||||||||||||||||||||||||||||||
| class: (.classes[] | select(.name == $class) | { | ||||||||||||||||||||||||||||||
| name: .name, | ||||||||||||||||||||||||||||||
| kind: .kind, | ||||||||||||||||||||||||||||||
| doc: .doc, | ||||||||||||||||||||||||||||||
| methods: [.methods[] | select(.doc != null) | {name, doc}] | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ' | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Specific method doc | ||||||||||||||||||||||||||||||
| code-parser FILE --format json | jq --arg class "$CLASSNAME" --arg method "$METHODNAME" ' | ||||||||||||||||||||||||||||||
| .[0].classes[] | select(.name == $class) | | ||||||||||||||||||||||||||||||
| .methods[] | select(.name == $method) | | ||||||||||||||||||||||||||||||
| {class: .name, method: .name, doc: .doc} | ||||||||||||||||||||||||||||||
| ' | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
Comment on lines
+49
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect field reference in method doc extraction. Line 53 creates 🐛 Proposed fix to capture class name # Specific method doc
code-parser FILE --format json | jq --arg class "$CLASSNAME" --arg method "$METHODNAME" '
- .[0].classes[] | select(.name == $class) |
- .methods[] | select(.name == $method) |
- {class: .name, method: .name, doc: .doc}
+ .[0].classes[] | select(.name == $class) |
+ . as $cls |
+ .methods[] | select(.name == $method) |
+ {class: $cls.name, method: .name, doc: .doc}
'📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ### 2. Present findings clearly | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Format the output as readable documentation: | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
| 📁 lib/services/user_service.dart (dart) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ╔═══ UserService [class] ═════════════════════════════════════════╗ | ||||||||||||||||||||||||||||||
| ║ Handles all user-related operations including ║ | ||||||||||||||||||||||||||||||
| ║ fetching, updating, and deleting users from the API. ║ | ||||||||||||||||||||||||||||||
| ║ ║ | ||||||||||||||||||||||||||||||
| ║ Methods with documentation: ║ | ||||||||||||||||||||||||||||||
| ║ • UserService() ║ | ||||||||||||||||||||||||||||||
| ║ Creates a new UserService instance ║ | ||||||||||||||||||||||||||||||
| ║ ║ | ||||||||||||||||||||||||||||||
| ║ • fetchUser(id: String) ║ | ||||||||||||||||||||||||||||||
| ║ Fetches a user by ID from the remote API. ║ | ||||||||||||||||||||||||||||||
| ║ Throws [ApiException] if user not found. ║ | ||||||||||||||||||||||||||||||
| ║ ║ | ||||||||||||||||||||||||||||||
| ║ • deleteUser(id: String) ║ | ||||||||||||||||||||||||||||||
| ║ Permanently deletes a user account. ║ | ||||||||||||||||||||||||||||||
| ╚════════════════════════════════════════════════════════════════╝ | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 📁 lib/models/user.dart (dart) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ╔═══ User [class] ════════════════════════════════════════════════╗ | ||||||||||||||||||||||||||||||
| ║ Data model representing a user in the system. ║ | ||||||||||||||||||||||||||||||
| ║ ║ | ||||||||||||||||||||||||||||||
| ║ Methods with documentation: ║ | ||||||||||||||||||||||||||||||
| ║ • fromJson(json) ║ | ||||||||||||||||||||||||||||||
| ║ Creates a User from JSON map ║ | ||||||||||||||||||||||||||||||
| ║ ║ | ||||||||||||||||||||||||||||||
| ║ • toJson() ║ | ||||||||||||||||||||||||||||||
| ║ Converts User to JSON map ║ | ||||||||||||||||||||||||||||||
| ╚════════════════════════════════════════════════════════════════╝ | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Summary: 2 files · 2 classes · 5 documented methods | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ### 3. Handle edge cases | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| - **No documentation found**: Report "No documentation comments found in specified path" | ||||||||||||||||||||||||||||||
| - **Class not found**: Report "Class 'ClassName' not found in FILE" | ||||||||||||||||||||||||||||||
| - **Method not found**: Report "Method 'MethodName' not found in class 'ClassName'" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ### 4. Optional: Generate API documentation | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| For generating markdown documentation: | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||
| code-parser ./lib --format json | jq -r ' | ||||||||||||||||||||||||||||||
| .[] | | ||||||||||||||||||||||||||||||
| "# " + .file + "\n\n" + | ||||||||||||||||||||||||||||||
| (.classes[] | | ||||||||||||||||||||||||||||||
| "## " + .name + " (" + .kind + ")\n\n" + | ||||||||||||||||||||||||||||||
| (.doc // "No documentation") + "\n\n" + | ||||||||||||||||||||||||||||||
| "### Methods\n\n" + | ||||||||||||||||||||||||||||||
| (.methods[] | | ||||||||||||||||||||||||||||||
| "#### " + .name + "\n\n" + | ||||||||||||||||||||||||||||||
| (.doc // "No documentation") + "\n" | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| ' > API_DOCS.md | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## Usage examples | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||
| # Extract all documentation from project | ||||||||||||||||||||||||||||||
| /parse-docs ./lib | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Get docs for specific class | ||||||||||||||||||||||||||||||
| /parse-docs ./lib UserService | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Get docs for specific method | ||||||||||||||||||||||||||||||
| /parse-docs ./lib UserService fetchUser | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Generate markdown API documentation | ||||||||||||||||||||||||||||||
| code-parser ./src --format json | jq -r '...' > docs/API.md | ||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## Notes | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| - Python: Extracts triple-quoted docstrings (`"""..."""` or `'''...'''`) | ||||||||||||||||||||||||||||||
| - TypeScript: Extracts JSDoc comments (`/** ... */`) | ||||||||||||||||||||||||||||||
| - Dart: Extracts doc comments (`///` or `/** ... */`) | ||||||||||||||||||||||||||||||
| - Only classes/methods with documentation are included in output | ||||||||||||||||||||||||||||||
| - Empty docstrings are treated as no documentation | ||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical:
${PATH:-.}will use system PATH variable, not the command argument.Line 23 uses
${PATH:-.}butPATHis a reserved system environment variable containing executable search paths. This will produce unexpected results. Use a different variable name or$1.🐛 Proposed fix
Or use a more descriptive variable like
${TARGET_PATH:-.}with appropriate setup.🤖 Prompt for AI Agents