コード例 #1
0
        public IEnumerable <ICssCompletionListEntry> GetListEntries(CssCompletionContext context)
        {
            if (!IsColorContext(context))
            {
                yield break;
            }

            StyleSheet         styleSheet = context.ContextItem.StyleSheet;
            CssVariableHelpers helper     = ((CssStyleSheet)styleSheet).CreateVariableHelpers();
            var declarations = helper.FindDeclaredVariables(styleSheet, context.SpanStart);

            // First collect variables from current documents
            foreach (CssVariableDeclaration color in declarations.Where(c => IsValidColor(c.Value.Text)))
            {
                yield return(new ColorSwatchIntellisense(color.VariableName.Text, color.Value.Text));
            }

            // Next, collect from imported documents
            using (MultiDocumentReadLock locks = CssDocumentHelpers.DocumentImportManager.LockImportedStyleSheets(styleSheet))
            {
                foreach (StyleSheet importedStyleSheet in locks.StyleSheets)
                {
                    declarations = helper.FindDeclaredVariables(importedStyleSheet, importedStyleSheet.AfterEnd);

                    foreach (CssVariableDeclaration color in declarations.Where(c => IsValidColor(c.Value.Text)))
                    {
                        yield return(new ColorSwatchIntellisense(color.VariableName.Text, color.Value.Text));
                    }
                }
            }
        }
コード例 #2
0
        public IEnumerable <ICssCompletionListEntry> GetListEntries(CssCompletionContext context)
        {
            if (!IsColorContext(context))
            {
                yield break;
            }

            StyleSheet         styleSheet = context.ContextItem.StyleSheet;
            CssVariableHelpers helper     = ((CssStyleSheet)styleSheet).CreateVariableHelpers();
            var declarations = helper.FindDeclaredVariables(styleSheet, context.SpanStart);

            // First collect variables from current document
            var varsCollection = new CssColorVariableCollector(declarations.Select(c => new CssVariable(c.VariableName.Text, c.Value.Text)));

            // Next, collect from imported documents
            using (MultiDocumentReadLock locks = CssDocumentHelpers.DocumentImportManager.LockImportedStyleSheets(styleSheet))
            {
                foreach (StyleSheet importedStyleSheet in locks.StyleSheets)
                {
                    declarations = helper.FindDeclaredVariables(importedStyleSheet, importedStyleSheet.AfterEnd);
                    varsCollection.AddMany(declarations.Select(c => new CssVariable(c.VariableName.Text, c.Value.Text)));
                }
            }

            foreach (var variable in varsCollection.GetEvaluatedColorVariables())
            {
                yield return(new ColorSwatchCompletionListEntry(variable.Name, variable.Value));
            }
        }