Skip to content

[clangd] Optionally Suppress Types in Completions - #200103

Open
V-FEXrt wants to merge 1 commit into
llvm:mainfrom
V-FEXrt:clangd-1252-suppress-types-in-completions
Open

V-FEXrt wants to merge 1 commit into
llvm:mainfrom
V-FEXrt:clangd-1252-suppress-types-in-completions

Conversation

@V-FEXrt

@V-FEXrt V-FEXrt commented May 28, 2026

Copy link
Copy Markdown
Contributor

Fixes clangd/clangd#1252

Adds new NamePlaceholders value to ArgumentLists that omits the type of a parameter from the completions

@V-FEXrt
V-FEXrt requested a review from HighCommander4 May 28, 2026 02:20
@llvmorg-github-actions llvmorg-github-actions Bot added clang-tools-extra clangd clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 28, 2026
@llvmorg-github-actions

llvmorg-github-actions Bot commented May 28, 2026 •

Copy link
Copy Markdown

@llvm/pr-subscribers-clangd

@llvm/pr-subscribers-clang-tools-extra

Author: Ashley Coleman (V-FEXrt)

Changes

Fixes clangd/clangd#1252

Adds new NamePlaceholders value to ArgumentLists that omits the type of a parameter from the completions


Full diff: https://github.com/llvm/llvm-project/pull/200103.diff

8 Files Affected:

  • (modified) clang-tools-extra/clangd/CodeComplete.cpp (+5-1)
  • (modified) clang-tools-extra/clangd/Config.h (+2)
  • (modified) clang-tools-extra/clangd/ConfigCompile.cpp (+2)
  • (modified) clang-tools-extra/clangd/ConfigFragment.h (+1)
  • (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+2-2)
  • (modified) clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp (+33)
  • (modified) clang/include/clang/Sema/CodeCompleteConsumer.h (+9-12)
  • (modified) clang/lib/Sema/SemaCodeComplete.cpp (+26-15)
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 9f7da6b6f8fac..7cdf04097f221 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -578,6 +578,8 @@ struct CodeCompletionBuilder {
     const bool Delim = ArgumentLists == Config::ArgumentListsPolicy::Delimiters;
     const bool Full =
         ArgumentLists == Config::ArgumentListsPolicy::FullPlaceholders ||
+        // When NamePlaceholders is set the "full" value is edited elsewhere
+        ArgumentLists == Config::ArgumentListsPolicy::NamePlaceholders ||
         (!None && !Open && !Delim); // <-- failsafe: Full is default
 
     if (IsUsingDeclaration)
@@ -1029,7 +1031,9 @@ struct CompletionRecorder : public CodeCompleteConsumer {
     // CodeCompletionResult doesn't seem to be const-correct. We own it, anyway.
     return const_cast<CodeCompletionResult &>(R).CreateCodeCompletionString(
         *CCSema, CCContext, *CCAllocator, CCTUInfo,
-        /*IncludeBriefComments=*/false);
+        /*IncludeBriefComments=*/false,
+        /*SuppressFuncParamType=*/Opts.ArgumentLists ==
+            Config::ArgumentListsPolicy::NamePlaceholders);
   }
 
 private:
diff --git a/clang-tools-extra/clangd/Config.h b/clang-tools-extra/clangd/Config.h
index 56d7ac453deeb..aa1efcd1a30b3 100644
--- a/clang-tools-extra/clangd/Config.h
+++ b/clang-tools-extra/clangd/Config.h
@@ -144,6 +144,8 @@ struct Config {
     OpenDelimiter,
     /// empty pair of delimiters "()" or "<>".
     Delimiters,
+    /// only the name of the variable
+    NamePlaceholders,
     /// full name of both type and variable.
     FullPlaceholders,
   };
diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp
index 2b41949d6d05c..5650ab99c0ac7 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -690,6 +690,8 @@ struct FragmentCompiler {
                   .map("OpenDelimiter",
                        Config::ArgumentListsPolicy::OpenDelimiter)
                   .map("Delimiters", Config::ArgumentListsPolicy::Delimiters)
+                  .map("NamePlaceholders",
+                       Config::ArgumentListsPolicy::NamePlaceholders)
                   .map("FullPlaceholders",
                        Config::ArgumentListsPolicy::FullPlaceholders)
                   .value())
diff --git a/clang-tools-extra/clangd/ConfigFragment.h b/clang-tools-extra/clangd/ConfigFragment.h
index 7604fe4e24c97..8f73d1917060f 100644
--- a/clang-tools-extra/clangd/ConfigFragment.h
+++ b/clang-tools-extra/clangd/ConfigFragment.h
@@ -339,6 +339,7 @@ struct Fragment {
     ///   None: Nothing at all
     ///   OpenDelimiter: only opening delimiter "(" or "<"
     ///   Delimiters: empty pair of delimiters "()" or "<>"
+    ///   NamePlaceholders: name of the parameters only
     ///   FullPlaceholders: full name of both type and parameter
     std::optional<Located<std::string>> ArgumentLists;
     /// Add #include directives when accepting code completions. Config
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index bd974e4c18818..732763d2b8913 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -1110,7 +1110,7 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, SymbolID ID,
   const auto *CCS = SymbolCompletion.CreateCodeCompletionString(
       *ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator,
       *CompletionTUInfo,
-      /*IncludeBriefComments*/ false);
+      /*IncludeBriefComments*/ false, /*SuppressFuncParamType=*/false);
   std::string DocComment;
   std::string Documentation;
   bool AlreadyHasDoc = S.Flags & Symbol::HasDocComment;
@@ -1181,7 +1181,7 @@ void SymbolCollector::addDefinition(const NamedDecl &ND, const Symbol &DeclSym,
     const auto *CCS = SymbolCompletion.CreateCodeCompletionString(
         *ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator,
         *CompletionTUInfo,
-        /*IncludeBriefComments*/ false);
+        /*IncludeBriefComments*/ false, /*SuppressFuncParamType=*/false);
     DocComment = getDocComment(ND.getASTContext(), SymbolCompletion,
                                /*CommentsFromHeaders=*/true);
     if (!S.Documentation.empty())
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 5808b2145965f..734ba6666763d 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -2991,6 +2991,39 @@ TEST(CompletionTest, ArgumentListsPolicy) {
     EXPECT_THAT(Results.Completions,
                 UnorderedElementsAre(AllOf(named("xfoo"), snippetSuffix("("))));
   }
