Esempio n. 1
0
        private CustomAnalysisTag RepurposeTagForSupplementaryAction(CustomAnalysisTag tag, AnalysisAction suppAction)
        {
            var catd = new CustomAnalysisTagDependencies
            {
                AnalyzedElement = tag.AnalyzedElement,
                Action          = suppAction,
                ElementName     = tag.ElementName,
                FileName        = tag.FileName,
                InsertPos       = tag.InsertPosition,
                Logger          = tag.Logger,
                ProjectFilePath = tag.ProjectFilePath,
                Snapshot        = tag.Snapshot,
                //// Don't need to set VsAbstraction as tags only need it for referencing settings but supplementary actions don't need to know about settings.
            };

            if (suppAction.Location == null)
            {
                catd.Span = tag.Span;
            }
            else
            {
                catd.Span = suppAction.Location.ToSpanPlusStartPos(tag.InsertPosition);
            }

            return(new CustomAnalysisTag(catd));
        }
        private CustomAnalysisTag RepurposeTagForSupplementaryAction(CustomAnalysisTag tag, AnalysisAction suppAction, string elementXaml)
        {
            var ae = RapidXamlElementExtractor.GetElement(elementXaml, tag.AnalyzedElement.Location.Start);

            var catd = new CustomAnalysisTagDependencies
            {
                AnalyzedElement = ae,
                Action          = suppAction,
                ElementName     = ae.Name,
                FileName        = tag.FileName,
                InsertPos       = tag.InsertPosition,
                Logger          = tag.Logger,
                ProjectFilePath = tag.ProjectFilePath,
                Snapshot        = tag.Snapshot,
                //// Don't need to set VsAbstraction as tags only need it for referencing settings but supplementary actions don't need to know about settings.
            };

            if (suppAction.Location == null)
            {
                if (tag.Action == ActionType.RenameElement)
                {
                    catd.Span = new Span(tag.Span.Start, tag.Name.Length);
                }
                else
                {
                    catd.Span = tag.Span;
                }
            }
            else
            {
                catd.Span = suppAction.Location.ToSpanPlusStartPos(tag.InsertPosition);
            }

            return(new CustomAnalysisTag(catd));
        }
        public override void Process(string fileName, int offset, string xamlElement, string linePadding, ITextSnapshot snapshot, TagList tags, List <TagSuppression> suppressions = null)
        {
            var rxElement = RapidXamlElementExtractor.GetElement(xamlElement, offset);

            var details = new ExtraAnalysisDetails(fileName, ProjectFrameworkHelper.FromType(this.ProjectType));

            var analysisActions = this.customProcessor.Analyze(rxElement, details);

            if (!analysisActions.IsNone)
            {
                foreach (var action in analysisActions.Actions)
                {
                    var tagDeps = new CustomAnalysisTagDependencies
                    {
                        AnalyzedElement = rxElement,
                        Action          = action,
                        ElementName     = GetElementName(xamlElement), // Do this to get any xmlns
                        ErrorCode       = action.Code,
                        ErrorType       = TagErrorTypeCreator.FromCustomAnalysisErrorType(action.ErrorType),
                        FileName        = fileName,
                        InsertPos       = offset,
                        Logger          = this.Logger,
                        Snapshot        = snapshot,
                    };

                    // Treat `NotReallyCustomAnalyzer` types as any other built-in type.
                    // Track additional information about 3rd party custom analyzers.
                    if (this.customProcessor is CustomAnalysis.NotReallyCustomAnalyzer)
                    {
                        tagDeps.CustomFeatureUsageValue = this.customProcessor.GetType().Name;
                    }
                    else
                    {
                        tagDeps.CustomFeatureUsageValue = $"{this.customProcessor} {action.Code}";
                    }

                    if (action.Location == null)
                    {
                        // Add one to allow for opening angle bracket
                        tagDeps.Span = new Span(offset + 1, tagDeps.ElementName.Length); // Highlight only the opening element name
                    }
                    else
                    {
                        tagDeps.Span = action.Location.ToSpanPlusStartPos(offset);
                    }

                    tags.TryAdd(
                        new CustomAnalysisTag(tagDeps),
                        xamlElement,
                        suppressions);
                }
            }
        }
        private CustomAnalysisTag RepurposeTagForSupplementaryAction(CustomAnalysisTag tag, AnalysisAction suppAction)
        {
            var catd = new CustomAnalysisTagDependencies
            {
                AnalyzedElement = tag.AnalyzedElement,
                Action          = suppAction,
                ElementName     = tag.ElementName,
                FileName        = tag.FileName,
                InsertPos       = tag.InsertPosition,
                Logger          = tag.Logger,
                Snapshot        = tag.Snapshot,
            };

            if (suppAction.Location == null)
            {
                catd.Span = tag.Span;
            }
            else
            {
                catd.Span = suppAction.Location.ToSpanPlusStartPos(tag.InsertPosition);
            }

            return(new CustomAnalysisTag(catd));
        }