[clangd] Add flag to control #import include insertions
authorDavid Goldman <davg@google.com>
Tue, 6 Dec 2022 19:25:46 +0000 (14:25 -0500)
committerDavid Goldman <davg@google.com>
Mon, 9 Jan 2023 14:48:29 +0000 (09:48 -0500)
This will be disabled by default, hopefully we can enable for the next
major release.

Differential Revision: https://reviews.llvm.org/D139446

clang-tools-extra/clangd/CodeComplete.h
clang-tools-extra/clangd/tool/ClangdMain.cpp

index 44482d1..a7c1ae9 100644 (file)
@@ -70,6 +70,10 @@ struct CodeCompleteOptions {
     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 {
index 4cdfb1a..06cfdcc 100644 (file)
@@ -264,6 +264,14 @@ opt<CodeCompleteOptions::IncludeInsertion> HeaderInsertion{
             "Never insert #include directives as part of code completion")),
 };
 
+opt<bool> 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<bool> IncludeCleanerStdlib{
     "include-cleaner-stdlib",
     cat(Features),
@@ -913,6 +921,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
     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();