From 07a380d72a13899a84cbdc35692be7a3d9246dcb Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 22 Jun 2022 19:58:34 -0700 Subject: More Language Server Improvements. (#2289) --- source/slang/slang-lookup.cpp | 73 ++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 28 deletions(-) (limited to 'source/slang/slang-lookup.cpp') diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp index a77478ccb..8c69e2013 100644 --- a/source/slang/slang-lookup.cpp +++ b/source/slang/slang-lookup.cpp @@ -2,6 +2,7 @@ #include "slang-lookup.h" #include "../compiler-core/slang-name.h" +#include "slang-check-impl.h" namespace Slang { @@ -199,27 +200,45 @@ static void _lookUpDirectAndTransparentMembers( { ContainerDecl* containerDecl = containerDeclRef.getDecl(); - // Ensure that the lookup dictionary in the container is up to date - if (!containerDecl->isMemberDictionaryValid()) + + if (request.isCompletionRequest()) { - buildMemberDictionary(containerDecl); + // If we are looking up for completion suggestions, + // return all the members that are available. + for (auto member : containerDecl->members) + { + if (!DeclPassesLookupMask(member, request.mask)) + continue; + AddToLookupResult( + result, + CreateLookupResultItem( + DeclRef(member, containerDeclRef.substitutions), inBreadcrumbs)); + } } + else + { + // Ensure that the lookup dictionary in the container is up to date + if (!containerDecl->isMemberDictionaryValid()) + { + buildMemberDictionary(containerDecl); + } - // Look up the declarations with the chosen name in the container. - Decl* firstDecl = nullptr; - containerDecl->memberDictionary.TryGetValue(name, firstDecl); + // Look up the declarations with the chosen name in the container. + Decl* firstDecl = nullptr; + containerDecl->memberDictionary.TryGetValue(name, firstDecl); - // Now iterate over those declarations (if any) and see if - // we find any that meet our filtering criteria. - // For example, we might be filtering so that we only consider - // type declarations. - for (auto m = firstDecl; m; m = m->nextInContainerWithSameName) - { - if (!DeclPassesLookupMask(m, request.mask)) - continue; + // Now iterate over those declarations (if any) and see if + // we find any that meet our filtering criteria. + // For example, we might be filtering so that we only consider + // type declarations. + for (auto m = firstDecl; m; m = m->nextInContainerWithSameName) + { + if (!DeclPassesLookupMask(m, request.mask)) + continue; - // The declaration passed the test, so add it! - AddToLookupResult(result, CreateLookupResultItem(DeclRef(m, containerDeclRef.substitutions), inBreadcrumbs)); + // The declaration passed the test, so add it! + AddToLookupResult(result, CreateLookupResultItem(DeclRef(m, containerDeclRef.substitutions), inBreadcrumbs)); + } } // TODO(tfoley): should we look up in the transparent decls @@ -937,9 +956,11 @@ static void _lookUpInScopes( if (result.isValid()) { - // If it's overloaded or the decl we have is of an overloadable type then we just keep going + // If it's overloaded or the decl we have is of an overloadable type, or if we are + // looking up for completion suggestions then we just keep going if (result.isOverloaded() || - _isDeclOverloadable(result.item.declRef.getDecl())) + _isDeclOverloadable(result.item.declRef.getDecl()) || + ((int32_t)request.options & (int32_t)LookupOptions::Completion) != 0) { continue; } @@ -964,21 +985,14 @@ LookupResult lookUp( request.semantics = semantics; request.scope = scope; request.mask = mask; - + if (semantics && semantics->getSession() && + name == semantics->getSession()->getCompletionRequestTokenName()) + request.options = (LookupOptions)((int)request.options | (int)LookupOptions::Completion); LookupResult result; _lookUpInScopes(astBuilder, name, request, result); return result; } -void lookUpMemberImpl( - ASTBuilder* astBuilder, - SemanticsVisitor* semantics, - Name* name, - Type* type, - LookupResult& ioResult, - BreadcrumbInfo* inBreadcrumbs, - LookupMask mask); - LookupResult lookUpMember( ASTBuilder* astBuilder, SemanticsVisitor* semantics, @@ -991,6 +1005,9 @@ LookupResult lookUpMember( request.semantics = semantics; request.mask = mask; request.options = options; + if (semantics && semantics->getSession() && + name == semantics->getSession()->getCompletionRequestTokenName()) + request.options = (LookupOptions)((int)request.options | (int)LookupOptions::Completion); LookupResult result; _lookUpMembersInType(astBuilder, name, type, request, result, nullptr); -- cgit v1.2.3