Simplify Ast::find_element Functions - #811
Open
InsertCreativityHere wants to merge 2 commits into
Open
Conversation
InsertCreativityHere
requested review from
externl
and
a lite review from Copilot
August 28, 2026 18:22
| @@ -546,10 +546,14 @@ mod underlying_type { | |||
| let ast = parse_for_ast(slice); | |||
|
|
|||
| // Assert | |||
Member
Author
There was a problem hiding this comment.
A couple test places were reworked slightly to keep everything under 120 and easily readable.
There was a problem hiding this comment.
Pull request overview
This PR streamlines AST element lookup APIs by removing the scope-resolving lookup and introducing a renamed, more constrained lookup method that targets user-defined symbols only (not primitives). It updates internal call sites, tests, and documentation to reflect the new API as a stepping stone toward #806 and #808 work.
Changes:
- Replaced
Ast::find_element/Ast::find_element_with_scopeusage withAst::find_symbol_by_idacross the codebase and tests. - Removed the scope-based element lookup API and standardized callers on fully-qualified IDs.
- Updated public-facing documentation (README + rustdoc) to reference the new method.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| slicec/src/ast/mod.rs | Removes find_element_with_scope, renames/tightens element lookup to find_symbol_by_id (NamedSymbol-only) and updates rustdoc references. |
| slicec/src/slice_file_converter.rs | Switches symbol lookup to find_symbol_by_id for named symbol conversion path. |
| slicec/src/diagnostics/annotated_diagnostic.rs | Uses find_symbol_by_id for resolving diagnostic scopes to entities. |
| slicec/README.md | Updates example AST lookup call to find_symbol_by_id. |
| slicec/tests/typealias_tests.rs | Migrates lookups to find_symbol_by_id in type-alias tests. |
| slicec/tests/tag_tests.rs | Migrates lookups to find_symbol_by_id in tag tests. |
| slicec/tests/structs/tags.rs | Migrates struct field lookup to find_symbol_by_id. |
| slicec/tests/structs/container.rs | Migrates struct lookup to find_symbol_by_id for container/fields assertions. |
| slicec/tests/sequence_tests.rs | Migrates type-alias lookup to find_symbol_by_id for sequence tests. |
| slicec/tests/scope_resolution_tests.rs | Migrates all field lookups to find_symbol_by_id in scope resolution tests. |
| slicec/tests/result_tests.rs | Migrates operation lookup to find_symbol_by_id in result type tests. |
| slicec/tests/primitives/mod.rs | Migrates type-alias lookup to find_symbol_by_id while still validating primitive patching behavior. |
| slicec/tests/preprocessor_tests.rs | Migrates interface/struct/operation lookups to find_symbol_by_id in preprocessor tests. |
| slicec/tests/parser_tests.rs | Migrates struct/enumerator lookups to find_symbol_by_id in parser tests. |
| slicec/tests/optional_tests.rs | Migrates all member/parameter lookups to find_symbol_by_id in optional type tests. |
| slicec/tests/module_tests.rs | Migrates module/struct lookups to find_symbol_by_id in module tests. |
| slicec/tests/interfaces/operations.rs | Migrates operation lookups to find_symbol_by_id across operation behavior tests. |
| slicec/tests/interfaces/mod.rs | Migrates interface lookups to find_symbol_by_id in interface container tests. |
| slicec/tests/interfaces/inheritance.rs | Migrates interface lookups to find_symbol_by_id in inheritance tests. |
| slicec/tests/identifier_tests.rs | Migrates identifier-related lookups to find_symbol_by_id. |
| slicec/tests/enums/container.rs | Migrates enum/enumerator/field lookups to find_symbol_by_id. |
| slicec/tests/custom_tests.rs | Migrates custom type lookup to find_symbol_by_id. |
| slicec/tests/comment_tests.rs | Migrates interface/operation/struct lookups to find_symbol_by_id in doc comment tests. |
| slicec/tests/attribute_tests.rs | Migrates operation/module/parameter lookups to find_symbol_by_id in attribute tests. |
Suppressed comments (1)
slicec/src/ast/mod.rs:158
- Same doc issue for
find_node_with_scope: the guidance to usefind_symbol_by_idis only correct for user-defined symbols. Primitive lookups should continue to usefind_node/find_node_with_scopeand matchNode::Primitive.
/// This is a low level method used for retrieving nodes from the AST directly.
/// Only use this if you need access to the node, or the pointer, holding a slice element.
///
/// If you want a reference to the Slice construct itself, use [find_symbol_by_id](Ast::find_symbol_by_id) instead.
///
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, we have 4 functions on
Astfor looking stuff up, 2 that return raw AST-nodes, and 2 that return references to Slice elements. This PR addresses the latter 2. This is a stepping stone towards fixing #806 and #808.These 2 functions were named
find_elementandfind_element_with_scope; the first took a fully-scoped ID, the 2nd works could take relative IDs. I deletedfind_element_with_scope, since it was only called byvscode-slice, and there, we can fix the callers to manually append the scope and usefind_elementinstead. And forfind_element, I restricted the types it could be used to lookup.Right now, you can lookup both primitive and user-defined types. After this PR, you can only use this function to lookup user-defined types. To signal this, I changed it's name from
find_elementtofind_symbol_by_id.Elementis the base-most thing inslicec, everything is anElement,struct,Sequence,Identifier,Primitive.Symbolis the compiler jargon term for something a user-wrote in a Slice file, so this term does not include the primitives.What's Changed
find_elementandfind_element_by_idfunctions were simplified and merged into a singlefind_symbol_by_idfunction. This can no longer be used to lookup primitive types.