public InstrumentationSyntaxRewriter(
     IEnumerable <SyntaxNode> instrumentedNodes,
     VariableLocationMap printOnce,
     AugmentationMap printEveryStep)
 {
     _variableLocations = printOnce ?? throw new ArgumentNullException(nameof(printOnce));
     _augmentations     = printEveryStep ?? throw new ArgumentNullException(nameof(printEveryStep));
     _instrumentedNodes = instrumentedNodes ?? throw new ArgumentNullException(nameof(instrumentedNodes));
 }
Esempio n. 2
0
        public InstrumentationSyntaxVisitor(
            Document document,
            SemanticModel semanticModel,
            IEnumerable <TextSpan> replacementRegions = null)
        {
            _document           = document ?? throw new ArgumentNullException(nameof(document));
            _semanticModel      = semanticModel ?? throw new ArgumentNullException(nameof(semanticModel));
            _replacementRegions = replacementRegions;
            VariableLocations   = new VariableLocationMap();
            Augmentations       = new AugmentationMap();

            Visit(_semanticModel.SyntaxTree.GetRoot());
        }
Esempio n. 3
0
        public static async Task <(AugmentationMap, VariableLocationMap)> MapLineLocationsRelativeToViewportAsync(
            AugmentationMap augmentationMap,
            VariableLocationMap locations,
            Document document,
            Viewport viewport = null)
        {
            if (viewport == null)
            {
                return(augmentationMap, locations);
            }

            var text = await document.GetTextAsync();

            var viewportSpan = viewport.Region.ToLinePositionSpan(text);

            var mappedAugmentations = MapAugmentationsToViewport();
            var mappedLocations     = MapVariableLocationsToViewport();

            return(mappedAugmentations, mappedLocations);

            AugmentationMap MapAugmentationsToViewport()
            {
                var augmentations = augmentationMap.Data.Values
                                    .Where(augmentation => viewportSpan.ContainsLine((int)augmentation.CurrentFilePosition.Line))
                                    .Select(augmentation => MapAugmentationToViewport(augmentation, viewportSpan));

                return(new AugmentationMap(augmentations.ToArray()));
            }

            VariableLocationMap MapVariableLocationsToViewport()
            {
                var variableLocationDictionary = locations.Data.ToDictionary(
                    kv => kv.Key,
                    kv =>
                {
                    var variableLocations = kv.Value;
                    return(new HashSet <VariableLocation>(variableLocations
                                                          .Where(loc => viewportSpan.ContainsLine(loc.StartLine) &&
                                                                 viewportSpan.ContainsLine(loc.EndLine))
                                                          .Select(location => MapVariableLocationToViewport(location, viewportSpan))));
                },
                    SymbolEqualityComparer.Default
                    );

                return(new VariableLocationMap
                {
                    Data = variableLocationDictionary
                });
            }
        }