protected override bool AddLookupItems()

in resharper/resharper-unity/src/Unity.Shaders/HlslSupport/Feature/Services/CodeCompletion/BlockShadersSemanticItemsProvider.cs [33:93]


        protected override bool AddLookupItems(BlockShadersCodeCompletionContext context, IItemsCollector collector)
        {
            if (context.LanguageDialect is not UnityBlockShadersDialect { Semantics: { Length: > 0 } semantics} 
                || context.UnterminatedContext.TreeNode is not {} node)
                return false;

            var isTrailing = false;
            Declarator? declarator; 
            if (node is { Parent: HlslTrailingSemantic semanticNode })
            {
                declarator = semanticNode.GetContainingNode<Declarator>();
                isTrailing = true;
            }
            else if (node is { Parent: BSAttributeParameterValue attributeParameterValue } &&
                     BSAttributeParameterValueNavigator.IsSemanticAttributeValue(attributeParameterValue) &&
                     BSAttributeParameterValueNavigator.GetAttribute(attributeParameterValue) is { } attribute &&
                     BSAttributeNavigator.GetCorrespondingDeclaration(attribute) is { } declaration)
                declarator = declaration.TryGetSingleDeclaratorNode() as Declarator;
            else
                return false;
            
            var scope = HlslSemanticScope.Any;
            if (declarator != null) {
                
                var qualType = declarator.GetResolveEntity().GetCppType();
                var cppType = qualType.InternalType switch
                {
                    CppFunctionType cppFunction => cppFunction.ReturnType,
                    _ => qualType
                };
            
                var isUnknownType = cppType.IsUnknownType();
                foreach (var hlslSemantic in semantics)
                {
                    if ((hlslSemantic.Scope & scope) != 0 && (isUnknownType || hlslSemantic.IsTypeSupported(cppType)))
                    {
                        string? name;
                        if (isTrailing)
                            name = hlslSemantic.Name;
                        else
                        {
                            AttributeSemanticsNames.TryGetValue(hlslSemantic.Name, out name);
                            name ??= TryGetAttributeEnumerableSemanticName(hlslSemantic);
                            if (name == null)
                                continue;
                        }
                        
                        AddLookupItem(context, collector, name);
                    }
                }
            }
            else
            {
                foreach (var attrSemantics in AttributeSemanticsNames.Values.
                             Concat(new []{"VertexAttributeColor", "VertexAttributeTextureCoordinate"}))
                {
                    AddLookupItem(context, collector, attrSemantics);
                }
            }
            return true;
        }