private RegionsToAnalyze GetOrSetCachedRegionsToAnalyzeInFile(SyntaxNode codeBlock) { SyntaxNode rootNode = codeBlock.Ancestors().Last(); SyntaxReference rootNodeRef = rootNode.GetReference(); if (_rootNodeToAnalyzerTextSpans.TryGetValue(rootNodeRef, out RegionsToAnalyze regionsToAnalyze)) { return(regionsToAnalyze); } regionsToAnalyze = RegionsToAnalyzeProvider.GetRegionsToAnalyze(rootNode); _rootNodeToAnalyzerTextSpans = _rootNodeToAnalyzerTextSpans.SetItem(rootNodeRef, regionsToAnalyze); Debug.WriteLine("Cache root node: " + rootNode); RemoveExcessCache(); return(regionsToAnalyze); }
private RegionsToAnalyze GetOrSetCachedRegionsToAnalyzeInFile(SyntaxNode codeBlock) { SyntaxNode rootNode = codeBlock.Ancestors().Last(); SyntaxReference rootNodeRef = rootNode.GetReference(); if (_rootNodeToAnalyzerTextSpans.TryGetValue(rootNodeRef, out var regionsToAnalyze)) { return(regionsToAnalyze); } regionsToAnalyze = RegionsToAnalyzeProvider.GetRegionsToAnalyze(rootNode); _rootNodeToAnalyzerTextSpans = _rootNodeToAnalyzerTextSpans.SetItem(rootNodeRef, regionsToAnalyze); Debug.WriteLine("Cache root node: " + rootNode); while (_rootNodeToAnalyzerTextSpans.Count > MaxRootNodeCacheCount) { SyntaxReference oldestCacheKey = _rootNodeToAnalyzerTextSpans.OrderBy(x => x.Value.Created) .Last().Key; _rootNodeToAnalyzerTextSpans = _rootNodeToAnalyzerTextSpans.Remove(oldestCacheKey); Debug.WriteLine("Remove cached item: " + oldestCacheKey); } return(regionsToAnalyze); }