Пример #1
0
        //private HashSet<string> _deprecated = new HashSet<string>()
        //{
        //    "-moz-opacity",
        //    "-moz-outline",
        //    "-moz-outline-style",
        //};

        public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context)
        {
            if (!WESettings.GetBoolean(WESettings.Keys.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);

            //if (_deprecated.Contains(dec.PropertyName.Text))
            //{
            //    string message = string.Format(Resources.ValidationDeprecatedVendorDeclaration, dec.PropertyName.Text);
            //    context.AddError(new SimpleErrorTag(dec.PropertyName, message));
            //    return ItemCheckResult.CancelCurrentItem;
            //}
            if (schema.GetProperty(dec.PropertyName.Text) == null)
            {
                string message = string.Format(Resources.ValidationVendorDeclarations, dec.PropertyName.Text);
                context.AddError(new SimpleErrorTag(dec.PropertyName, message, CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed));
                return(ItemCheckResult.CancelCurrentItem);
            }

            return(ItemCheckResult.Continue);
        }
        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)
                    yield return entry.DisplayText;
            }
        }
Пример #3
0
        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;
            }
        }
Пример #4
0
        public static ICssCompletionListEntry GetMatchingStandardEntry(Declaration declaration, ICssSchemaInstance rootSchema)
        {
            string standardName;

            if (declaration.TryGetStandardPropertyName(out standardName, rootSchema))
            {
                ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaForItem(rootSchema, declaration);
                return(schema.GetProperty(standardName));
            }

            return(null);
        }
Пример #5
0
        public static ICssCompletionListEntry GetMatchingStandardEntry(Declaration declaration, ICssCheckerContext context)
        {
            string standardName;

            if (declaration.TryGetStandardPropertyName(out standardName, CssEditorChecker.GetSchemaForItem(context, declaration)))
            {
                ICssSchemaInstance schema = CssEditorChecker.GetSchemaForItem(context, declaration);
                return(schema.GetProperty(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;
        }
Пример #7
0
        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);
            }

            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);
        }
        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 (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));
        }
        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);
        }
Пример #12
0
        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));
            }
        }