diff --git a/clang-tools-extra/clangd/CodeComplete.h b/clang-tools-extra/clangd/CodeComplete.h --- a/clang-tools-extra/clangd/CodeComplete.h +++ b/clang-tools-extra/clangd/CodeComplete.h @@ -70,6 +70,10 @@ NeverInsert, } InsertIncludes = IncludeInsertion::IWYU; + /// Whether include insertions for Objective-C code should use #import instead + /// of #include. + bool ImportInsertions = false; + /// A visual indicator to prepend to the completion label to indicate whether /// completion result would trigger an #include insertion or not. struct IncludeInsertionIndicator { diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -264,6 +264,14 @@ "Never insert #include directives as part of code completion")), }; +opt ImportInsertions{ + "import-insertions", + cat(Features), + desc("If header insertion is enabled, add #import directives when " + "accepting code completions or fixing includes in Objective-C code"), + init(CodeCompleteOptions().ImportInsertions), +}; + opt IncludeCleanerStdlib{ "include-cleaner-stdlib", cat(Features), @@ -906,6 +914,7 @@ Opts.CodeComplete.BundleOverloads = CompletionStyle != Detailed; Opts.CodeComplete.ShowOrigins = ShowOrigins; Opts.CodeComplete.InsertIncludes = HeaderInsertion; + Opts.CodeComplete.ImportInsertions = ImportInsertions; if (!HeaderInsertionDecorators) { Opts.CodeComplete.IncludeIndicator.Insert.clear(); Opts.CodeComplete.IncludeIndicator.NoInsert.clear();