llvm.org GIT mirror llvm / 24da186
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359701 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Weber 3 months ago
3 changed file(s) with 26 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
300300 unsigned Distance =
301301 CandidateRef.edit_distance(NormalizedName, /*AllowReplacements=*/true,
302302 /*MaxEditDistance=*/BestDistance);
303 if (RHS.empty() && CandidateHasDelimiter) {
304 // The Candidate ends with a = or : delimiter, but the option passed in
305 // didn't contain the delimiter (or doesn't have anything after it).
306 // In that case, penalize the correction: `-nodefaultlibs` is more
307 // likely to be a spello for `-nodefaultlib` than `-nodefaultlib:` even
308 // though both have an unmodified editing distance of 1, since the
309 // latter would need an argument.
310 ++Distance;
311 }
303312 if (Distance < BestDistance) {
304313 BestDistance = Distance;
305314 NearestString = (Candidate + RHS).str();
297297 EXPECT_EQ(1U, T.findNearest("/framb:foo", Nearest));
298298 EXPECT_EQ(Nearest, "/cramb:foo");
299299
300 // `--glormp` should have an editing distance of 1 to `--glormp=`.
301 EXPECT_EQ(1U, T.findNearest("--glormp", Nearest));
302 EXPECT_EQ(Nearest, "--glormp=");
303 EXPECT_EQ(0U, T.findNearest("--glormp=foo", Nearest));
300 // `--glormp` should have an editing distance > 0 from `--glormp=`.
301 EXPECT_GT(T.findNearest("--glorrmp", Nearest), 0U);
302 EXPECT_EQ(Nearest, "--glorrmp=");
303 EXPECT_EQ(0U, T.findNearest("--glorrmp=foo", Nearest));
304
305 // `--blurmps` should correct to `--blurmp`, not `--blurmp=`, even though
306 // both naively have an editing distance of 1.
307 EXPECT_EQ(1U, T.findNearest("--blurmps", Nearest));
308 EXPECT_EQ(Nearest, "--blurmp");
309
310 // ...but `--blurmps=foo` should correct to `--blurmp=foo`.
311 EXPECT_EQ(1U, T.findNearest("--blurmps=foo", Nearest));
312 EXPECT_EQ(Nearest, "--blurmp=foo");
304313
305314 // Flags should be included and excluded as specified.
306315 EXPECT_EQ(1U, T.findNearest("-doopf", Nearest, /*FlagsToInclude=*/OptFlag2));
3636 def Ermgh : Joined<["--"], "ermgh">, HelpText<"The ermgh option">, MetaVarName<"ERMGH">, Flags<[OptFlag1]>;
3737 def Fjormp : Flag<["--"], "fjormp">, HelpText<"The fjormp option">, Flags<[OptFlag1]>;
3838
39 def Glormp_eq : Flag<["--"], "glormp=">;
39 def Glorrmp_eq : Flag<["--"], "glorrmp=">;
40
41 def Blurmpq : Flag<["--"], "blurmp">;
42 def Blurmpq_eq : Flag<["--"], "blurmp=">;
4043
4144 def DashDash : Option<["--"], "", KIND_REMAINING_ARGS>;