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 ColorSwatchIntellisense(variable.Name, variable.Value); } }
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)); } }