10000 Rust: Extend jump-to-def to include paths and `mod file;` imports by hvitved · Pull Request #19605 · github/codeql · GitHub
[go: up one dir, main page]

Skip to content

Rust: Extend jump-to-def to include paths and mod file; imports #19605

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 2 commits into from
Jun 3, 2025

Conversation

hvitved
Copy link
Contributor
@hvitved hvitved commented May 28, 2025

No description provided.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label May 28, 2025
@hvitved hvitved force-pushed the rust/jump-to-def-extensions branch from 27fd756 to d74e95f Compare May 28, 2025 11:29
@hvitved hvitved marked this pull request as ready for review May 28, 2025 12:29
@Copilot Copilot AI review requested due to automatic review settings May 28, 2025 12:29
@hvitved hvitved requested a review from a team as a code owner May 28, 2025 12:29
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.

Pull Request Overview

Adds support for resolving paths and file imports (mod file;) in Rust jump-to-definition.

  • Introduce a struct S, mod lib;, and reference in main.rs for new resolution tests
  • Update test query (Definitions.ql) to only select source uses and refresh expected results (Definitions.expected)
  • Extend internal QL libraries (PathResolution.qll, Definitions.qll) with fileImport, PathUse, FileUse, and ItemNode support

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rust/ql/test/library-tests/definitions/main.rs Add struct S, mod lib;, and a let x = S usage for path resolution testing
rust/ql/test/library-tests/definitions/Definitions.ql Filter Use to fromSource() in test query
rust/ql/test/library-tests/definitions/Definitions.expected Updated expected table to include path and file entries
rust/ql/lib/codeql/rust/internal/PathResolution.qll Added pragma[nomagic] on fileImport predicate
rust/ql/lib/codeql/rust/internal/Definitions.qll Imported PathResolution, added TItemNode, extended Definition and defined PathUse & FileUse

8000
@@ -1021,7 +1021,8 @@ private predicate pathAttrImport(Folder f, Module m, string relativePath) {
private predicate shouldAppend(Folder f, string relativePath) { pathAttrImport(f, _, relativePath) }

/** Holds if `m` is a `mod name;` item importing file `f`. */
private predicate fileImport(Module m, SourceFile f) {
pragma[nomagic]
Copy link
Preview
Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

[nitpick] After marking fileImport with pragma[nomagic], consider re-adding the private qualifier (e.g. pragma[nomagic] private predicate fileImport…) to keep its visibility scope intentional.

Suggested change
pragma[nomagic]
pragma[nomagic] private

Copilot uses AI. Check for mistakes.

@@ -3,6 +3,7 @@
* in the code viewer.
*/

private import rust
Copy link
Preview
Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

[nitpick] The private import rust line does not appear to be used by this module; you may remove it to avoid unnecessary imports.

Suggested change
private import rust

Copilot uses AI. Check for mistakes.

| main.rs:14:31:14:31 | 1 | main.rs:14:23:14:23 | 0 | format argument |
| main.rs:14:34:14:34 | 2 | main.rs:14:16:14:16 | 1 | format argument |
| main.rs:14:34:14:34 | 2 | main.rs:14:26:14:27 | {} | format argument |
| main.rs:15:40:15:42 | "x" | main.rs:15:31:15:35 | {:<5} | format argument |
Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing on main.rs lines 3 or 16?

Copy link
Contributor Author
@hvitved hvitved Jun 3, 2025

Choose a reason for hiding this comment

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

They are there, it's just the output that is confusing (def, use instead of use, def); I'll push a commit to change that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, thanks for making it clearer!

@hvitved hvitved merged commit ae4a425 into github:main Jun 3, 2025
17 checks passed
@hvitved hvitved deleted the rust/jump-to-def-extensions branch June 3, 2025 08:19
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
0