public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context) { if (!WESettings.GetBoolean(WESettings.Keys.ValidateVendorSpecifics)) { return(ItemCheckResult.Continue); } AtDirective dir = item as AtDirective; if (!dir.IsValid || !dir.IsVendorSpecific() || context == null) { return(ItemCheckResult.Continue); } ICssSchemaInstance rootSchema = CssSchemaManager.SchemaManager.GetSchemaRoot(null); ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(rootSchema, dir); if (schema.GetAtDirective("@" + dir.Keyword.Text) == null) { string message = string.Format(Resources.ValidationVendorDirective, dir.Keyword.Text); context.AddError(new SimpleErrorTag(dir.Keyword, message, CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); return(ItemCheckResult.CancelCurrentItem); } return(ItemCheckResult.Continue); }
public static IEnumerable<string> GetPossibleVendorSpecifics(this AtDirective directive, ICssSchemaInstance schema) { string text = directive.Keyword.Text; foreach (string prefix in VendorHelpers.GetPrefixes(schema).Where(p => p != "-o-")) // Remove -o- since the parser doesn't recognize -o-keyframes { ICssCompletionListEntry entry = schema.GetAtDirective("@" + prefix + text); if (entry != null) yield return entry.DisplayText; } }
public static IEnumerable<string> GetPossibleVendorSpecifics(this AtDirective directive, ICssSchemaInstance schema) { string text = directive.Keyword.Text; foreach (string prefix in VendorHelpers.GetPrefixes(schema).Where(p => p != "-o-")) // Remove -o- since the parser doesn't recognize -o-keyframes { ICssCompletionListEntry entry = schema.GetAtDirective("@" + prefix + text); if (entry != null && string.IsNullOrEmpty(entry.GetAttribute("obsolete"))) yield return entry.DisplayText; } }
public static ICssCompletionListEntry GetMatchingStandardEntry(AtDirective directive, ICssSchemaInstance rootSchema) { string standardName; if (directive.TryGetStandardPropertyName(out standardName, rootSchema)) { ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(rootSchema, directive); return(schema.GetAtDirective("@" + standardName)); } return(null); }
public static ICssCompletionListEntry GetMatchingStandardEntry(AtDirective directive, ICssCheckerContext context) { string standardName; if (directive.TryGetStandardPropertyName(out standardName, CssEditorChecker.GetSchemaForItem(context, directive))) { ICssSchemaInstance schema = CssEditorChecker.GetSchemaForItem(context, directive); return(schema.GetAtDirective("@" + standardName)); } return(null); }
private static ICssCompletionListEntry GetSchemaEntry(ICssSchemaInstance schema, CssCompletionContext context, CssCompletionEntry entry) { switch (context.ContextType) { case CssCompletionContextType.AtDirectiveName: return schema.GetAtDirective(entry.DisplayText); case CssCompletionContextType.PropertyName: return schema.GetProperty(entry.DisplayText); case CssCompletionContextType.PseudoClassOrElement: return schema.GetPseudo(entry.DisplayText); } return null; }
private static ICssCompletionListEntry GetSchemaEntry(ICssSchemaInstance schema, CssCompletionContext context, CssCompletionEntry entry) { switch (context.ContextType) { case CssCompletionContextType.AtDirectiveName: return(schema.GetAtDirective(entry.DisplayText)); case CssCompletionContextType.PropertyName: return(schema.GetProperty(entry.DisplayText)); case CssCompletionContextType.PseudoClassOrElement: return(schema.GetPseudo(entry.DisplayText)); } return(null); }
public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context) { if (!WESettings.Instance.Css.ValidateVendorSpecifics) { return(ItemCheckResult.Continue); } AtDirective dir = item as AtDirective; if (!dir.IsValid || !dir.IsVendorSpecific() || context == null) { return(ItemCheckResult.Continue); } ICssSchemaInstance rootSchema = CssSchemaManager.SchemaManager.GetSchemaRoot(null); ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(rootSchema, dir); ICssCompletionListEntry at = schema.GetAtDirective("@" + dir.Keyword.Text); if (at == null) { string message = string.Format(CultureInfo.CurrentCulture, Resources.ValidationVendorDirective, dir.Keyword.Text); context.AddError(new SimpleErrorTag(dir.Keyword, message, CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); return(ItemCheckResult.CancelCurrentItem); } else { string obsolete = at.GetAttribute("obsolete"); if (!string.IsNullOrEmpty(obsolete)) { string message = string.Format(CultureInfo.CurrentCulture, Resources.BestPracticeRemoveObsolete, "@" + dir.Keyword.Text, obsolete); context.AddError(new SimpleErrorTag(dir.Keyword, message, CssErrorFlags.TaskListMessage)); return(ItemCheckResult.CancelCurrentItem); } } return(ItemCheckResult.Continue); }
private static Tuple<ParseItem, ICssCompletionListEntry> GetEntriesAndPoint(ParseItem item, SnapshotPoint point, ICssSchemaInstance schema) { // Declaration Declaration dec = item.FindType<Declaration>(); if (dec != null && dec.PropertyName != null && dec.PropertyName.ContainsRange(point.Position, 1)) { return Tuple.Create<ParseItem, ICssCompletionListEntry>(dec.PropertyName, schema.GetProperty(dec.PropertyName.Text)); } if (dec != null && dec.IsValid && dec.Values.TextStart <= point.Position && dec.Values.TextAfterEnd >= point.Position) { var entry = schema.GetProperty(dec.PropertyName.Text); if (entry != null) { var list = schema.GetPropertyValues(entry.DisplayText); var theOne = dec.StyleSheet.ItemFromRange(point.Position, 0); return Tuple.Create<ParseItem, ICssCompletionListEntry>(theOne, list.SingleOrDefault(r => r.DisplayText.Equals(theOne.Text, StringComparison.OrdinalIgnoreCase))); } } // Pseudo class PseudoClassSelector pseudoClass = item.FindType<PseudoClassSelector>(); if (pseudoClass != null) { return Tuple.Create<ParseItem, ICssCompletionListEntry>(pseudoClass, schema.GetPseudo(pseudoClass.Text)); } // Pseudo class function PseudoClassFunctionSelector pseudoClassFunction = item.FindType<PseudoClassFunctionSelector>(); if (pseudoClassFunction != null) { return Tuple.Create<ParseItem, ICssCompletionListEntry>(pseudoClassFunction, schema.GetPseudo(pseudoClassFunction.Text)); } // Pseudo element PseudoElementSelector pseudoElement = item.FindType<PseudoElementSelector>(); if (pseudoElement != null) { return Tuple.Create<ParseItem, ICssCompletionListEntry>(pseudoElement, schema.GetPseudo(pseudoElement.Text)); } // Pseudo element function PseudoElementFunctionSelector pseudoElementFunction = item.FindType<PseudoElementFunctionSelector>(); if (pseudoElementFunction != null) { return Tuple.Create<ParseItem, ICssCompletionListEntry>(pseudoElementFunction, schema.GetPseudo(pseudoElementFunction.Text)); } // @-directive AtDirective atDirective = item.Parent as AtDirective; if (atDirective != null && atDirective.Keyword != null) { return Tuple.Create<ParseItem, ICssCompletionListEntry>(atDirective.Keyword, schema.GetAtDirective("@" + atDirective.Keyword.Text)); } return null; }
private static Tuple <ParseItem, ICssCompletionListEntry> GetEntriesAndPoint(ParseItem item, SnapshotPoint point, ICssSchemaInstance schema) { // Declaration Declaration dec = item.FindType <Declaration>(); if (dec != null && dec.PropertyName != null && dec.PropertyName.ContainsRange(point.Position, 1)) { return(Tuple.Create <ParseItem, ICssCompletionListEntry>(dec.PropertyName, schema.GetProperty(dec.PropertyName.Text))); } if (dec != null && dec.IsValid && dec.Values.TextStart <= point.Position && dec.Values.TextAfterEnd >= point.Position) { var entry = schema.GetProperty(dec.PropertyName.Text); if (entry != null) { var list = schema.GetPropertyValues(entry.DisplayText); var theOne = dec.StyleSheet.ItemFromRange(point.Position, 0); return(Tuple.Create <ParseItem, ICssCompletionListEntry>(theOne, list.SingleOrDefault(r => r.DisplayText.Equals(theOne.Text, StringComparison.OrdinalIgnoreCase)))); } } // Pseudo class PseudoClassSelector pseudoClass = item.FindType <PseudoClassSelector>(); if (pseudoClass != null) { return(Tuple.Create <ParseItem, ICssCompletionListEntry>(pseudoClass, schema.GetPseudo(pseudoClass.Text))); } // Pseudo class function PseudoClassFunctionSelector pseudoClassFunction = item.FindType <PseudoClassFunctionSelector>(); if (pseudoClassFunction != null) { return(Tuple.Create <ParseItem, ICssCompletionListEntry>(pseudoClassFunction, schema.GetPseudo(pseudoClassFunction.Text))); } // Pseudo element PseudoElementSelector pseudoElement = item.FindType <PseudoElementSelector>(); if (pseudoElement != null) { return(Tuple.Create <ParseItem, ICssCompletionListEntry>(pseudoElement, schema.GetPseudo(pseudoElement.Text))); } // Pseudo element function PseudoElementFunctionSelector pseudoElementFunction = item.FindType <PseudoElementFunctionSelector>(); if (pseudoElementFunction != null) { return(Tuple.Create <ParseItem, ICssCompletionListEntry>(pseudoElementFunction, schema.GetPseudo(pseudoElementFunction.Text))); } // @-directive AtDirective atDirective = item.Parent as AtDirective; if (atDirective != null && atDirective.Keyword != null) { return(Tuple.Create <ParseItem, ICssCompletionListEntry>(atDirective.Keyword, schema.GetAtDirective("@" + atDirective.Keyword.Text))); } return(null); }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (!EnsureTreeInitialized() || session == null || qiContent == null || qiContent.Count > 0 || !WESettings.GetBoolean(WESettings.Keys.ShowBrowserTooltip)) { return; } SnapshotPoint?point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) { return; } ParseItem item = _tree.StyleSheet.ItemBeforePosition(point.Value.Position); if (item == null || !item.IsValid) { return; } ParseItem theOne = null; ICssCompletionListEntry entry = null; ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(_rootSchema, item); // Declaration Declaration dec = item.FindType <Declaration>(); if (dec != null && dec.PropertyName != null && dec.PropertyName.ContainsRange(point.Value.Position, 1)) { entry = schema.GetProperty(dec.PropertyName.Text); theOne = dec.PropertyName; } else if (dec != null && dec.IsValid && dec.Values.TextStart <= point.Value.Position && dec.Values.TextAfterEnd >= point.Value.Position) { entry = schema.GetProperty(dec.PropertyName.Text); if (entry != null) { var list = schema.GetPropertyValues(entry.DisplayText); theOne = dec.StyleSheet.ItemFromRange(point.Value.Position, 0); entry = list.SingleOrDefault(r => r.DisplayText.Equals(theOne.Text, StringComparison.OrdinalIgnoreCase)); } } // Pseudo class if (entry == null) { PseudoClassSelector pseudoClass = item.FindType <PseudoClassSelector>(); if (pseudoClass != null) { entry = schema.GetPseudo(pseudoClass.Text); theOne = pseudoClass; } } // Pseudo class function if (entry == null) { PseudoClassFunctionSelector pseudoClassFunction = item.FindType <PseudoClassFunctionSelector>(); if (pseudoClassFunction != null) { entry = schema.GetPseudo(pseudoClassFunction.Text); theOne = pseudoClassFunction; } } // Pseudo element if (entry == null) { PseudoElementSelector pseudoElement = item.FindType <PseudoElementSelector>(); if (pseudoElement != null) { entry = schema.GetPseudo(pseudoElement.Text); theOne = pseudoElement; } } // Pseudo element function if (entry == null) { PseudoElementFunctionSelector pseudoElementFunction = item.FindType <PseudoElementFunctionSelector>(); if (pseudoElementFunction != null) { entry = schema.GetPseudo(pseudoElementFunction.Text); theOne = pseudoElementFunction; } } // @-directive if (entry == null) { AtDirective atDirective = item.Parent as AtDirective; if (atDirective != null && atDirective.Keyword != null) { entry = schema.GetAtDirective("@" + atDirective.Keyword.Text); theOne = atDirective.Keyword; } } if (entry != null) { applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(theOne.Start, theOne.Length, SpanTrackingMode.EdgeNegative); string syntax = entry.GetSyntax(schema.Version); string b = entry.GetAttribute("browsers"); if (string.IsNullOrEmpty(b) && theOne.Parent != null && theOne.Parent is Declaration) { b = schema.GetProperty(((Declaration)theOne.Parent).PropertyName.Text).GetAttribute("browsers"); if (string.IsNullOrEmpty(syntax)) { syntax = theOne.Text; } } if (!string.IsNullOrEmpty(syntax)) { qiContent.Add("Example: " + syntax); } Dictionary <string, string> browsers = GetBrowsers(b); qiContent.Add(CreateBrowserList(browsers)); } }