-
Notifications
You must be signed in to change notification settings - Fork 313
feature(psl): Support ignore directives on values in enums #5648
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: main
Are you sure you want to change the base?
Changes from all commits
5ff459d
034f331
2f78759
d07d39a
ad072b5
9b338a2
abdd099
41ac5ee
b6d36b2
22bae69
f912874
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 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ use psl::schema_ast::ast::{self, FieldArity}; | |||||||||||||||||||||||||||||||
| pub(crate) trait DatamodelAssert<'a> { | ||||||||||||||||||||||||||||||||
| fn assert_has_model(&'a self, name: &str) -> walkers::ModelWalker<'a>; | ||||||||||||||||||||||||||||||||
| fn assert_has_type(&'a self, name: &str) -> walkers::CompositeTypeWalker<'a>; | ||||||||||||||||||||||||||||||||
| fn assert_has_enum(&'a self, name: &str) -> walkers::EnumWalker<'a>; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| pub(crate) trait WarningAsserts { | ||||||||||||||||||||||||||||||||
|
|
@@ -139,6 +140,14 @@ impl<'a> DatamodelAssert<'a> for psl::ValidatedSchema { | |||||||||||||||||||||||||||||||
| .find(|m| m.name() == name) | ||||||||||||||||||||||||||||||||
| .expect("Type {name} not found") | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| #[track_caller] | ||||||||||||||||||||||||||||||||
| fn assert_has_enum(&'a self, name: &str) -> walkers::EnumWalker<'a> { | ||||||||||||||||||||||||||||||||
| self.db | ||||||||||||||||||||||||||||||||
| .walk_enums() | ||||||||||||||||||||||||||||||||
| .find(|e| e.name() == name) | ||||||||||||||||||||||||||||||||
| .expect("Enum {name} not found") | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+143
to
+150
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. Fix the The error message uses 🐛 Proposed fix #[track_caller]
fn assert_has_enum(&'a self, name: &str) -> walkers::EnumWalker<'a> {
self.db
.walk_enums()
.find(|e| e.name() == name)
- .expect("Enum {name} not found")
+ .unwrap_or_else(|| panic!("Enum {name} not found"))
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| impl RelationFieldAssert for walkers::RelationFieldWalker<'_> { | ||||||||||||||||||||||||||||||||
|
|
@@ -792,3 +801,27 @@ impl IndexAssert for walkers::PrimaryKeyWalker<'_> { | |||||||||||||||||||||||||||||||
| self | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| pub(crate) trait EnumAssert<'a> { | ||||||||||||||||||||||||||||||||
| fn assert_has_value(&'a self, name: &str) -> walkers::EnumValueWalker<'a>; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| impl<'a> EnumAssert<'a> for walkers::EnumWalker<'a> { | ||||||||||||||||||||||||||||||||
| #[track_caller] | ||||||||||||||||||||||||||||||||
| fn assert_has_value(&'a self, name: &str) -> walkers::EnumValueWalker<'a> { | ||||||||||||||||||||||||||||||||
| self.values() | ||||||||||||||||||||||||||||||||
| .find(|v| v.name() == name) | ||||||||||||||||||||||||||||||||
| .expect("Enum value {name} not found") | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+804
to
+815
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. Fix the Same issue as 🐛 Proposed fix #[track_caller]
fn assert_has_value(&'a self, name: &str) -> walkers::EnumValueWalker<'a> {
self.values()
.find(|v| v.name() == name)
- .expect("Enum value {name} not found")
+ .unwrap_or_else(|| panic!("Enum value {name} not found"))
} |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| pub(crate) trait EnumValueAssert { | ||||||||||||||||||||||||||||||||
| fn assert_ignored(&self, ignored: bool) -> &Self; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| impl EnumValueAssert for walkers::EnumValueWalker<'_> { | ||||||||||||||||||||||||||||||||
| #[track_caller] | ||||||||||||||||||||||||||||||||
| fn assert_ignored(&self, ignored: bool) -> &Self { | ||||||||||||||||||||||||||||||||
| assert_eq!(self.is_ignored(), ignored); | ||||||||||||||||||||||||||||||||
| self | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -48,6 +48,9 @@ fn enum_to_dmmf(en: walkers::EnumWalker<'_>) -> Enum { | |||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| for enum_value in en.values() { | ||||||||||||||||||||
| if enum_value.is_ignored() { | ||||||||||||||||||||
| continue; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| enm.values.push(enum_value_to_dmmf(enum_value)); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
50
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. 🧹 Nitpick | 🔵 Trivial 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Check for test coverage of ignored enum values in DMMF rendering
# Look for `@ignore` on enum values in test files
echo "=== Checking DMMF test files for `@ignore` on enum values ==="
fd -e prisma . query-compiler/dmmf/test_files --exec grep -l '@ignore' {} \; 2>/dev/null || echo "No `@ignore` found in DMMF test files"
# Show any matches in detail
echo ""
echo "=== Detailed matches ==="
rg -n '@ignore' query-compiler/dmmf/test_files/ 2>/dev/null || echo "No matches"
# Also check for enum-related ignore tests in PSL tests
echo ""
echo "=== PSL ignore tests for enum values ==="
rg -n -A5 'ignore.*enum|enum.*ignore' psl/psl/tests/attributes/ --type rust 2>/dev/null | head -50Repository: prisma/prisma-engines Length of output: 1202 Consider using The change correctly excludes ignored enum values from DMMF output. However, other filtering operations in this file use the ♻️ Suggested refactor using `.filter()`- for enum_value in en.values() {
- if enum_value.is_ignored() {
- continue;
- }
+ for enum_value in en.values().filter(|v| !v.is_ignored()) {
enm.values.push(enum_value_to_dmmf(enum_value));
}Alternatively, restructure the entire function to match the more declarative style used elsewhere: fn enum_to_dmmf(en: walkers::EnumWalker<'_>) -> Enum {
Enum {
name: en.name().to_owned(),
values: en
.values()
.filter(|v| !v.is_ignored())
.map(enum_value_to_dmmf)
.collect(),
db_name: en.mapped_name().map(ToOwned::to_owned),
documentation: en.ast_enum().documentation().map(ToOwned::to_owned),
}
}Test coverage exists in PSL tests ( 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
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.
🧹 Nitpick | 🔵 Trivial
Consider using
FxHashSetfor consistency and performance.The file uses
rustc_hash::FxHashMap(aliased asHashMap) for other collections likemapped_values, butignored_valuesusesstd::collections::HashSet. For small integer keys likeEnumValueId,FxHashSetprovides better performance and maintains consistency with the rest of the codebase.♻️ Suggested change
Note: You'll need to add
FxHashSetto the imports at the top of the file alongsideFxHashMap.