예제 #1
0
        public static void MergeDirectives(
            ICompletionContext context,
            IList <DirectiveDefinition> extension,
            IList <DirectiveDefinition> type)
        {
            var directives =
                new List <(DirectiveType type, DirectiveDefinition def)>();

            foreach (DirectiveDefinition directive in type)
            {
                DirectiveType directiveType =
                    context.GetDirectiveType(directive.Reference);
                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);
            }
        }
예제 #2
0
        private bool TryCompleteDirective(
            ICompletionContext context,
            DirectiveDefinition definition,
            ISet <string> processed,
            out Directive directive)
        {
            DirectiveType directiveType = context.GetDirectiveType(definition.Reference);

            directive = null;

            if (directiveType != null)
            {
                if (!processed.Add(directiveType.Name) && !directiveType.IsRepeatable)
                {
                    context.ReportError(SchemaErrorBuilder.New()
                                        .SetMessage(string.Format(
                                                        CultureInfo.InvariantCulture,
                                                        TypeResources.DirectiveCollection_DirectiveIsUnique,
                                                        directiveType.Name))
                                        .SetCode(ErrorCodes.Schema.MissingType)
                                        .SetTypeSystemObject(context.Type)
                                        .AddSyntaxNode(definition.ParsedDirective)
                                        .SetExtension("Source", _source)
                                        .Build());
                }
                else if (directiveType.Locations.Contains(_location))
                {
                    directive = Directive.FromDescription(directiveType, definition, _source);
                }
                else
                {
                    context.ReportError(SchemaErrorBuilder.New()
                                        .SetMessage(string.Format(
                                                        CultureInfo.InvariantCulture,
                                                        TypeResources.DirectiveCollection_LocationNotAllowed,
                                                        directiveType.Name,
                                                        _location))
                                        .SetCode(ErrorCodes.Schema.MissingType)
                                        .SetTypeSystemObject(context.Type)
                                        .AddSyntaxNode(definition.ParsedDirective)
                                        .SetExtension("Source", _source)
                                        .Build());
                }
            }

            return(directive != null);
        }
예제 #3
0
        private void CompleteDirective(
            ICompletionContext context,
            DirectiveDefinition definition,
            ISet <string> processed)
        {
            DirectiveType directiveType =
                context.GetDirectiveType(definition.Reference);

            if (directiveType != null)
            {
                if (!processed.Add(directiveType.Name) &&
                    !directiveType.IsRepeatable)
                {
                    // TODO : resources
                    context.ReportError(SchemaErrorBuilder.New()
                                        .SetMessage(
                                            $"The specified directive `@{directiveType.Name}` " +
                                            "is unique and cannot be added twice.")
                                        .SetCode(TypeErrorCodes.MissingType)
                                        .SetTypeSystemObject(context.Type)
                                        .AddSyntaxNode(definition.ParsedDirective)
                                        .Build());
                }
                else if (directiveType.Locations.Contains(_location))
                {
                    _directives.Add(Directive.FromDescription(
                                        directiveType, definition, _source));
                }
                else
                {
                    // TODO : resources
                    context.ReportError(SchemaErrorBuilder.New()
                                        .SetMessage(
                                            $"The specified directive `@{directiveType.Name}` " +
                                            "is not allowed on the current location " +
                                            $"`{_location}`.")
                                        .SetCode(TypeErrorCodes.MissingType)
                                        .SetTypeSystemObject(context.Type)
                                        .AddSyntaxNode(definition.ParsedDirective)
                                        .Build());
                }
            }
        }