Feat: add typo suggestions to MODEL block field errors#4661
Conversation
c4b032e to
ba370d9
Compare
| extra_field_names = "'" + "', '".join(extra_fields) + "'" | ||
|
|
||
| all_fields = klass.all_fields() | ||
| close_matches = {} | ||
| for field in extra_fields: | ||
| matches = get_close_matches(field, all_fields, n=1) | ||
| if matches: | ||
| close_matches[field] = matches[0] |
There was a problem hiding this comment.
not important: This looks great to me and is a lovely bit of kit!
@izeigerman this is an example of the thing I talked about on Tuesday when I was saying building with sympathy for the "LSP"
To me, this is a perfect example of something that could be a diagnostic, e.g., if this were a structured error, we could
- Highlight it in line, e.g., under the misspelled word
- Suggest a code action that could correct the mistyped word to the 'close_match'
Actually even more than just for the LSP if you printed it correctly, you could print a link to the file with the right code line that IDE's would pick up as a link to the right file and place.
There was a problem hiding this comment.
I hear you. Though, I don't believe all the relevant information is available here—for example, the position of the field in the code. So Trey wouldn't be able to express this sympathy in the PR even if he wanted to, since he doesn't have access to the original source, only the Pydantic model object.
a304be2 to
51dc7df
Compare
Before
After