Rust: Extend jump-to-def to include paths and mod file; imports#19605
Rust: Extend jump-to-def to include paths and mod file; imports#19605hvitved merged 2 commits intogithub:mainfrom
mod file; imports#19605Conversation
27fd756 to
d74e95f
Compare
There was a problem hiding this comment.
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 inmain.rsfor 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) withfileImport,PathUse,FileUse, andItemNodesupport
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 |
|
|
||
| /** Holds if `m` is a `mod name;` item importing file `f`. */ | ||
| private predicate fileImport(Module m, SourceFile f) { | ||
| pragma[nomagic] |
There was a problem hiding this comment.
[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.
| pragma[nomagic] | |
| pragma[nomagic] private |
| * in the code viewer. | ||
| */ | ||
|
|
||
| private import rust |
There was a problem hiding this comment.
[nitpick] The private import rust line does not appear to be used by this module; you may remove it to avoid unnecessary imports.
| private import rust |
| | 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 | |
There was a problem hiding this comment.
Nothing on main.rs lines 3 or 16?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ah, thanks for making it clearer!
No description provided.