示例#1
0
        /// <summary>
        /// Analyze text for issues
        /// </summary>
        /// <param name="text">line of code</param>
        /// <param name="contenttype">VS Content Type</param>
        /// <returns>List of actionable and non-actionable issues</returns>
        public static Problem[] Analyze(string text, string contentType, string fileName)
        {
            List <Problem> results = new List <Problem>();

            Issue[] issues = _instance.processor.Analyze(text, _instance.GetLanguageList(contentType, fileName));

            // Add matches for errors
            foreach (Issue issue in issues)
            {
                results.Add(new Problem()
                {
                    Actionable = true, Issue = issue
                });
            }

            // Get list of IDs on the ignore list
            SuppressionEx supp = new SuppressionEx(text, contentType);

            string[] suppissues = supp.GetIssues();
            if (suppissues != null && suppissues.Count() > 0)
            {
                int index = supp.IssuesIndex;
                foreach (string id in suppissues)
                {
                    Issue issue = new Issue()
                    {
                        Index  = index,
                        Length = id.Length,
                        Rule   = _instance.ruleset.FirstOrDefault(x => x.Id == id)
                    };

                    if (issue.Rule != null)
                    {
                        results.Add(new Problem()
                        {
                            Actionable = false, Issue = issue
                        });
                    }

                    index += id.Length + 1;
                }
            }

            return(results.ToArray());
        }
示例#2
0
        public void Invoke(CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            string        fixedCode = string.Empty;
            SuppressionEx supp      = new SuppressionEx(_error, ContentType.GetLanguages(_snapshot.ContentType.TypeName)[0]);

            if (_rule == null)
            {
                fixedCode = supp.SuppressAll(_suppDate);
            }
            else
            {
                fixedCode = supp.SuppressIssue(_rule.Id, _suppDate);
            }

            _error.Snapshot.TextBuffer.Replace(_error.LineAndSuppressionCommentTrackingSpan.GetSpan(_error.Snapshot), fixedCode);
        }