feat(parser): broaden typo hints for staticcall / extcall#713
Draft
augmentcode[bot] wants to merge 1 commit into
Draft
feat(parser): broaden typo hints for staticcall / extcall#713augmentcode[bot] wants to merge 1 commit into
staticcall / extcall#713augmentcode[bot] wants to merge 1 commit into
Conversation
The previous implementation only matched two literal substrings
("staticall", "staticcal") against the rendered SyntaxException, so
common misspellings such as "staticcakl", "statiocall", or any typo
of `extcall` produced no hint at all.
Replace the literal substring scan with a Levenshtein-based check
over identifier-like tokens in the error message. Any token of length
>= 4 whose Levenshtein distance to `staticcall` or `extcall` is between
1 and 2 (inclusive) now produces a "did you mean ...?" hint. This
covers single deletions, insertions, substitutions, and adjacent
transpositions for both keywords.
Reuses the existing `levenshtein` helper from
`vyper.semantics.analysis.levenshtein_utils` via a lazy import to
avoid a top-level cycle (vyper.semantics imports from vyper.ast).
staticcall / extcall
Author
|
👋 I've got this PR — here's what I'll handle for you:
Marking it ready and picking reviewers are your call — I'll leave both alone. Drop a comment anytime! |
Author
|
All blocking gates are green on |
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.
Why the existing
likely_errorstuple is so narrowvyper/ast/parse.pycurrently does this when the python parser raises aSyntaxErroron vyper source:A few observations:
staticcall(onec, or the finall). Anything else —staticcakl(insertion),statiocall(transposition),staticcll(substitution) — gets no hint.extcallis missing entirely. It is just as much a vyper keyword and just as easy to mis-type, but there is no entry for any of its typos (extcal,extcll,etcall,exctall, ...)."staticcal" in "staticcall"isTrue).What this PR does
Replaces the literal substring scan with a Levenshtein-distance check over identifier-like tokens in the error message:
re.compile(r"[A-Za-z_][A-Za-z0-9_]*").if→extcallsuggestions and avoids triggering on correct usage).staticcallandextcallusing the existinglevenshteinhelper fromvyper.semantics.analysis.levenshtein_utils."did you mean?"hint. Distance 2 was chosen because both keywords are 7+ chars long, so 2 edits comfortably cover a single deletion, insertion, substitution, or adjacent transposition without false matches on unrelated identifiers.The
levenshteinhelper is brought in via a lazy import inside the helper function —vyper.semanticsimports heavily fromvyper.ast, so a top-level import here would create a cycle. The slow path (a SyntaxError has already been raised) is the right place to absorb the import cost.Tests
Added to
vyper/tests/unit/ast/test_parser.py:test_call_keyword_typo_hintcovering 11 misspellings acrossstaticcallandextcall(deletions, insertions, substitutions, transpositions). All produce the expected hint.test_unrelated_syntax_error_has_no_call_hintconfirms that a normal syntax error (return 1 +) does not produce a spuriousstaticcall/extcallsuggestion.Full unit suite still passes:
Lint (
black,flake8,isort) is clean on the touched files.Files changed
vyper/vyper/ast/parse.py— replacedlikely_errorsblock with_suggest_call_keyword(...)helper backed by Levenshtein distance.vyper/tests/unit/ast/test_parser.py— added typo-hint coverage.