Skip to content

Commit 8b07e54

Browse files
authored
Merge pull request #5614 from rjmccall/dash-disable-typo-correction
Provide a frontend option to disable typo correction
2 parents 1fcd7d7 + d123345 commit 8b07e54

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ namespace swift {
4747

4848
/// \brief Disable API availability checking.
4949
bool DisableAvailabilityChecking = false;
50+
51+
/// \brief Disable typo correction.
52+
bool DisableTypoCorrection = false;
5053

5154
/// Should access control be respected?
5255
bool EnableAccessControl = true;

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def serialize_debugging_options : Flag<["-"], "serialize-debugging-options">,
116116
def autolink_library : Separate<["-"], "autolink-library">,
117117
HelpText<"Add dependent library">, Flags<[FrontendOption]>;
118118

119+
def disable_typo_correction : Flag<["-"], "disable-typo-correction">,
120+
HelpText<"Disable typo correction">;
121+
119122
} // end let Flags = [FrontendOption, NoDriverOption]
120123

121124
def debug_crash_Group : OptionGroup<"<automatic crashing options>">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
821821
= A->getOption().matches(OPT_enable_access_control);
822822
}
823823

824+
Opts.DisableTypoCorrection |= Args.hasArg(OPT_disable_typo_correction);
825+
824826
Opts.CodeCompleteInitsInPostfixExpr |=
825827
Args.hasArg(OPT_code_complete_inits_in_postfix_expr);
826828

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ void TypeChecker::performTypoCorrection(DeclContext *DC, DeclRefKind refKind,
504504
NameLookupOptions lookupOptions,
505505
LookupResult &result,
506506
unsigned maxResults) {
507+
if (getLangOpts().DisableTypoCorrection)
508+
return;
509+
507510
// Fill in a collection of the most reasonable entries.
508511
TopCollection<unsigned, ValueDecl*> entries(maxResults);
509512
auto consumer = makeDeclConsumer([&](ValueDecl *decl,

0 commit comments

Comments
 (0)