private static bool AddMissingStandardDeclaration(StringBuilder sb, CssEditorDocument doc, ICssSchemaInstance rootSchema, out int count) { bool hasChanged = false; var visitor = new CssItemCollector <RuleBlock>(true); doc.Tree.StyleSheet.Accept(visitor); count = 0; //var items = visitor.Items.Where(d => d.IsValid && d.IsVendorSpecific()); foreach (RuleBlock rule in visitor.Items.Reverse()) { HashSet <string> list = new HashSet <string>(); foreach (Declaration dec in rule.Declarations.Where(d => d.IsValid && d.IsVendorSpecific()).Reverse()) { ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(rootSchema, dec); ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(dec, schema); if (entry != null && !list.Contains(entry.DisplayText) && !rule.Declarations.Any(d => d.PropertyName != null && d.PropertyName.Text == entry.DisplayText)) { int index = dec.Text.IndexOf(":", StringComparison.Ordinal); string standard = entry.DisplayText + dec.Text.Substring(index); sb.Insert(dec.AfterEnd, standard); list.Add(entry.DisplayText); count++; hasChanged = true; } } } return(hasChanged); }
public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { Declaration dec = (Declaration)item; if (!item.IsValid || position > dec.Colon.Start || !view.TextBuffer.ContentType.IsOfType("css")) { yield break; } RuleBlock rule = dec.FindType <RuleBlock>(); if (!rule.IsValid) { yield break; } ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaRootForBuffer(view.TextBuffer); if (!dec.IsVendorSpecific()) { IEnumerable <Declaration> vendors = VendorHelpers.GetMatchingVendorEntriesInRule(dec, rule, schema); if (vendors.Any(v => v.Start > dec.Start)) { yield return(new VendorOrderSmartTagAction(itemTrackingSpan, vendors.Last(), dec, view)); } } else { ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(dec, schema); if (entry != null && !rule.Declarations.Any(d => d.PropertyName != null && d.PropertyName.Text == entry.DisplayText)) { yield return(new MissingStandardSmartTagAction(itemTrackingSpan, dec, entry.DisplayText, view)); } } }
public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context) { AtDirective directive = (AtDirective)item; if (context == null || !directive.IsValid || !directive.IsVendorSpecific()) { return(ItemCheckResult.Continue); } ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(directive, context); if (entry != null) { var visitor = new CssItemCollector <AtDirective>(); directive.Parent.Accept(visitor); if (!visitor.Items.Any(a => "@" + a.Keyword.Text == entry.DisplayText)) { string message = string.Format(CultureInfo.InvariantCulture, Resources.BestPracticeAddMissingStandardDirective, entry.DisplayText); context.AddError(new SimpleErrorTag(directive.Keyword, message)); return(ItemCheckResult.CancelCurrentItem); } } return(ItemCheckResult.Continue); }
public bool IsSupported(Version cssVersion, ICssCompletionListEntry entry) { if (WESettings.GetBoolean(WESettings.Keys.ShowUnsupported)) return entry.IsSupported(cssVersion); return entry.GetAttribute("browsers") != "none" || entry.DisplayText.Contains("gradient"); }
public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { Declaration dec = (Declaration)item; if (!item.IsValid || position > dec.Colon.Start || !EnsureInitialized(itemTrackingSpan.TextBuffer)) { yield break; } Microsoft.CSS.Core.TreeItems.RuleBlock rule = dec.FindType <RuleBlock>(); if (!rule.IsValid) { yield break; } if (!dec.IsVendorSpecific()) { IEnumerable <Declaration> vendors = VendorHelpers.GetMatchingVendorEntriesInRule(dec, rule, _schema); if (vendors.Any(v => v.Start > dec.Start)) { yield return(new VendorOrderSmartTagAction(itemTrackingSpan, vendors.Last(), dec)); } } else { ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(dec, _schema); if (entry != null && !rule.Declarations.Any(d => d.PropertyName != null && d.PropertyName.Text == entry.DisplayText)) { yield return(new MissingStandardSmartTagAction(itemTrackingSpan, dec, entry.DisplayText)); } } }
public void OnCommitted(ICssCompletionListEntry entry, ITrackingSpan contextSpan, SnapshotPoint caret, ITextView textView) { if (entry.DisplayText == "Add region...") { Dispatcher.CurrentDispatcher.BeginInvoke( new Action(() => System.Windows.Forms.SendKeys.Send("{TAB}")), DispatcherPriority.Normal); } }
public void OnCommitted(ICssCompletionListEntry entry, Microsoft.VisualStudio.Text.ITrackingSpan contextSpan, Microsoft.VisualStudio.Text.SnapshotPoint caret, Microsoft.VisualStudio.Text.Editor.ITextView textView) { if (Path.GetExtension(entry.DisplayText).Length == 0) { Dispatcher.CurrentDispatcher.BeginInvoke( new Action(() => CssCompletionController.FromView(textView).OnShowMemberList(filterList: true)), DispatcherPriority.Normal); } }
public void OnCommitted(ICssCompletionListEntry entry, Microsoft.VisualStudio.Text.ITrackingSpan contextSpan, Microsoft.VisualStudio.Text.SnapshotPoint caret, Microsoft.VisualStudio.Text.Editor.ITextView textView) { if (Path.GetExtension(entry.DisplayText).Length == 0) { Dispatcher.CurrentDispatcher.BeginInvoke( new Action(() => CssCompletionController.FromView(textView).OnShowMemberList(filterList: true, autoShown: true)), DispatcherPriority.Normal); } }
public void OnCommitted(ICssCompletionListEntry entry, ITrackingSpan contextSpan, SnapshotPoint caret, ITextView textView) { if (entry.DisplayText == "Add region...") { Dispatcher.CurrentDispatcher.BeginInvoke( new Action(() => System.Windows.Forms.SendKeys.Send("{TAB}")), DispatcherPriority.Normal); } }
private static void WriteBrowserSupport(XmlWriter writer, ICssCompletionListEntry entry) { string attr = entry.GetAttribute("browsers"); if (string.IsNullOrEmpty(attr)) attr = "all"; writer.WriteAttributeString("browsers", attr); }
public bool IsSupported(Version cssVersion, ICssCompletionListEntry entry) { if (WESettings.GetBoolean(WESettings.Keys.ShowUnsupported)) { return(entry.IsSupported(cssVersion)); } return(entry.GetAttribute("browsers") != "none" || entry.DisplayText.Contains("gradient")); }
public void OnCommitted(ICssCompletionListEntry entry, ITrackingSpan contextSpan, SnapshotPoint caret, ITextView textView) { if (entry.DisplayText == "Pick from file...") { string fontFamily; string atDirective = GetFontFromFile(entry.DisplayText, (IWpfTextView)textView, out fontFamily); Dispatcher.CurrentDispatcher.BeginInvoke( new Action(() => Replace(contextSpan, textView, atDirective, fontFamily)), DispatcherPriority.Normal); } }
public static IEnumerable<string> GetPossibleVendorSpecifics(this Declaration declaration, ICssSchemaInstance schema) { string text = declaration.PropertyName.Text; foreach (string prefix in VendorHelpers.GetPrefixes(schema)) { ICssCompletionListEntry entry = schema.GetProperty(prefix + text); if (entry != null && string.IsNullOrEmpty(entry.GetAttribute("obsolete"))) yield return entry.DisplayText; } }
private static void WriteBrowserSupport(XmlWriter writer, ICssCompletionListEntry entry) { string attr = entry.GetAttribute("browsers"); if (string.IsNullOrEmpty(attr)) { attr = "all"; } writer.WriteAttributeString("browsers", attr); }
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 void OnCommitted(ICssCompletionListEntry entry, ITrackingSpan contextSpan, SnapshotPoint caret, ITextView textView) { if (entry.DisplayText == "Pick from file...") { string fontFamily; string atDirective = GetFontFromFile(entry.DisplayText, (IWpfTextView)textView, out fontFamily); Dispatcher.CurrentDispatcher.BeginInvoke( new Action(() => Replace(contextSpan, textView, atDirective, fontFamily)), DispatcherPriority.Normal); } }
public void FilterCompletionList(IList <CssCompletionEntry> completions, CssCompletionContext context) { ICssSchemaInstance rootSchema = CssSchemaManager.SchemaManager.GetSchemaRoot(null); ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(rootSchema, context.ContextItem); foreach (CssCompletionEntry entry in completions) { ICssCompletionListEntry prop = GetSchemaEntry(schema, context, entry); if (prop != null && !string.IsNullOrEmpty(prop.GetAttribute("obsolete"))) { entry.FilterType = CompletionEntryFilterTypes.NeverVisible; } } }
private static bool OpenReferenceUrl(Reference reference, string name, string baseUrl) { ICssCompletionListEntry entry = reference.Invoke(name); if (entry != null) { string text = entry.DisplayText; Uri url; if (Uri.TryCreate(baseUrl + text, UriKind.Absolute, out url)) { System.Diagnostics.Process.Start(url.ToString()); return(true); } } return(false); }
public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context) { Declaration dec = (Declaration)item; if (context == null || !dec.IsValid) { return(ItemCheckResult.Continue); } RuleBlock rule = dec.FindType <RuleBlock>(); if (!rule.IsValid) { return(ItemCheckResult.Continue); } if (!dec.IsVendorSpecific()) { ICssSchemaInstance schema = CssEditorChecker.GetSchemaForItem(context, item); bool hasVendor = VendorHelpers.HasVendorLaterInRule(dec, schema); if (hasVendor) { context.AddError(new SimpleErrorTag(dec.PropertyName, Resources.BestPracticeStandardPropertyOrder)); return(ItemCheckResult.CancelCurrentItem); } } else { ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(dec, context); if (entry != null && !rule.Declarations.Any(d => d.PropertyName != null && d.PropertyName.Text == entry.DisplayText)) { if (entry.DisplayText != "filter" && entry.DisplayText != "zoom" && entry.DisplayText != "behavior") { string message = string.Format(CultureInfo.InvariantCulture, Resources.BestPracticeAddMissingStandardProperty, entry.DisplayText); context.AddError(new SimpleErrorTag(dec.PropertyName, message)); return(ItemCheckResult.CancelCurrentItem); } } } return(ItemCheckResult.Continue); }
public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { AtDirective directive = (AtDirective)item; if (!item.IsValid || !directive.IsVendorSpecific()) { yield break; } ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaRootForBuffer(view.TextBuffer); var visitor = new CssItemCollector <AtDirective>(); directive.Parent.Accept(visitor); ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(directive, schema); if (entry != null && !visitor.Items.Any(d => d.Keyword != null && "@" + d.Keyword.Text == entry.DisplayText)) { yield return(new MissingStandardDirectiveSmartTagAction(itemTrackingSpan, directive, entry.DisplayText)); } }
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); }
public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context) { if (!WESettings.Instance.Css.ValidateVendorSpecifics) { return(ItemCheckResult.Continue); } Declaration dec = (Declaration)item; if (!dec.IsValid || !dec.IsVendorSpecific() || context == null) { return(ItemCheckResult.Continue); } ICssSchemaInstance rootSchema = CssSchemaManager.SchemaManager.GetSchemaRoot(null); ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(rootSchema, item); ICssCompletionListEntry prop = schema.GetProperty(dec.PropertyName.Text); if (prop == null) { string message = string.Format(CultureInfo.CurrentCulture, Resources.ValidationVendorDeclarations, dec.PropertyName.Text); context.AddError(new SimpleErrorTag(dec.PropertyName, message, CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); return(ItemCheckResult.CancelCurrentItem); } else { string obsolete = prop.GetAttribute("obsolete"); if (!string.IsNullOrEmpty(obsolete)) { string message = string.Format(CultureInfo.CurrentCulture, Resources.BestPracticeRemoveObsolete, dec.PropertyName.Text, obsolete); context.AddError(new SimpleErrorTag(dec.PropertyName, message, CssErrorFlags.TaskListMessage)); return(ItemCheckResult.CancelCurrentItem); } } return(ItemCheckResult.Continue); }
public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context) { if (!WESettings.Instance.Css.ValidateVendorSpecifics) { return(ItemCheckResult.Continue); } if (!item.IsValid || context == null) { return(ItemCheckResult.Continue); } ICssSchemaInstance rootSchema = CssSchemaManager.SchemaManager.GetSchemaRoot(null); ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(rootSchema, item); string normalized = item.Text.Trim(':'); ICssCompletionListEntry pseudo = schema.GetPseudo(item.Text); if (normalized.Length > 0 && normalized[0] == '-' && pseudo == null) { string message = string.Format(CultureInfo.CurrentCulture, Resources.ValidationVendorPseudo, item.Text); context.AddError(new SimpleErrorTag(item, message, CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); return(ItemCheckResult.CancelCurrentItem); } else if (pseudo != null) { string obsolete = pseudo.GetAttribute("obsolete"); if (!string.IsNullOrEmpty(obsolete)) { string message = string.Format(CultureInfo.CurrentCulture, Resources.BestPracticeRemoveObsolete, normalized, obsolete); context.AddError(new SimpleErrorTag(item, message, CssErrorFlags.TaskListMessage)); return(ItemCheckResult.CancelCurrentItem); } } return(ItemCheckResult.Continue); }
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)); } }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (session == null || qiContent == null || qiContent.Count > 0 || !WESettings.Instance.Css.ShowBrowserTooltip) { return; } SnapshotPoint?point = session.GetTriggerPoint(_buffer.CurrentSnapshot); if (!point.HasValue) { return; } var tree = CssEditorDocument.FromTextBuffer(_buffer); ParseItem item = tree.StyleSheet.ItemBeforePosition(point.Value.Position); if (item == null || !item.IsValid) { return; } ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(_rootSchema, item); Tuple <ParseItem, ICssCompletionListEntry> tuple = GetEntriesAndPoint(item, point.Value, schema); if (tuple == null) { return; } ParseItem tipItem = tuple.Item1; ICssCompletionListEntry entry = tuple.Item2; if (tipItem == null || entry == null) { return; } var ruleSet = item.FindType <RuleSet>(); //If the selector's full name would require computation (it's nested), compute it and add it to the output if (ruleSet != null && ruleSet.Parent.FindType <RuleSet>() != null) { qiContent.Add(LessDocument.GetLessSelectorName(ruleSet)); } applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tipItem.Start, tipItem.Length, SpanTrackingMode.EdgeNegative); string syntax = entry.GetSyntax(schema.Version); string b = entry.GetAttribute("browsers"); if (string.IsNullOrEmpty(b) && tipItem.Parent != null && tipItem.Parent is Declaration) { b = schema.GetProperty(((Declaration)tipItem.Parent).PropertyName.Text).GetAttribute("browsers"); if (string.IsNullOrEmpty(syntax)) { syntax = tipItem.Text; } } if (!string.IsNullOrEmpty(syntax)) { //var example = CreateExample(syntax); qiContent.Add("Example: " + syntax); } Dictionary <string, string> browsers = GetBrowsers(b); qiContent.Add(CreateBrowserList(browsers)); }