예제 #1
0
        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);
        }
예제 #2
0
        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);
        }