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");
        }
        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"));
        }
Пример #4
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;
            }
        }
Пример #5
0
        private static void WriteBrowserSupport(XmlWriter writer, ICssCompletionListEntry entry)
        {
            string attr = entry.GetAttribute("browsers");

            if (string.IsNullOrEmpty(attr))
            {
                attr = "all";
            }

            writer.WriteAttributeString("browsers", attr);
        }
Пример #6
0
        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;
            }
        }
Пример #7
0
        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;
                }
            }
        }
Пример #8
0
        private bool OpenReferenceUrl(Reference reference, string name, string baseUrl)
        {
            ICssCompletionListEntry entry = reference.Invoke(name);

            if (entry != null)
            {
                entry.GetAttribute("standard-reference");
                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)
        {
            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 (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));
        }
Пример #13
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));
            }
        }