示例#1
0
        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);
        }
        private string AddMissingStandardDeclaration(StringBuilder sb, CssEditorDocument doc, ICssSchemaInstance rootSchema)
        {
            var visitor = new CssItemCollector <RuleBlock>(true);

            doc.Tree.StyleSheet.Accept(visitor);

            //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);
                    }
                }
            }

            return(sb.ToString());
        }
示例#4
0
        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);
        }
示例#5
0
        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, view));
            }
        }