Ejemplo n.º 1
0
    public static void MergeDirectives(
        ITypeCompletionContext context,
        IList <DirectiveDefinition> extension,
        IList <DirectiveDefinition> type)
    {
        var directives = new List <(DirectiveType type, DirectiveDefinition def)>();

        foreach (DirectiveDefinition directive in type)
        {
            if (context.TryGetDirectiveType(
                    directive.Reference,
                    out DirectiveType? directiveType))
            {
                directives.Add((directiveType, directive));
            }
        }

        foreach (DirectiveDefinition directive in extension)
        {
            MergeDirective(context, directives, directive);
        }

        type.Clear();

        foreach (DirectiveDefinition directive in directives.Select(t => t.def))
        {
            type.Add(directive);
        }
    }
Ejemplo n.º 2
0
        private bool TryCompleteDirective(
            ITypeCompletionContext context,
            DirectiveDefinition definition,
            ISet <string> processed,
            [NotNullWhen(true)] out Directive?directive)
        {
            if (!context.TryGetDirectiveType(
                    definition.Reference,
                    out DirectiveType? directiveType))
            {
                directive = null;
                return(false);
            }

            if (!processed.Add(directiveType.Name) && !directiveType.IsRepeatable)
            {
                context.ReportError(
                    DirectiveCollection_DirectiveIsUnique(
                        directiveType,
                        context.Type,
                        definition.ParsedDirective,
                        _source));
                directive = null;
                return(false);
            }

            if (directiveType.Locations.Contains(_location))
            {
                directive = Directive.FromDescription(directiveType, definition, _source);
                return(true);
            }

            context.ReportError(
                DirectiveCollection_LocationNotAllowed(
                    directiveType,
                    _location,
                    context.Type,
                    definition.ParsedDirective,
                    _source));
            directive = null;
            return(false);
        }