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; 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.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; }
protected override JSONItemValidationResult ValidateJsonItem(JSONParseItem item, IJSONValidationContext context) { var member = item.FindType<JSONMember>(); if (member == null || member.UnquotedNameText != "files") return JSONItemValidationResult.Continue; var package = member.Parent?.Parent as JSONMember; var packages = package?.Parent?.Parent as JSONMember; if (package == null || packages == null || packages.UnquotedNameText != "packages") return JSONItemValidationResult.Continue; var parent = member.Parent as JSONObject; var children = parent?.BlockItemChildren.OfType<JSONMember>(); var version = children?.SingleOrDefault(c => c.UnquotedNameText == "version"); if (version == null) return JSONItemValidationResult.Continue; var installable = VSPackage.Manager.Provider.GetInstallablePackageAsync(package.UnquotedNameText, version.UnquotedValueText).Result; if (installable == null) return JSONItemValidationResult.Continue; if (!installable.AllFiles.Contains(item.Text.Trim('"', ','))) { string message = $"({VSPackage.Name}) {item.Text} is not a valid file name for {package.Name.Text}."; AddError(context, item, message); } return JSONItemValidationResult.Continue; }
public JSONItemValidationResult ValidateItem(JSONParseItem item, IJSONValidationContext context) { if (!VSPackage.Manager.Provider.IsInitialized) return JSONItemValidationResult.Continue; return ValidateJsonItem(item, context); }
public JSONItemValidationResult ValidateItem(JSONParseItem item, IJSONValidationContext context) { JSONMember member = item as JSONMember; if (member != null && member.Name != null && member.Name.Text == "\"$ref\"") { var parent = member.FindType<JSONBlockItem>(); // Only show error when $ref is not the only property in the object if (parent == null || parent.BlockItemChildren.Count() == 1) return JSONItemValidationResult.Continue; JsonErrorTag error = new JsonErrorTag { Flags = JSONErrorFlags.UnderlineBlue | JSONErrorFlags.ErrorListMessage, Item = member.Name, Start = member.Name.Start, AfterEnd = member.Name.AfterEnd, Length = member.Name.Length, Text = "When $ref is present, all other attributes are ignored" }; 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; 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.Name != null && member.Name.Text == "\"$ref\"") { var parent = member.FindType <JSONBlockItem>(); // Only show error when $ref is not the only property in the object if (parent == null || parent.BlockItemChildren.Count() == 1) { return(JSONItemValidationResult.Continue); } JsonErrorTag error = new JsonErrorTag { Flags = JSONErrorFlags.UnderlineBlue | JSONErrorFlags.ErrorListMessage, Item = member.Name, Start = member.Name.Start, AfterEnd = member.Name.AfterEnd, Length = member.Name.Length, Text = "When $ref is present, all other attributes are ignored" }; context.AddError(error); } return(JSONItemValidationResult.Continue); }
public JSONItemValidationResult ValidateItem(JSONParseItem item, IJSONValidationContext context) { if (!VSPackage.Manager.Provider.IsInitialized) return JSONItemValidationResult.Continue; if (item.JSONDocument.HasSchema(_reportCache)) { return ValidateJsonItem(item, context); } return JSONItemValidationResult.Continue; }
public JSONItemValidationResult ValidateItem(JSONParseItem item, IJSONValidationContext context) { if (!VSPackage.Manager.Provider.IsInitialized) { return(JSONItemValidationResult.Continue); } if (item.JSONDocument.HasSchema(_reportCache)) { return(ValidateJsonItem(item, context)); } return(JSONItemValidationResult.Continue); }
protected static void AddError(IJSONValidationContext context, JSONParseItem item, string message) { if (item == null) return; var error = new JsonErrorTag { Flags = JSONErrorFlags.ErrorListError | JSONErrorFlags.UnderlineRed, Item = item, Start = item.Start, AfterEnd = item.AfterEnd, Length = item.Length, Text = message }; context.AddError(error); }
protected override JSONItemValidationResult ValidateJsonItem(JSONParseItem item, IJSONValidationContext context) { var member = item as JSONMember; var packages = item.Parent?.Parent as JSONMember; if (packages == null || packages.UnquotedNameText != "packages") return JSONItemValidationResult.Continue; var names = VSPackage.Manager.Provider.GetPackageNamesAsync().Result; if (names != null && !names.Contains(member.UnquotedNameText)) { string message = $"({VSPackage.Name}) The package \"{member.UnquotedNameText}\" does not exist"; AddError(context, member.Name, message); } return JSONItemValidationResult.Continue; }
protected static void AddError(IJSONValidationContext context, JSONParseItem item, string message) { if (item == null) { return; } var error = new JsonErrorTag { Flags = JSONErrorFlags.ErrorListError | JSONErrorFlags.UnderlineRed, Item = item, Start = item.Start, AfterEnd = item.AfterEnd, Length = item.Length, Text = message }; context.AddError(error); }
protected override JSONItemValidationResult ValidateJsonItem(JSONParseItem item, IJSONValidationContext context) { var member = item as JSONMember; var packages = item.Parent?.Parent as JSONMember; if (packages == null || packages.UnquotedNameText != "packages") return JSONItemValidationResult.Continue; var children = (member.Value as JSONObject)?.BlockItemChildren?.OfType<JSONMember>(); if (!children.Any(c => c.UnquotedNameText == "version")) return JSONItemValidationResult.Continue; var names = VSPackage.Manager.Provider.GetPackageNamesAsync().Result; if (names != null && !names.Contains(member.UnquotedNameText)) { string message = $"({Vsix.Name}) The package \"{member.UnquotedNameText}\" does not exist"; AddError(context, member.Name, message); } return JSONItemValidationResult.Continue; }
protected override JSONItemValidationResult ValidateJsonItem(JSONParseItem item, IJSONValidationContext context) { var member = item as JSONMember; if (member.UnquotedNameText != "version") return JSONItemValidationResult.Continue; var package = item.Parent?.Parent as JSONMember; var packages = package?.Parent?.Parent as JSONMember; if (package == null ||packages == null || packages.UnquotedNameText != "packages") return JSONItemValidationResult.Continue; var versions = VSPackage.Manager.Provider.GetVersionsAsync(package.UnquotedNameText).Result; if (versions != null && !versions.Contains(member.UnquotedValueText)) { string message = $"({Vsix.Name}) \"{member.UnquotedValueText}\" is not a valid version for \"{package.UnquotedNameText}\"."; AddError(context, member.Value, message); } 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); }
protected abstract JSONItemValidationResult ValidateJsonItem(JSONParseItem item, IJSONValidationContext context);
protected abstract JSONItemValidationResult ValidateJsonItem(JSONParseItem item, IJSONValidationContext context);
protected override JSONItemValidationResult ValidateJsonItem(JSONParseItem item, IJSONValidationContext context) { var member = item.FindType <JSONMember>(); if (member == null || member.UnquotedNameText != "files") { return(JSONItemValidationResult.Continue); } var package = member.Parent?.Parent as JSONMember; var packages = package?.Parent?.Parent as JSONMember; if (package == null || packages == null || packages.UnquotedNameText != "packages") { return(JSONItemValidationResult.Continue); } var parent = member.Parent as JSONObject; var children = parent?.BlockItemChildren.OfType <JSONMember>(); var version = children?.SingleOrDefault(c => c.UnquotedNameText == "version"); if (version == null) { return(JSONItemValidationResult.Continue); } var installable = VSPackage.Manager.Provider.GetInstallablePackageAsync(package.UnquotedNameText, version.UnquotedValueText).Result; if (installable == null) { return(JSONItemValidationResult.Continue); } if (!installable.AllFiles.Contains(item.Text.Trim('"', ','))) { string message = $"({Vsix.Name}) {item.Text} is not a valid file name for {installable.Name} {installable.Version}."; AddError(context, item, message); } return(JSONItemValidationResult.Continue); }
protected override JSONItemValidationResult ValidateJsonItem(JSONParseItem item, IJSONValidationContext context) { var member = item as JSONMember; if (member.UnquotedNameText != "version") { return(JSONItemValidationResult.Continue); } var package = item.Parent?.Parent as JSONMember; var packages = package?.Parent?.Parent as JSONMember; if (package == null || packages == null || packages.UnquotedNameText != "packages") { return(JSONItemValidationResult.Continue); } var versions = VSPackage.Manager.Provider.GetVersionsAsync(package.UnquotedNameText).Result; if (versions != null && !versions.Contains(member.UnquotedValueText)) { string message = $"({Vsix.Name}) \"{member.UnquotedValueText}\" is not a valid version for \"{package.UnquotedNameText}\"."; AddError(context, member.Value, message); } return(JSONItemValidationResult.Continue); }
protected override JSONItemValidationResult ValidateJsonItem(JSONParseItem item, IJSONValidationContext context) { var member = item as JSONMember; var packages = item.Parent?.Parent as JSONMember; if (packages == null || packages.UnquotedNameText != "packages") { return(JSONItemValidationResult.Continue); } var children = (member.Value as JSONObject)?.BlockItemChildren?.OfType <JSONMember>(); if (!children.Any(c => c.UnquotedNameText == "version")) { return(JSONItemValidationResult.Continue); } var names = VSPackage.Manager.Provider.GetPackageNamesAsync().Result; if (names != null && !names.Contains(member.UnquotedNameText)) { string message = $"({Vsix.Name}) The package \"{member.UnquotedNameText}\" does not exist"; AddError(context, member.Name, message); } return(JSONItemValidationResult.Continue); }