llvm/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

//===-- CodeCompleteTests.cpp -----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "ASTSignals.h"
#include "Annotations.h"
#include "ClangdServer.h"
#include "CodeComplete.h"
#include "Compiler.h"
#include "Feature.h"
#include "Matchers.h"
#include "Protocol.h"
#include "Quality.h"
#include "SourceCode.h"
#include "SyncAPI.h"
#include "TestFS.h"
#include "TestIndex.h"
#include "TestTU.h"
#include "index/Index.h"
#include "index/MemIndex.h"
#include "index/SymbolOrigin.h"
#include "support/Threading.h"
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Tooling/CompilationDatabase.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Path.h"
#include "llvm/Testing/Annotations/Annotations.h"
#include "llvm/Testing/Support/Error.h"
#include "llvm/Testing/Support/SupportHelpers.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <condition_variable>
#include <functional>
#include <mutex>
#include <vector>

namespace clang {
namespace clangd {

namespace {
Failed;
AllOf;
Contains;
ElementsAre;
Field;
HasSubstr;
IsEmpty;
Not;
UnorderedElementsAre;
ContextKind;

// GMock helpers for matching completion items.
MATCHER_P(named, Name, "") {}
MATCHER_P(mainFileRefs, Refs, "") {}
MATCHER_P(scopeRefs, Refs, "") {}
MATCHER_P(nameStartsWith, Prefix, "") {}
MATCHER_P(filterText, F, "") {}
MATCHER_P(scope, S, "") {}
MATCHER_P(qualifier, Q, "") {}
MATCHER_P(labeled, Label, "") {}
MATCHER_P(sigHelpLabeled, Label, "") {}
MATCHER_P(kind, K, "") {}
MATCHER_P(doc, D, "") {}
MATCHER_P(returnType, D, "") {}
MATCHER_P(hasInclude, IncludeHeader, "") {}
MATCHER_P(insertInclude, IncludeHeader, "") {}
MATCHER_P(insertIncludeText, InsertedText, "") {}
MATCHER(insertInclude, "") {}
MATCHER_P(snippetSuffix, Text, "") {}
MATCHER_P(origin, OriginSet, "") {}
MATCHER_P(signature, S, "") {}
MATCHER_P(replacesRange, Range, "") {}

// Shorthand for Contains(named(Name)).
Matcher<const std::vector<CodeCompletion> &> has(std::string Name) {}
Matcher<const std::vector<CodeCompletion> &> has(std::string Name,
                                                 CompletionItemKind K) {}
MATCHER(isDocumented, "") {}
MATCHER(deprecated, "") {}

std::unique_ptr<SymbolIndex> memIndex(std::vector<Symbol> Symbols) {}

// Runs code completion.
// If IndexSymbols is non-empty, an index will be built and passed to opts.
CodeCompleteResult completions(const TestTU &TU, Position Point,
                               std::vector<Symbol> IndexSymbols = {}

// Runs code completion.
CodeCompleteResult completions(llvm::StringRef Text,
                               std::vector<Symbol> IndexSymbols = {}

// Runs code completion without the clang parser.
CodeCompleteResult completionsNoCompile(llvm::StringRef Text,
                                        std::vector<Symbol> IndexSymbols = {}

Symbol withReferences(int N, Symbol S) {}

#if CLANGD_DECISION_FOREST
TEST(DecisionForestRankingModel, NameMatchSanityTest) {}

TEST(DecisionForestRankingModel, ReferencesAffectRanking) {}
#endif // CLANGD_DECISION_FOREST

TEST(DecisionForestRankingModel, DecisionForestScorerCallbackTest) {}

TEST(CompletionTest, Limit) {}

TEST(CompletionTest, Filter) {}

void testAfterDotCompletion(clangd::CodeCompleteOptions Opts) {}

void testGlobalScopeCompletion(clangd::CodeCompleteOptions Opts) {}

TEST(CompletionTest, CompletionOptions) {}

TEST(CompletionTest, Accessible) {}

TEST(CompletionTest, Qualifiers) {}

// https://github.com/clangd/clangd/issues/1451
TEST(CompletionTest, QualificationWithInlineNamespace) {}

TEST(CompletionTest, InjectedTypename) {}

TEST(CompletionTest, SkipInjectedWhenUnqualified) {}

TEST(CompletionTest, Snippets) {}

TEST(CompletionTest, HeuristicsForMemberFunctionCompletion) {}

TEST(CompletionTest, NoSnippetsInUsings) {}

TEST(CompletionTest, Kinds) {}

TEST(CompletionTest, NoDuplicates) {}

TEST(CompletionTest, ScopedNoIndex) {}

TEST(CompletionTest, Scoped) {}

TEST(CompletionTest, ScopedWithFilter) {}

TEST(CompletionTest, ReferencesAffectRanking) {}

TEST(CompletionTest, ContextWords) {}

TEST(CompletionTest, GlobalQualified) {}

TEST(CompletionTest, FullyQualified) {}

TEST(CompletionTest, SemaIndexMerge) {}

TEST(CompletionTest, SemaIndexMergeWithLimit) {}

TEST(CompletionTest, IncludeInsertionPreprocessorIntegrationTests) {}

TEST(CompletionTest, NoIncludeInsertionWhenDeclFoundInFile) {}

TEST(CompletionTest, IndexSuppressesPreambleCompletions) {}

// This verifies that we get normal preprocessor completions in the preamble.
// This is a regression test for an old bug: if we override the preamble and
// try to complete inside it, clang kicks our completion point just outside the
// preamble, resulting in always getting top-level completions.
TEST(CompletionTest, CompletionInPreamble) {}

TEST(CompletionTest, CompletionRecoveryASTType) {}

TEST(CompletionTest, DynamicIndexIncludeInsertion) {}

TEST(CompletionTest, DynamicIndexMultiFile) {}

TEST(CompletionTest, Documentation) {}

TEST(CompletionTest, CommentsFromSystemHeaders) {}

TEST(CompletionTest, GlobalCompletionFiltering) {}

TEST(CodeCompleteTest, DisableTypoCorrection) {}

TEST(CodeCompleteTest, NoColonColonAtTheEnd) {}

TEST(CompletionTests, EmptySnippetDoesNotCrash) {}

TEST(CompletionTest, Issue1427Crash) {}

TEST(CompletionTest, BacktrackCrashes) {}

TEST(CompletionTest, CompleteInMacroWithStringification) {}

TEST(CompletionTest, CompleteInMacroAndNamespaceWithStringification) {}

TEST(CompletionTest, IgnoreCompleteInExcludedPPBranchWithRecoveryContext) {}

TEST(CompletionTest, DefaultArgs) {}

TEST(CompletionTest, NoCrashWithTemplateParamsAndPreferredTypes) {}

TEST(CompletionTest, NestedTemplateHeuristics) {}

TEST(CompletionTest, RecordCCResultCallback) {}

TEST(CompletionTest, ASTSignals) {}

SignatureHelp
signatures(llvm::StringRef Text, Position Point,
           std::vector<Symbol> IndexSymbols = {}

SignatureHelp
signatures(llvm::StringRef Text, std::vector<Symbol> IndexSymbols = {}

struct ExpectedParameter {};
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
                              const ExpectedParameter &P) {}
MATCHER_P(paramsAre, P, "") {}
MATCHER_P(sigDoc, doc, "") {}

/// \p AnnotatedLabel is a signature label with ranges marking parameters, e.g.
///    foo([[int p1]], [[double p2]]) -> void
Matcher<SignatureInformation> sig(llvm::StringRef AnnotatedLabel) {}

TEST(SignatureHelpTest, Overloads) {}

TEST(SignatureHelpTest, FunctionPointers) {}

TEST(SignatureHelpTest, Constructors) {}

TEST(SignatureHelpTest, Aggregates) {}

TEST(SignatureHelpTest, OverloadInitListRegression) {}

TEST(SignatureHelpTest, DefaultArgs) {}

TEST(SignatureHelpTest, ActiveArg) {}

TEST(SignatureHelpTest, OpeningParen) {}

TEST(SignatureHelpTest, StalePreamble) {}

class IndexRequestCollector : public SymbolIndex {};

// Clients have to consume exactly Num requests.
std::vector<FuzzyFindRequest> captureIndexRequests(llvm::StringRef Code,
                                                   size_t Num = 1) {}

TEST(CompletionTest, UnqualifiedIdQuery) {}

TEST(CompletionTest, EnclosingScopeComesFirst) {}

TEST(CompletionTest, ResolvedQualifiedIdQuery) {}

TEST(CompletionTest, UnresolvedQualifierIdQuery) {}

TEST(CompletionTest, UnresolvedNestedQualifierIdQuery) {}

TEST(CompletionTest, EmptyQualifiedQuery) {}

TEST(CompletionTest, GlobalQualifiedQuery) {}

TEST(CompletionTest, NoDuplicatedQueryScopes) {}

TEST(CompletionTest, NoIndexCompletionsInsideClasses) {}

TEST(CompletionTest, NoIndexCompletionsInsideDependentCode) {}

TEST(CompletionTest, OverloadBundling) {}

TEST(CompletionTest, OverloadBundlingSameFileDifferentURI) {}

TEST(CompletionTest, DocumentationFromChangedFileCrash) {}

TEST(CompletionTest, NonDocComments) {}

TEST(CompletionTest, CompleteOnInvalidLine) {}

TEST(CompletionTest, QualifiedNames) {}

TEST(CompletionTest, Render) {}

TEST(CompletionTest, IgnoreRecoveryResults) {}

TEST(CompletionTest, ScopeOfClassFieldInConstructorInitializer) {}

// Like other class members, constructor init lists have to parse what's below,
// after the completion point.
// But recovering from an incomplete constructor init list is particularly
// tricky because the bulk of the list is not surrounded by brackets.
TEST(CompletionTest, ConstructorInitListIncomplete) {}

TEST(CompletionTest, CodeCompletionContext) {}

TEST(CompletionTest, FixItForArrowToDot) {}

TEST(CompletionTest, FixItForDotToArrow) {}

TEST(CompletionTest, RenderWithFixItMerged) {}

TEST(CompletionTest, RenderWithFixItNonMerged) {}

TEST(CompletionTest, CompletionTokenRange) {}

TEST(SignatureHelpTest, OverloadsOrdering) {}

TEST(SignatureHelpTest, InstantiatedSignatures) {}

TEST(SignatureHelpTest, IndexDocumentation) {}

TEST(SignatureHelpTest, DynamicIndexDocumentation) {}

TEST(CompletionTest, CompletionFunctionArgsDisabled) {}

TEST(CompletionTest, SuggestOverrides) {}

TEST(CompletionTest, OverridesNonIdentName) {}

TEST(CompletionTest, NoCrashOnMissingNewLineAtEOF) {}

TEST(GuessCompletionPrefix, Filters) {}

TEST(CompletionTest, EnableSpeculativeIndexRequest) {}

TEST(CompletionTest, InsertTheMostPopularHeader) {}

TEST(CompletionTest, InsertIncludeOrImport) {}

TEST(CompletionTest, NoInsertIncludeIfOnePresent) {}

TEST(CompletionTest, MergeMacrosFromIndexAndSema) {}

TEST(CompletionTest, MacroFromPreamble) {}

TEST(CompletionTest, DeprecatedResults) {}

TEST(SignatureHelpTest, PartialSpec) {}

TEST(SignatureHelpTest, InsideArgument) {}

TEST(SignatureHelpTest, ConstructorInitializeFields) {}

TEST(SignatureHelpTest, Variadic) {}

TEST(SignatureHelpTest, VariadicTemplate) {}

TEST(SignatureHelpTest, VariadicMethod) {}

TEST(SignatureHelpTest, VariadicType) {}

TEST(CompletionTest, IncludedCompletionKinds) {}

TEST(CompletionTest, NoCrashAtNonAlphaIncludeHeader) {}

TEST(CompletionTest, NoAllScopesCompletionWhenQualified) {}

TEST(CompletionTest, AllScopesCompletion) {}

TEST(CompletionTest, NoQualifierIfShadowed) {}

TEST(CompletionTest, NoCompletionsForNewNames) {}

TEST(CompletionTest, Lambda) {}

TEST(CompletionTest, StructuredBinding) {}

TEST(CompletionTest, ObjectiveCMethodNoArguments) {}

TEST(CompletionTest, ObjectiveCMethodOneArgument) {}

TEST(CompletionTest, ObjectiveCMethodTwoArgumentsFromBeginning) {}

TEST(CompletionTest, ObjectiveCMethodTwoArgumentsFromMiddle) {}

TEST(CompletionTest, ObjectiveCMethodFilterOnEntireSelector) {}

TEST(CompletionTest, ObjectiveCSimpleMethodDeclaration) {}

TEST(CompletionTest, ObjectiveCMethodDeclaration) {}

TEST(CompletionTest, ObjectiveCMethodDeclarationFilterOnEntireSelector) {}

TEST(CompletionTest, ObjectiveCMethodDeclarationPrefixTyped) {}

TEST(CompletionTest, ObjectiveCMethodDeclarationFromMiddle) {}

TEST(CompletionTest, ObjectiveCProtocolFromIndex) {}

TEST(CompletionTest, ObjectiveCProtocolFromIndexSpeculation) {}

TEST(CompletionTest, ObjectiveCCategoryFromIndexIgnored) {}

TEST(CompletionTest, ObjectiveCForwardDeclFromIndex) {}

TEST(CompletionTest, CursorInSnippets) {}

TEST(CompletionTest, WorksWithNullType) {}

TEST(CompletionTest, UsingDecl) {}

TEST(CompletionTest, Enums) {}

TEST(CompletionTest, ScopeIsUnresolved) {}

TEST(CompletionTest, NestedScopeIsUnresolved) {}

// Clang parser gets confused here and doesn't report the ns:: prefix.
// Naive behavior is to insert it again. We examine the source and recover.
TEST(CompletionTest, NamespaceDoubleInsertion) {}

TEST(CompletionTest, DerivedMethodsAreAlwaysVisible) {}

TEST(CompletionTest, NoCrashWithIncompleteLambda) {}

TEST(CompletionTest, DelayedTemplateParsing) {}

TEST(CompletionTest, CompletionRange) {}

TEST(NoCompileCompletionTest, Basic) {}

TEST(NoCompileCompletionTest, WithFilter) {}

TEST(NoCompileCompletionTest, WithIndex) {}

TEST(AllowImplicitCompletion, All) {}

TEST(CompletionTest, FunctionArgsExist) {}

TEST(CompletionTest, FunctionArgsExist_Issue1785) {}

TEST(CompletionTest, NoCrashDueToMacroOrdering) {}

TEST(CompletionTest, ObjCCategoryDecls) {}

TEST(CompletionTest, PreambleCodeComplete) {}

TEST(CompletionTest, CommentParamName) {}

TEST(CompletionTest, Concepts) {}

TEST(SignatureHelp, DocFormat) {}

TEST(SignatureHelp, TemplateArguments) {}

TEST(CompletionTest, DoNotCrash) {}
TEST(CompletionTest, PreambleFromDifferentTarget) {}
} // namespace
} // namespace clangd
} // namespace clang