示例#1
0
        public JSONItemValidationResult ValidateItem(JSONParseItem item, IJSONValidationContext context)
        {
            JSONMember member = item as JSONMember;
            JSONMember icons  = item?.Parent?.FindType <JSONMember>();

            if (icons != null && icons.UnquotedNameText == "icons")
            {
                string folder = Path.GetDirectoryName(item.JSONDocument.DocumentLocation);
                string file   = Path.Combine(folder, member.UnquotedValueText);

                if (!File.Exists(file))
                {
                    JsonErrorTag error = new JsonErrorTag
                    {
                        Flags    = JSONErrorFlags.ErrorListError | JSONErrorFlags.UnderlineRed,
                        Item     = member.Value,
                        Start    = member.Value.Start,
                        AfterEnd = member.Value.AfterEnd,
                        Length   = member.Value.Length,
                        Text     = $"The file \"{member.UnquotedValueText}\" does not exist"
                    };

                    Telemetry.TrackEvent("Icon file missing");
                    context.AddError(error);
                }
            }

            return(JSONItemValidationResult.Continue);
        }
        public JSONItemValidationResult ValidateItem(JSONParseItem item, IJSONValidationContext context)
        {
            JSONMember member = item as JSONMember;

            if (member != null && member.UnquotedNameText == "icon")
            {
                var icons = IconCompletionProvider.GetIcons(member);

                if (icons != null && !icons.ContainsKey(member.UnquotedValueText))
                {
                    JsonErrorTag error = new JsonErrorTag
                    {
                        Flags = JSONErrorFlags.ErrorListError | JSONErrorFlags.UnderlineRed,
                        Item = member.Value,
                        Start = member.Value.Start,
                        AfterEnd = member.Value.AfterEnd,
                        Length = member.Value.Length,
                        Text = $"The icon \"{member.UnquotedValueText}\" has not been declared"
                    };

                    Telemetry.TrackEvent("Icon no declared");
                    context.AddError(error);
                }
            }

            return JSONItemValidationResult.Continue;
        }
        public JSONItemValidationResult ValidateItem(JSONParseItem item, IJSONValidationContext context)
        {
            JSONMember member = item as JSONMember;

            if (member == null || !member.UnquotedValueText.Contains("{{"))
                return JSONItemValidationResult.Continue;

            var variables = GetVariables(member);
            var regex = new Regex("{{(?<name>[^}{]+)}}", RegexOptions.Compiled);

            foreach (Match match in regex.Matches(member.UnquotedValueText))
            {
                Group group = match.Groups["name"];
                string name = group.Value;

                if (!variables.Contains(name))
                {
                    JsonErrorTag error = new JsonErrorTag
                    {
                        Flags = JSONErrorFlags.ErrorListError | JSONErrorFlags.UnderlineRed,
                        Item = member.Value,
                        Start = member.Value.Start + group.Index + 1, // 1 is for the quotation mark
                        AfterEnd = member.Value.Start + group.Index + group.Length,
                        Length = group.Length,
                        Text = $"The variable \"{name}\" has not been declared"
                    };

                    Telemetry.TrackEvent("Icon no declared");
                    context.AddError(error);
                }
            }

            return JSONItemValidationResult.Continue;
        }
        public JSONItemValidationResult ValidateItem(JSONParseItem item, IJSONValidationContext context)
        {
            JSONMember member = item as JSONMember;
            JSONMember icons = item?.Parent?.FindType<JSONMember>();

            if (icons != null && icons.UnquotedNameText == "icons")
            {
                string folder = Path.GetDirectoryName(item.JSONDocument.DocumentLocation);
                string file = Path.Combine(folder, member.UnquotedValueText);

                if (!File.Exists(file))
                {
                    JsonErrorTag error = new JsonErrorTag
                    {
                        Flags = JSONErrorFlags.ErrorListError | JSONErrorFlags.UnderlineRed,
                        Item = member.Value,
                        Start = member.Value.Start,
                        AfterEnd = member.Value.AfterEnd,
                        Length = member.Value.Length,
                        Text = $"The file \"{member.UnquotedValueText}\" does not exist"
                    };

                    Telemetry.TrackEvent("Icon file missing");
                    context.AddError(error);
                }
            }

            return JSONItemValidationResult.Continue;
        }
        public JSONItemValidationResult ValidateItem(JSONParseItem item, IJSONValidationContext context)
        {
            JSONMember member = item as JSONMember;

            if (member != null && member.UnquotedNameText == "icon")
            {
                var icons = IconCompletionProvider.GetIcons(member);

                if (icons != null && !icons.ContainsKey(member.UnquotedValueText))
                {
                    JsonErrorTag error = new JsonErrorTag
                    {
                        Flags    = JSONErrorFlags.ErrorListError | JSONErrorFlags.UnderlineRed,
                        Item     = member.Value,
                        Start    = member.Value.Start,
                        AfterEnd = member.Value.AfterEnd,
                        Length   = member.Value.Length,
                        Text     = $"The icon \"{member.UnquotedValueText}\" has not been declared"
                    };

                    Telemetry.TrackEvent("Icon no declared");
                    context.AddError(error);
                }
            }

            return(JSONItemValidationResult.Continue);
        }
        public JSONItemValidationResult ValidateItem(JSONParseItem item, IJSONValidationContext context)
        {
            JSONMember member = item as JSONMember;

            if (member == null || !member.UnquotedValueText.Contains("{{"))
            {
                return(JSONItemValidationResult.Continue);
            }

            var variables = GetVariables(member);
            var regex     = new Regex("{{(?<name>[^}{]+)}}", RegexOptions.Compiled);

            foreach (Match match in regex.Matches(member.UnquotedValueText))
            {
                Group  group = match.Groups["name"];
                string name  = group.Value;

                if (!variables.Contains(name))
                {
                    JsonErrorTag error = new JsonErrorTag
                    {
                        Flags    = JSONErrorFlags.ErrorListError | JSONErrorFlags.UnderlineRed,
                        Item     = member.Value,
                        Start    = member.Value.Start + group.Index + 1, // 1 is for the quotation mark
                        AfterEnd = member.Value.Start + group.Index + group.Length,
                        Length   = group.Length,
                        Text     = $"The variable \"{name}\" has not been declared"
                    };

                    Telemetry.TrackEvent("Icon no declared");
                    context.AddError(error);
                }
            }

            return(JSONItemValidationResult.Continue);
        }