|
40 | 40 | #include "llvm/ADT/StringSet.h"
|
41 | 41 | #include "llvm/Support/Error.h"
|
42 | 42 | #include "llvm/Support/FormatVariadic.h"
|
| 43 | +#include <algorithm> |
| 44 | +#include <set> |
| 45 | +#include <string> |
43 | 46 | #include <vector>
|
44 | 47 |
|
45 | 48 | namespace clang {
|
46 | 49 | namespace clangd {
|
47 | 50 |
|
48 |
| -namespace { |
49 |
| - |
50 |
| -// Collects contexts visited during a Sema name lookup. |
51 |
| -class VisitedContextCollector : public VisibleDeclConsumer { |
52 |
| -public: |
53 |
| - void EnteredContext(DeclContext *Ctx) override { Visited.push_back(Ctx); } |
54 |
| - |
55 |
| - void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, |
56 |
| - bool InBaseClass) override {} |
57 |
| - |
58 |
| - std::vector<DeclContext *> takeVisitedContexts() { |
59 |
| - return std::move(Visited); |
60 |
| - } |
61 |
| - |
62 |
| -private: |
63 |
| - std::vector<DeclContext *> Visited; |
64 |
| -}; |
65 |
| - |
66 |
| -} // namespace |
67 |
| - |
68 | 51 | std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
|
69 | 52 | const clang::Diagnostic &Info) const {
|
70 | 53 | switch (Info.getID()) {
|
@@ -313,17 +296,26 @@ llvm::Optional<CheapUnresolvedName> extractUnresolvedNameCheaply(
|
313 | 296 | std::vector<std::string>
|
314 | 297 | collectAccessibleScopes(Sema &Sem, const DeclarationNameInfo &Typo, Scope *S,
|
315 | 298 | Sema::LookupNameKind LookupKind) {
|
| 299 | + // Collects contexts visited during a Sema name lookup. |
| 300 | + struct VisitedContextCollector : public VisibleDeclConsumer { |
| 301 | + VisitedContextCollector(std::vector<std::string> &Out) : Out(Out) {} |
| 302 | + void EnteredContext(DeclContext *Ctx) override { |
| 303 | + if (llvm::isa<NamespaceDecl>(Ctx)) |
| 304 | + Out.push_back(printNamespaceScope(*Ctx)); |
| 305 | + } |
| 306 | + void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, |
| 307 | + bool InBaseClass) override {} |
| 308 | + std::vector<std::string> &Out; |
| 309 | + }; |
| 310 | + |
316 | 311 | std::vector<std::string> Scopes;
|
317 |
| - VisitedContextCollector Collector; |
| 312 | + Scopes.push_back(""); |
| 313 | + VisitedContextCollector Collector(Scopes); |
318 | 314 | Sem.LookupVisibleDecls(S, LookupKind, Collector,
|
319 | 315 | /*IncludeGlobalScope=*/false,
|
320 | 316 | /*LoadExternal=*/false);
|
321 |
| - |
322 |
| - Scopes.push_back(""); |
323 |
| - for (const auto *Ctx : Collector.takeVisitedContexts()) { |
324 |
| - if (isa<NamespaceDecl>(Ctx)) |
325 |
| - Scopes.push_back(printNamespaceScope(*Ctx)); |
326 |
| - } |
| 317 | + std::sort(Scopes.begin(), Scopes.end()); |
| 318 | + Scopes.erase(std::unique(Scopes.begin(), Scopes.end()), Scopes.end()); |
327 | 319 | return Scopes;
|
328 | 320 | }
|
329 | 321 |
|
|
0 commit comments