Skip to content

Rust: fix <X as Y> path extraction #18847

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

Merged
merged 3 commits into from
Feb 24, 2025
Merged

Rust: fix <X as Y> path extraction #18847

merged 3 commits into from
Feb 24, 2025

Conversation

redsun82
Copy link
Contributor

@redsun82 redsun82 commented Feb 24, 2025

This works around a quirk in rust-analyzer's AST generation machinery, where for an <X as Y> path there might be no way to directly get Y from the path segment.

This also renames that property from getPathType to getTraitTypeRepr.

This works around a quirk in rust-analyzer's AST generation machinery,
where for an `<X as Y>` path there might be no way to directly get `Y`
from the path segment.
@Copilot Copilot AI review requested due to automatic review settings February 24, 2025 09:38
@github-actions github-actions bot added the Rust Pull requests that update Rust code label Feb 24, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR fixes the extraction of types from <X as Y> paths in the Rust extractor. It introduces a dedicated function in the translator to isolate type and trait extraction logic and updates the corresponding schema and AST generation.

  • Introduces extract_types_from_path_segment in the Translator to emit type and trait representations for path segments.
  • Removes direct emission of type information from the PathSegment in generated output.
  • Updates the annotations and AST generator to align with the new type extraction strategy.

Reviewed Changes

File Description
rust/extractor/src/translate/base.rs Adds a dedicated function to extract type and trait info from path segments.
rust/schema/annotations.py Updates the PathSegment annotation to include type_repr and trait_type_repr.
rust/ast-generator/src/main.rs Refactors field extraction for several nodes and skips type-related fields for PathSegment.
rust/extractor/src/translate/generated.rs Removes direct emission of type_repr and path_type for PathSegment.

Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

rust/extractor/src/translate/base.rs:606

  • The code relies on the order of children() when extracting the type and trait nodes. Consider explicitly filtering nodes by their kind to ensure the correct type is extracted regardless of order.
if let Some(t) = type_refs.next().and_then(ast::Type::cast).and_then(|t| self.emit_type(t))

rust/ast-generator/src/main.rs:347

  • [nitpick] It might help to add a clarifying comment explaining why fields with method names 'ty' or 'path_type' for PathSegment are skipped, to aid future maintainers.
| ("PathSegment", "ty" | "path_type")  // these are broken, handling them manually

Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more

aibaars
aibaars previously approved these changes Feb 24, 2025
Copy link
Contributor

@aibaars aibaars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for looking into this.

@redsun82
Copy link
Contributor Author

@hvitved are you ok merging this with the test changes in 1bce783, and then maybe you can take care of fixing that back?

@redsun82 redsun82 requested review from hvitved and aibaars February 24, 2025 11:43
@redsun82 redsun82 merged commit 22074af into main Feb 24, 2025
16 checks passed
@redsun82 redsun82 deleted the redsun82/rust-trait-path branch February 24, 2025 14:10
@redsun82
Copy link
Contributor Author

ping after merge @hvitved 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants