Ejemplo n.º 1
0
        public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view)
        {
            RuleSet rule = item.FindType <RuleSet>();

            if (rule == null || rule.Block == null || !rule.Block.IsValid || UsageRegistry.IsRuleUsed(rule))
            {
                yield break;
            }

            yield return(new RemoveCssRuleSmartTagAction(itemTrackingSpan, rule));
        }
        private void BufferOnPostChanged(object sender, EventArgs eventArgs)
        {
            var fileName = _buffer.GetFileName();

            if (fileName == null)
            {
                return;
            }

            var doc = DocumentFactory.GetDocument(fileName);

            if (doc == null)
            {
                return;
            }

            doc.Reparse(_buffer.CurrentSnapshot.GetText());
            UsageRegistry.Resynchronize();
        }
        public IEnumerable <ITagSpan <IErrorTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            var fileName = _buffer.GetFileName();

            if (fileName == null)
            {
                return(new ITagSpan <UnusedCssTag> [0]);
            }

            var doc = DocumentFactory.GetDocument(fileName);

            if (doc == null)
            {
                return(new ITagSpan <UnusedCssTag> [0]);
            }

            var result = new List <ITagSpan <IErrorTag> >();

            using (AmbientRuleContext.GetOrCreate())
            {
                var applicableRules = UsageRegistry.GetAllUnusedRules(new HashSet <IStylingRule>(doc.Rules));

                foreach (var rule in applicableRules)
                {
                    try
                    {
                        result.Add(UnusedCssTag.FromRuleSet(_buffer, rule));
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        //Sometimes while the document is being modified and retagging is happening, a rule's boundary will momentarily be out of sync with the document and possibly past the end
                        //  this is a condition that may be safely ignored
                    }
                }
            }

            return(result);
        }