Index: clangd/CodeComplete.cpp =================================================================== --- clangd/CodeComplete.cpp +++ clangd/CodeComplete.cpp @@ -40,6 +40,7 @@ #include "clang/Sema/Sema.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/Support/Format.h" +#include "llvm/Support/FormatVariadic.h" #include // We log detailed candidate here if you run with -debug-only=codecomplete. @@ -939,6 +940,7 @@ int NSema = 0, NIndex = 0, NBoth = 0; // Counters for logging. bool Incomplete = false; // Would more be available with a higher limit? llvm::Optional Filter; // Initialized once Sema runs. + std::vector QueryScopes; // Initialized once Sema runs. std::unique_ptr Includes; // Initialized once compiler runs. FileProximityMatcher FileProximityMatch; @@ -968,6 +970,10 @@ Includes.reset(); // Make sure this doesn't out-live Clang. SPAN_ATTACH(Tracer, "sema_completion_kind", getCompletionKindString(Recorder->CCContext.getKind())); + log(llvm::formatv( + "Code complete: sema context {0}, query scopes [{1}]", + getCompletionKindString(Recorder->CCContext.getKind()), + llvm::join(QueryScopes.begin(), QueryScopes.end(), ","))); }); Recorder = RecorderOwner.get(); @@ -995,6 +1001,8 @@ CompletionList runWithSema() { Filter = FuzzyMatcher( Recorder->CCSema->getPreprocessor().getCodeCompletionFilter()); + QueryScopes = getQueryScopes(Recorder->CCContext, + Recorder->CCSema->getSourceManager()); // Sema provides the needed context to query the index. // FIXME: in addition to querying for extra/overlapping symbols, we should // explicitly request symbols corresponding to Sema results. @@ -1024,8 +1032,7 @@ Req.MaxCandidateCount = Opts.Limit; Req.Query = Filter->pattern(); Req.RestrictForCodeCompletion = true; - Req.Scopes = getQueryScopes(Recorder->CCContext, - Recorder->CCSema->getSourceManager()); + Req.Scopes = QueryScopes; Req.ProximityPaths.push_back(FileName); log(llvm::formatv("Code complete: fuzzyFind(\"{0}\", scopes=[{1}])", Req.Query,