diff options
Diffstat (limited to 'clang-tools-extra/clangd/CodeComplete.cpp')
-rw-r--r-- | clang-tools-extra/clangd/CodeComplete.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index bc826ba0adc..db9f9cc0519 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -253,9 +253,10 @@ struct CodeCompletionBuilder { const IncludeInserter &Includes, llvm::StringRef FileName, CodeCompletionContext::Kind ContextKind, - const CodeCompleteOptions &Opts) + const CodeCompleteOptions &Opts, bool GenerateSnippets) : ASTCtx(ASTCtx), ExtractDocumentation(Opts.IncludeComments), - EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets) { + EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets), + GenerateSnippets(GenerateSnippets) { add(C, SemaCCS); if (C.SemaResult) { assert(ASTCtx); @@ -419,6 +420,8 @@ private: } std::string summarizeSnippet() const { + if (!GenerateSnippets) + return ""; auto *Snippet = onlyValue<&BundledEntry::SnippetSuffix>(); if (!Snippet) // All bundles are function calls. @@ -476,6 +479,8 @@ private: llvm::SmallVector<BundledEntry, 1> Bundled; bool ExtractDocumentation; bool EnableFunctionArgSnippets; + /// When false, no snippets are generated argument lists. + bool GenerateSnippets; }; // Determine the symbol ID for a Sema code completion result, if possible. @@ -1204,6 +1209,7 @@ class CodeCompleteFlow { // Sema takes ownership of Recorder. Recorder is valid until Sema cleanup. CompletionRecorder *Recorder = nullptr; CodeCompletionContext::Kind CCContextKind = CodeCompletionContext::CCC_Other; + bool IsUsingDeclaration = false; // Counters for logging. int NSema = 0, NIndex = 0, NSemaAndIndex = 0, NIdent = 0; bool Incomplete = false; // Would more be available with a higher limit? @@ -1254,6 +1260,7 @@ public: auto RecorderOwner = std::make_unique<CompletionRecorder>(Opts, [&]() { assert(Recorder && "Recorder is not set"); CCContextKind = Recorder->CCContext.getKind(); + IsUsingDeclaration = Recorder->CCContext.isUsingDeclaration(); auto Style = getFormatStyleForFile( SemaCCInput.FileName, SemaCCInput.Contents, SemaCCInput.VFS.get()); // If preprocessor was run, inclusions from preprocessor callback should @@ -1289,11 +1296,12 @@ public: SPAN_ATTACH(Tracer, "sema_completion_kind", getCompletionKindString(CCContextKind)); log("Code complete: sema context {0}, query scopes [{1}] (AnyScope={2}), " - "expected type {3}", + "expected type {3}{4}", getCompletionKindString(CCContextKind), llvm::join(QueryScopes.begin(), QueryScopes.end(), ","), AllScopes, PreferredType ? Recorder->CCContext.getPreferredType().getAsString() - : "<none>"); + : "<none>", + IsUsingDeclaration ? ", inside using declaration" : ""); }); Recorder = RecorderOwner.get(); @@ -1328,6 +1336,7 @@ public: HeuristicPrefix = guessCompletionPrefix(Content, Offset); populateContextWords(Content); CCContextKind = CodeCompletionContext::CCC_Recovery; + IsUsingDeclaration = false; Filter = FuzzyMatcher(HeuristicPrefix.Name); auto Pos = offsetToPosition(Content, Offset); ReplacedRange.start = ReplacedRange.end = Pos; @@ -1665,7 +1674,8 @@ private: if (!Builder) Builder.emplace(Recorder ? &Recorder->CCSema->getASTContext() : nullptr, Item, SemaCCS, QueryScopes, *Inserter, FileName, - CCContextKind, Opts); + CCContextKind, Opts, + /*GenerateSnippets=*/!IsUsingDeclaration); else Builder->add(Item, SemaCCS); } |