21
21
#include " AST.h"
22
22
#include " CodeCompletionStrings.h"
23
23
#include " Compiler.h"
24
+ #include " Config.h"
24
25
#include " ExpectedTypes.h"
25
26
#include " Feature.h"
26
27
#include " FileDistance.h"
@@ -350,8 +351,7 @@ struct CodeCompletionBuilder {
350
351
CodeCompletionContext::Kind ContextKind,
351
352
const CodeCompleteOptions &Opts,
352
353
bool IsUsingDeclaration, tok::TokenKind NextTokenKind)
353
- : ASTCtx(ASTCtx),
354
- EnableFunctionArgSnippets (Opts.EnableFunctionArgSnippets),
354
+ : ASTCtx(ASTCtx), ArgumentLists(Opts.ArgumentLists),
355
355
IsUsingDeclaration (IsUsingDeclaration), NextTokenKind(NextTokenKind) {
356
356
Completion.Deprecated = true ; // cleared by any non-deprecated overload.
357
357
add (C, SemaCCS, ContextKind);
@@ -561,14 +561,23 @@ struct CodeCompletionBuilder {
561
561
}
562
562
563
563
std::string summarizeSnippet () const {
564
+ // / localize ArgumentLists tests for better readability
565
+ const bool None = ArgumentLists == Config::ArgumentListsPolicy::None;
566
+ const bool Open =
567
+ ArgumentLists == Config::ArgumentListsPolicy::OpenDelimiter;
568
+ const bool Delim = ArgumentLists == Config::ArgumentListsPolicy::Delimiters;
569
+ const bool Full =
570
+ ArgumentLists == Config::ArgumentListsPolicy::FullPlaceholders ||
571
+ (!None && !Open && !Delim); // <-- failsafe: Full is default
572
+
564
573
if (IsUsingDeclaration)
565
574
return " " ;
566
575
auto *Snippet = onlyValue<&BundledEntry::SnippetSuffix>();
567
576
if (!Snippet)
568
577
// All bundles are function calls.
569
578
// FIXME(ibiryukov): sometimes add template arguments to a snippet, e.g.
570
579
// we need to complete 'forward<$1>($0)'.
571
- return " ( $0)" ;
580
+ return None ? " " : (Open ? " ( " : " ( $0)" ) ;
572
581
573
582
if (Snippet->empty ())
574
583
return " " ;
@@ -607,7 +616,7 @@ struct CodeCompletionBuilder {
607
616
return " " ;
608
617
}
609
618
}
610
- if (EnableFunctionArgSnippets )
619
+ if (Full )
611
620
return *Snippet;
612
621
613
622
// Replace argument snippets with a simplified pattern.
@@ -622,9 +631,9 @@ struct CodeCompletionBuilder {
622
631
623
632
bool EmptyArgs = llvm::StringRef (*Snippet).ends_with (" ()" );
624
633
if (Snippet->front () == ' <' )
625
- return EmptyArgs ? " <$1>()$0" : " <$1>($0)" ;
634
+ return None ? " " : (Open ? " < " : ( EmptyArgs ? " <$1>()$0" : " <$1>($0)" )) ;
626
635
if (Snippet->front () == ' (' )
627
- return EmptyArgs ? " ()" : " ($0)" ;
636
+ return None ? " " : (Open ? " ( " : ( EmptyArgs ? " ()" : " ($0)" )) ;
628
637
return *Snippet; // Not an arg snippet?
629
638
}
630
639
// 'CompletionItemKind::Interface' matches template type aliases.
@@ -638,7 +647,7 @@ struct CodeCompletionBuilder {
638
647
// e.g. Foo<${1:class}>.
639
648
if (llvm::StringRef (*Snippet).ends_with (" <>" ))
640
649
return " <>" ; // can happen with defaulted template arguments.
641
- return " < $0>" ;
650
+ return None ? " " : (Open ? " < " : " < $0>" ) ;
642
651
}
643
652
return *Snippet;
644
653
}
@@ -654,7 +663,8 @@ struct CodeCompletionBuilder {
654
663
ASTContext *ASTCtx;
655
664
CodeCompletion Completion;
656
665
llvm::SmallVector<BundledEntry, 1 > Bundled;
657
- bool EnableFunctionArgSnippets;
666
+ // / the way argument lists are handled.
667
+ Config::ArgumentListsPolicy ArgumentLists;
658
668
// No snippets will be generated for using declarations and when the function
659
669
// arguments are already present.
660
670
bool IsUsingDeclaration;
0 commit comments