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
Add feature inspector to FML #5827
Conversation
5ef635f
to
5b7a653
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #5827 +/- ##
==========================================
- Coverage 36.99% 36.96% -0.04%
==========================================
Files 343 346 +3
Lines 33114 33289 +175
==========================================
+ Hits 12251 12304 +53
- Misses 20863 20985 +122
☔ View full report in Codecov by Sentry. |
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.
Self review/guide for reviewers.
@@ -0,0 +1,91 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public |
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.
This code has been reviewed before; this moves it all into a file called client/descriptor.rs
.
} | ||
|
||
pub fn validate_default_by_typ( | ||
&self, | ||
path: &str, | ||
type_ref: &TypeRef, | ||
default: &Value, | ||
literals: &Vec<String>, |
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.
This work in this method is to add the literals
vec, a list of tokens leading from the root to where an error is detected.
The literals vec is then reported in errors, which are then unpacked in the FmlClient
.
Several improvements suggest themselves:
- remove the
FMLError::ValidationError
from this method. Those problems are likely detected in another method. - use the
preserve_order
feature of theserde_json
, and add more to theliterals
vec. This will improve the accuracy of the error placement; however this should be done in a different issue— because it may need work in theDefaultsMerger
. - Process the invalid property detection for features here, perhaps by translating the
FeatureDef
intoObjectDef
(currently this is done inDefaultsMerger
). - Split this feature validation into a smaller more managable file/set of methods; this would make reviewing/editing the error messages easier, at the very least.
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.
Thank you so much for this explanation!! 🙏
} | ||
|
||
pub fn get_feature(&self, nm: &str) -> Option<&FeatureDef> { | ||
self.iter_feature_defs().find(|f| f.name() == nm) | ||
self.feature_defs.get(nm) |
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.
Ah. O(1) instead of O(n).
ef36cd4
to
9b3a9de
Compare
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.
I hate to ask this, but how complicated would it be to separate the change from Vec<_>
to BTreeMap<String, _>
from the rest of this? Is it better to land it all in one chunk? (I know it can be tricky and things are interconnected, but figured it was worth asking 😅 )
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.
This looks great! I would ideally like to split it up so that the refactor from Vec<_>
to BTreeMap<String, _>
is landed first, but I'm also happy to just get this going. Up to you. One little nit/question about the tests, but this LGTM 💯
pub struct FmlLoaderConfig { | ||
pub cache: Option<String>, | ||
pub refs: HashMap<String, String>, | ||
pub ref_files: Vec<String>, | ||
} | ||
|
||
impl From<FmlLoaderConfig> for LoaderConfig { | ||
fn from(value: FmlLoaderConfig) -> Self { | ||
let cwd = std::env::current_dir().expect("Current Working Directory is not set"); | ||
let cache = value.cache.map(|v| cwd.join(v)); | ||
Self { | ||
cwd, | ||
refs: value.refs.into_iter().collect(), | ||
repo_files: value.ref_files, | ||
cache_dir: cache, | ||
} | ||
} |
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.
👏
} | ||
|
||
impl FmlFeatureInspector { | ||
fn get_syntax_error(&self, string: &str) -> Result<Value, FmlEditorError> { |
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.
Awesome! get_syntax_error
and get_semantic_error
👏
} | ||
|
||
#[test] | ||
fn test_find_err() -> Result<()> { |
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.
I'm a little unsure -- is this test covering the case when there's no error to be found? What about if the path is invalid?
@@ -65,3 +70,18 @@ pub enum ClientError { | |||
} | |||
|
|||
pub type Result<T, E = FMLError> = std::result::Result<T, E>; | |||
|
|||
pub(crate) fn did_you_mean(words: HashSet<String>) -> String { |
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.
😂 👍
fm.iter_enum_defs() | ||
.map(|e| &e.name) | ||
.collect::<HashSet<&String>>() |
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.
Oh that's much prettier 🍰
} | ||
|
||
pub fn validate_default_by_typ( | ||
&self, | ||
path: &str, | ||
type_ref: &TypeRef, | ||
default: &Value, | ||
literals: &Vec<String>, |
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.
Thank you so much for this explanation!! 🙏
9b3a9de
to
c80aa06
Compare
c80aa06
to
59fa04e
Compare
59fa04e
to
2ac2d80
Compare
Fixes EXP-3793.
This PR turned out larger than I was expecting:
changed the IR ofFeatureManifest
fromVec<_>
toBTreeMap<String, _>
. This is long overdue, but I've been resisting doing it until now.FMLClient
.client.rs
intoclient/mod.rs
and associated files.find_index
method to get the (line, col) number for where the errors occur.Pull Request checklist
[ci full]
to the PR title.Branch builds: add
[firefox-android: branch-name]
to the PR title.