diff options
author | Nico Weber <nicolasweber@gmx.de> | 2019-05-01 16:45:15 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2019-05-01 16:45:15 +0000 |
commit | c991daa5320d57bb7b0b53dee0cd5bd97aaa60a6 (patch) | |
tree | eb02a9a9dc38ae8443b8ce53af74a188fd366f38 /llvm/lib/Option | |
parent | c29d4915963251cbea47ec36a5cdaaf806944c59 (diff) | |
download | bcm5719-llvm-c991daa5320d57bb7b0b53dee0cd5bd97aaa60a6.tar.gz bcm5719-llvm-c991daa5320d57bb7b0b53dee0cd5bd97aaa60a6.zip |
Option spell checking: Penalize delimiter flags if input has no argument
If the user passes a flag like `-version` to a program, it's more likely
they mean `--version` than `-version:`, since there's no parameter
passed. Hence, give delimited arguments a penalty of 1 if the user input
doesn't contain the delimiter or no data after it.
The motivation is that with this, lld-link can suggest "--version"
instead of "-version:" for "-version" and "-nodefaultlib" instead of
"-nodefaultlib:" for "-nodefaultlibs".
Differential Revision: https://reviews.llvm.org/D61382
llvm-svn: 359701
Diffstat (limited to 'llvm/lib/Option')
-rw-r--r-- | llvm/lib/Option/OptTable.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp index 47c5f80c7d7..5833d03069f 100644 --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -301,6 +301,15 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString, unsigned Distance = CandidateRef.edit_distance(NormalizedName, /*AllowReplacements=*/true, /*MaxEditDistance=*/BestDistance); + if (RHS.empty() && CandidateHasDelimiter) { + // The Candidate ends with a = or : delimiter, but the option passed in + // didn't contain the delimiter (or doesn't have anything after it). + // In that case, penalize the correction: `-nodefaultlibs` is more + // likely to be a spello for `-nodefaultlib` than `-nodefaultlib:` even + // though both have an unmodified editing distance of 1, since the + // latter would need an argument. + ++Distance; + } if (Distance < BestDistance) { BestDistance = Distance; NearestString = (Candidate + RHS).str(); |