| 671 | } |
| 672 | |
| 673 | bool DUContext::findDeclarationsInternal(const SearchItem::PtrList& baseIdentifiers, |
| 674 | const CursorInRevision& position, |
| 675 | const AbstractType::Ptr& dataType, |
| 676 | DeclarationList& ret, const TopDUContext* source, |
| 677 | SearchFlags flags, uint depth) const |
| 678 | { |
| 679 | if (depth > maxParentDepth) { |
| 680 | qCDebug(LANGUAGE) << "maximum depth reached in" << scopeIdentifier(true); |
| 681 | return false; |
| 682 | } |
| 683 | |
| 684 | DUCHAIN_D(DUContext); |
| 685 | if (d->m_contextType != Namespace) { |
| 686 | // If we're in a namespace, delay all the searching into the top-context, because only that has the overview to pick the correct declarations. |
| 687 | for (auto& baseIdentifier : baseIdentifiers) { |
| 688 | if (!baseIdentifier->isExplicitlyGlobal && baseIdentifier->next.isEmpty()) { |
| 689 | // It makes no sense searching locally for qualified identifiers |
| 690 | findLocalDeclarationsInternal(baseIdentifier->identifier, position, dataType, ret, source, flags); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | if (foundEnough(ret, flags)) { |
| 695 | return true; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | ///Step 1: Apply namespace-aliases and -imports |
| 700 | SearchItem::PtrList aliasedIdentifiers; |
| 701 | //Because of namespace-imports and aliases, this identifier may need to be searched under multiple names |
| 702 | applyAliases(baseIdentifiers, aliasedIdentifiers, position, false, |
| 703 | type() != DUContext::Namespace && type() != DUContext::Global); |
| 704 | |
| 705 | if (d->m_importedContextsSize() != 0) { |
| 706 | ///Step 2: Give identifiers that are not marked as explicitly-global to imported contexts(explicitly global ones are treatead in TopDUContext) |
| 707 | SearchItem::PtrList nonGlobalIdentifiers; |
| 708 | for (const SearchItem::Ptr& identifier : std::as_const(aliasedIdentifiers)) { |
| 709 | if (!identifier->isExplicitlyGlobal) { |
| 710 | nonGlobalIdentifiers << identifier; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | if (!nonGlobalIdentifiers.isEmpty()) { |
| 715 | const auto& url = this->url(); |
| 716 | for (int import = d->m_importedContextsSize() - 1; import >= 0; --import) { |
| 717 | if (position.isValid() && d->m_importedContexts()[import].position.isValid() && |
| 718 | position < d->m_importedContexts()[import].position) { |
| 719 | continue; |
| 720 | } |
| 721 | |
| 722 | DUContext* context = d->m_importedContexts()[import].context(source); |
| 723 | |
| 724 | if (!context) { |
| 725 | continue; |
| 726 | } else if (context == this) { |
| 727 | qCDebug(LANGUAGE) << "resolved self as import:" << scopeIdentifier(true); |
| 728 | continue; |
| 729 | } |
| 730 | |