+  {
+    Opts.ArgumentLists = Config::ArgumentListsPolicy::Delimiters;
+    auto Results = completions(
+        R"cpp(
+      void xfoo(int x, int y);
+      void f() { xfo^ })cpp",
+        {}, Opts);
+    EXPECT_THAT(
+        Results.Completions,
+        UnorderedElementsAre(AllOf(named("xfoo"), snippetSuffix("($0)"))));
+  }
+  {
+    Opts.ArgumentLists = Config::ArgumentListsPolicy::NamePlaceholders;
+    auto Results = completions(
+        R"cpp(
+      void xfoo(int x, int y);
+      void f() { xfo^ })cpp",
+        {}, Opts);
+    EXPECT_THAT(Results.Completions,
+                UnorderedElementsAre(
+                    AllOf(named("xfoo"), snippetSuffix("(${1:x}, ${2:y})"))));
+  }
+  {
+    Opts.ArgumentLists = Config::ArgumentListsPolicy::FullPlaceholders;
+    auto Results = completions(
+        R"cpp(
+      void xfoo(int x, int y);
+      void f() { xfo^ })cpp",
+        {}, Opts);
+    EXPECT_THAT(Results.Completions,
+                UnorderedElementsAre(AllOf(
+                    named("xfoo"), snippetSuffix("(${1:int x}, ${2:int y})"))));
+  }
 }
 
 TEST(CompletionTest, SuggestOverrides) {
diff --git a/clang/include/clang/Sema/CodeCompleteConsumer.h b/clang/include/clang/Sema/CodeCompleteConsumer.h
index c26f4e33d289c..8437f662e8b47 100644
--- a/clang/include/clang/Sema/CodeCompleteConsumer.h
+++ b/clang/include/clang/Sema/CodeCompleteConsumer.h
@@ -958,17 +958,14 @@ class CodeCompletionResult {
   ///
   /// \param Allocator The allocator that will be used to allocate the
   /// string itself.
-  CodeCompletionString *CreateCodeCompletionString(Sema &S,
-                                         const CodeCompletionContext &CCContext,
-                                           CodeCompletionAllocator &Allocator,
-                                           CodeCompletionTUInfo &CCTUInfo,
-                                           bool IncludeBriefComments);
-  CodeCompletionString *CreateCodeCompletionString(ASTContext &Ctx,
-                                                   Preprocessor &PP,
-                                         const CodeCompletionContext &CCContext,
-                                           CodeCompletionAllocator &Allocator,
-                                           CodeCompletionTUInfo &CCTUInfo,
-                                           bool IncludeBriefComments);
+  CodeCompletionString *CreateCodeCompletionString(
+      Sema &S, const CodeCompletionContext &CCContext,
+      CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo,
+      bool IncludeBriefComments, bool SuppressFuncParamType = false);
+  CodeCompletionString *CreateCodeCompletionString(
+      ASTContext &Ctx, Preprocessor &PP, const CodeCompletionContext &CCContext,
+      CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo,
+      bool IncludeBriefComments, bool SuppressFuncParamType);
   /// Creates a new code-completion string for the macro result. Similar to the
   /// above overloads, except this only requires preprocessor information.
   /// The result kind must be `RK_Macro`.
@@ -980,7 +977,7 @@ class CodeCompletionResult {
   CodeCompletionString *createCodeCompletionStringForDecl(
       Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
       bool IncludeBriefComments, const CodeCompletionContext &CCContext,
-      PrintingPolicy &Policy);
+      PrintingPolicy &Policy, bool SuppressFuncParamType);
 
   CodeCompletionString *createCodeCompletionStringForOverride(
       Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index bef5eea9ed442..ab44474238e15 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -3132,7 +3132,8 @@ static std::string formatBlockPlaceholder(
 static std::string FormatFunctionParameter(
     const PrintingPolicy &Policy, const DeclaratorDecl *Param,
     bool SuppressName = false, bool SuppressBlock = false,
-    std::optional<ArrayRef<QualType>> ObjCSubsts = std::nullopt) {
+    std::optional<ArrayRef<QualType>> ObjCSubsts = std::nullopt,
+    bool SuppressType = false) {
   // Params are unavailable in FunctionTypeLoc if the FunctionType is invalid.
   // It would be better to pass in the param Type, which is usually available.
   // But this case is rare, so just pretend we fell back to int as elsewhere.
@@ -3160,9 +3161,13 @@ static std::string FormatFunctionParameter(
       Result += Type.getAsString(Policy) + ")";
       if (Param->getIdentifier() && !SuppressName)
         Result += Param->getIdentifier()->deuglifiedName();
-    } else {
-      Type.getAsStringInternal(Result, Policy);
+      return Result;
     }
+
+    if (SuppressType)
+      return Result;
+
+    Type.getAsStringInternal(Result, Policy);
     return Result;
   }
 
@@ -3314,7 +3319,7 @@ static void AddFunctionParameterChunks(
     Preprocessor &PP, const PrintingPolicy &Policy,
     const FunctionDecl *Function, CodeCompletionBuilder &Result,
     unsigned Start = 0, bool InOptional = false, bool FunctionCanBeCall = true,
-    bool IsInDeclarationContext = false) {
+    bool IsInDeclarationContext = false, bool SuppressFuncParamType = false) {
   bool FirstParameter = true;
   bool AsInformativeChunk = !(FunctionCanBeCall || IsInDeclarationContext);
 
@@ -3353,7 +3358,9 @@ static void AddFunctionParameterChunks(
     InOptional = false;
 
     // Format the placeholder string.
-    std::string PlaceholderStr = FormatFunctionParameter(Policy, Param);
+    std::string PlaceholderStr = FormatFunctionParameter(
+        Policy, Param, /*SuppressName=*/false, /*SuppressBlock=*/false,
+        /*ObjCSubsts=*/std::nullopt, SuppressFuncParamType);
     std::string DefaultValue;
     if (Param->hasDefaultArg()) {
       if (IsInDeclarationContext)
@@ -3674,9 +3681,10 @@ static void AddTypedNameChunk(ASTContext &Context, const PrintingPolicy &Policy,
 CodeCompletionString *CodeCompletionResult::CreateCodeCompletionString(
     Sema &S, const CodeCompletionContext &CCContext,
     CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo,
-    bool IncludeBriefComments) {
+    bool IncludeBriefComments, bool SuppressFuncParamType) {
   return CreateCodeCompletionString(S.Context, S.PP, CCContext, Allocator,
-                                    CCTUInfo, IncludeBriefComments);
+                                    CCTUInfo, IncludeBriefComments,
+                                    SuppressFuncParamType);
 }
 
 CodeCompletionString *CodeCompletionResult::CreateCodeCompletionStringForMacro(
@@ -3734,7 +3742,7 @@ CodeCompletionString *CodeCompletionResult::CreateCodeCompletionStringForMacro(
 CodeCompletionString *CodeCompletionResult::CreateCodeCompletionString(
     ASTContext &Ctx, Preprocessor &PP, const CodeCompletionContext &CCContext,
     CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo,
-    bool IncludeBriefComments) {
+    bool IncludeBriefComments, bool SuppressFuncParamType) {
   if (Kind == RK_Macro)
     return CreateCodeCompletionStringForMacro(PP, Allocator, CCTUInfo);
 
@@ -3763,8 +3771,9 @@ CodeCompletionString *CodeCompletionResult::CreateCodeCompletionString(
     return Result.TakeString();
   }
   assert(Kind == RK_Declaration && "Missed a result kind?");
-  return createCodeCompletionStringForDecl(
-      PP, Ctx, Result, IncludeBriefComments, CCContext, Policy);
+  return createCodeCompletionStringForDecl(PP, Ctx, Result,
+                                           IncludeBriefComments, CCContext,
+                                           Policy, SuppressFuncParamType);
 }
 
 static void printOverrideString(const CodeCompletionString &CCS,
@@ -3791,9 +3800,10 @@ CodeCompletionResult::createCodeCompletionStringForOverride(
     Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
     bool IncludeBriefComments, const CodeCompletionContext &CCContext,
     PrintingPolicy &Policy) {
-  auto *CCS = createCodeCompletionStringForDecl(PP, Ctx, Result,
-                                                /*IncludeBriefComments=*/false,
-                                                CCContext, Policy);
+  auto *CCS = createCodeCompletionStringForDecl(
+      PP, Ctx, Result,
+      /*IncludeBriefComments=*/false, CCContext, Policy,
+      /*SuppressFuncParamType=*/false);
   std::string BeforeName;
   std::string NameAndSignature;
   // For overrides all chunks go into the result, none are informative.
@@ -3828,7 +3838,7 @@ static const NamedDecl *extractFunctorCallOperator(const NamedDecl *ND) {
 CodeCompletionString *CodeCompletionResult::createCodeCompletionStringForDecl(
     Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
     bool IncludeBriefComments, const CodeCompletionContext &CCContext,
-    PrintingPolicy &Policy) {
+    PrintingPolicy &Policy, bool SuppressFuncParamType) {
   const NamedDecl *ND = Declaration;
   Result.addParentContext(ND->getDeclContext());
 
@@ -3862,7 +3872,8 @@ CodeCompletionString *CodeCompletionResult::createCodeCompletionStringForDecl(
     AddFunctionParameterChunks(PP, Policy, Function, Result, /*Start=*/0,
                                /*InOptional=*/false,
                                /*FunctionCanBeCall=*/FunctionCanBeCall,
-                               /*IsInDeclarationContext=*/DeclaringEntity);
+                               /*IsInDeclarationContext=*/DeclaringEntity,
+                               SuppressFuncParamType);
     if (InsertParameters)
       Result.AddChunk(CodeCompletionString::CK_RightParen);
     else

*CCSema, CCContext, *CCAllocator, CCTUInfo,
/*IncludeBriefComments=*/false);
/*IncludeBriefComments=*/false,
/*SuppressFuncParamType=*/Opts.ArgumentLists ==

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't convinced myself that this PR doesn't have unintended effects on downstream completions. If I do

    return const_cast<CodeCompletionResult &>(R).CreateCodeCompletionString(
        *CCSema, CCContext, *CCAllocator, CCTUInfo,
        /*IncludeBriefComments=*/false,
        /*SuppressFuncParamType=*/true);

instead a number of test start failing that I'm not quite certain I'd expect failures

@HighCommander4 HighCommander4 May 31, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand why: clangd derives two different things from the CodeCompletionString: a "signature" and a "snippet suffix". The "signature" is used to render the completion item in the completion popup, while the "snippet suffix" is used as part of the inserted code snippet if the completion is accepted.

Currently, both of these contain the parameter types, and to respect the existing values of ArgumentListsPolicy, we just ignore the "snippet suffix" for values of the setting other than FullPlaceholders.

But now, if we build the CodeCompletionString with SuppressFuncParmType=true, the "signature" will be missing the types too, which is undesirable (the user is still interested in seeing the types when viewing the completion item in the popup).

To address this, I think we'll need to build two CodeCompletionStrings, one for the "signature" with SuppressFuncParmType=false, and one for the "snippet suffix" with SuppressFuncParmType=(ArgumentListsPolicy==NamePlaceholders).

(A more principled solution may be to alter the CodeCompletionString structure to put the parameter types and parameter names into different chunks, so that we can continue to derive the signature and snippet suffix from the same CCS; but that seems like a bigger lift that we may not want to undertake now.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more principled solution may be to alter the CodeCompletionString structure to put the parameter types and parameter names into different chunks

Yeah the whole time I was working on this it felt very much like I was pushing "rendering" decisions down into the "data model" which I wasn't very happy with. I think splitting the completion into something like type prefix, name, type suffix would much better maintain separation of concerns. Or even maybe just a lightweight type that that tracks the completion and a string_view inside the completion to note the name section.

My main reservation is that it seems like quite a heavy lift to swap the type away from a string and bubble that up to all the consumers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A third option (still relying on a type swap) would be a opaque type returned from CodeCompleteString instead of a string and a separate set of functions RenderAsSignature, and RenderAsSnippet that converts the opaque type to a string.

The fast migration path would be to have RenderAsSignature(CodeCompleteString(...)) in all the current uses then maybe slowly bubble the type up into the higher layers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a union in the implementation of CodeCompletionString::Chunk. If we want to go with modifying the CodeCompletionString API, a comparatively less disruptive approach could be to extend that union with a new member which would be the "lightweight type that that tracks the completion and a string_view inside the completion to note the name section", to use only for chunks where we need it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started looking into this a bit today and I need to nearly more about how CodeCompletionString::Chunk is used but at a fairly surface level stack trace starts returning std::string instead of CodeCompletionString surprisingly early so even this feels like a fairly invasive change:(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I'd be fine with going with the originally suggested approach which leaves the CodeCompletionString API alone (and involves clangd making two calls to createCodeCompletionString if NamePlaceholders is specified) for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

79b945e

Is something like this what you mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I'm going to be out of office until next Tuesday so I probably wont be able to respond until then.

That said, after reading more of the CCS API I am inclined to say that adding another union value (and updating return types) is the right move. There will be some churn but after looking at it closer it seems like its not a crazy amount of churn. Sorry for the flip-flopping!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

79b945e

Is something like this what you mean?

That's part of what I had in mind, but since that SemaCCS object is used to create both the signature and the snippet suffix, we'd need to create and pass around two CCS objects instead, one for each.

FYI I'm going to be out of office until next Tuesday so I probably wont be able to respond until then.

No rush, I'm also traveling this week and next and will be slow to respond.

That said, after reading more of the CCS API I am inclined to say that adding another union value (and updating return types) is the right move. There will be some churn but after looking at it closer it seems like its not a crazy amount of churn. Sorry for the flip-flopping!

I'm happy to leave that up to your judgment :)

@github-actions

github-actions Bot commented May 28, 2026 •

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 118252 tests passed
  • 4816 tests skipped

✅ The build succeeded and all tests passed.

@github-actions

github-actions Bot commented May 28, 2026 •

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 55727 tests passed
  • 2641 tests skipped

✅ The build succeeded and all tests passed.

@llvmorg-github-actions llvmorg-github-actions Bot added the clang:as-a-library libclang and C++ API label May 28, 2026
@github-actions

github-actions Bot commented May 28, 2026 •

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

std::optional<ArrayRef<QualType>> ObjCSubsts = std::nullopt) {
std::optional<ArrayRef<QualType>> ObjCSubsts = std::nullopt,
bool SuppressType = false) {
// Params are unavailable in FunctionTypeLoc if the FunctionType is invalid.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe assert that SuppressName and SuppressType are not both true (as that would lead to an empty string)?

*CCSema, CCContext, *CCAllocator, CCTUInfo,
/*IncludeBriefComments=*/false);
/*IncludeBriefComments=*/false,
/*SuppressFuncParamType=*/Opts.ArgumentLists ==

@HighCommander4 HighCommander4 May 31, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand why: clangd derives two different things from the CodeCompletionString: a "signature" and a "snippet suffix". The "signature" is used to render the completion item in the completion popup, while the "snippet suffix" is used as part of the inserted code snippet if the completion is accepted.

Currently, both of these contain the parameter types, and to respect the existing values of ArgumentListsPolicy, we just ignore the "snippet suffix" for values of the setting other than FullPlaceholders.

But now, if we build the CodeCompletionString with SuppressFuncParmType=true, the "signature" will be missing the types too, which is undesirable (the user is still interested in seeing the types when viewing the completion item in the popup).

To address this, I think we'll need to build two CodeCompletionStrings, one for the "signature" with SuppressFuncParmType=false, and one for the "snippet suffix" with SuppressFuncParmType=(ArgumentListsPolicy==NamePlaceholders).

(A more principled solution may be to alter the CodeCompletionString structure to put the parameter types and parameter names into different chunks, so that we can continue to derive the signature and snippet suffix from the same CCS; but that seems like a bigger lift that we may not want to undertake now.)

*ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator,
*CompletionTUInfo,
/*IncludeBriefComments*/ false);
/*IncludeBriefComments*/ false, /*SuppressFuncParamType=*/false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the codepath that computes the "signature" and "snippet suffix" that are stored in the index, and will be used for completion items coming from the index.

We should respect NamePlaceholders here too (but here too we should build a separate CCS for the signature so it retains parameter types).

*ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator,
*CompletionTUInfo,
/*IncludeBriefComments*/ false);
/*IncludeBriefComments*/ false, /*SuppressFuncParamType=*/false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This CCS is used for symbol documentation and can continue using SuppressFuncParamType=false.)

@V-FEXrt
V-FEXrt force-pushed the clangd-1252-suppress-types-in-completions branch from 79b945e to c876700 Compare July 1, 2026 20:13
if (Param->getIdentifier() && !ObjCMethodParam && !SuppressName)
Result = std::string(Param->getIdentifier()->deuglifiedName());
std::string Name;
if (Param->getIdentifier() && !SuppressName) // TODO: remove SuppressName?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TODO here should be deleted, but I left it to remind myself of a future potential improvement.

Instead of having a SuppressName var we could update the callsite to extract everything outside of the terse range

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:as-a-library libclang and C++ API clang:frontend Language frontend issues, e.g. anything involving "Sema" clang-tools-extra clangd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to disable parameter types from call completion snippet

2 participants