private IEnumerable <ParseItem> GetColors(SnapshotSpan span) { ParseItem complexItem = _tree.StyleSheet.ItemFromRange(span.Start, span.Length); if (complexItem == null || (!(complexItem is AtDirective) && !(complexItem is RuleBlock) && !(complexItem is LessVariableDeclaration) && !(complexItem is FunctionArgument))) { return(Enumerable.Empty <ParseItem>()); } var colorCrawler = new CssItemAggregator <ParseItem>(filter: e => e.AfterEnd > span.Start && e.Start < span.End) { (HexColorValue h) => h, (FunctionColor c) => c, (TokenItem i) => (i.PreviousSibling == null || (i.PreviousSibling.Text != "@" && i.PreviousSibling.Text != "$")) && // Ignore variable names that happen to be colors i.TokenType == CssTokenType.Identifier && (i.FindType <Declaration>() != null || i.FindType <LessExpression>() != null) && // Ignore classnames that happen to be colors Color.FromName(i.Text).IsNamedColor ? i : null }; return(colorCrawler.Crawl(complexItem).Where(o => o != null)); //IEnumerable<ParseItem> declarations; //var lessVar = complexItem as LessVariableDeclaration; //if (lessVar != null) //{ // declarations = new[] { lessVar.Value }; //} //else //{ // declarations = new CssItemAggregator<ParseItem>(filter: e => e.AfterEnd > span.Start && e.Start < span.End) // { // (LessMixinArgument a) => a.Argument, // (LessMixinDeclarationArgument a) => a.Variable.Value, // (FunctionArgument a) => a.ArgumentItems // }.Crawl(complexItem).Where(d => d != null); //} //TODO: This doesn't seem to work correctly, probably because I'm reusing the mutable crawler. //return declarations.SelectMany(colorCrawler.Crawl).Where(o => o != null); }
private IEnumerable <ParseItem> GetColors(SnapshotSpan span) { ParseItem complexItem = _tree.StyleSheet.ItemFromRange(span.Start, span.Length); if (complexItem == null || (!(complexItem is AtDirective) && !(complexItem is RuleBlock) && !(complexItem is LessVariableDeclaration) && !(complexItem is FunctionArgument))) { return(Enumerable.Empty <ParseItem>()); } var colorCrawler = new CssItemAggregator <ParseItem>(filter: e => e.AfterEnd > span.Start && e.Start < span.End) { (HexColorValue h) => h, (FunctionColor c) => c, (TokenItem i) => (i.PreviousSibling == null || (i.PreviousSibling.Text != "@" && i.PreviousSibling.Text != "$")) && // Ignore variable names that happen to be colors i.TokenType == CssTokenType.Identifier && (i.FindType <Declaration>() != null || i.FindType <LessExpression>() != null) && // Ignore classnames that happen to be colors Color.FromName(i.Text).IsNamedColor ? i : null }; return(colorCrawler.Crawl(complexItem).Where(o => o != null)); }