Beispiel #1
0
        bool TryGetIssue(BaseCommandEventArgs e, out IssueMarker value)
        {
            value = null;
            IVsTextView tv = ((ISelectionContextEx)e.Selection).ActiveFrameTextView;

            if (tv == null)
            {
                LogMessageEditor editor = e.Selection.GetActiveControl<LogMessageEditor>();

                if (editor == null)
                    return false;

                tv = ((IAnkhHasVsTextView)editor).TextView;
            }

            int x, y;
            if (!ErrorHandler.Succeeded(tv.GetCaretPos(out y, out x)))
                return false;

            IVsTextLines lines;
            if (!ErrorHandler.Succeeded(tv.GetBuffer(out lines)))
                return false;

            string text, pre = null, post = null;

            text = GetLine(lines, y);

            if (string.IsNullOrEmpty(text))
                return false;

            string combined = null;
            int start = 0;
            if (y > 0)
            {
                pre = GetLine(lines, y - 1);
                combined = pre + '\n';
                start = combined.Length;
            }

            combined += text;

            post = GetLine(lines, y + 1);

            if (!string.IsNullOrEmpty(post))
                combined += '\n' + post;
            if ((y > 0) && !ErrorHandler.Succeeded(tv.GetTextStream(y - 1, 0, y, 0, out pre)))
                return false;

            if (!ErrorHandler.Succeeded(tv.GetTextStream(y + 1, 0, y + 2, 0, out post)))
                post = null;

            if (!string.IsNullOrEmpty(pre))
            {
                combined = pre.TrimEnd('\r', '\n') + '\n';
                start = combined.Length;
            }

            combined += text;

            if (!string.IsNullOrEmpty(post))
            {
                post = post.TrimEnd('\r', '\n');
                combined += '\n' + post;
            }

            if (_issueService == null)
                _issueService = e.GetService<IAnkhIssueService>();

            IEnumerable<IssueMarker> markers;

            int posToCheck = x + start;

            if (!_issueService.TryGetIssues(combined, out markers))
                return false;

            foreach (IssueMarker im in markers)
            {
                if (im.Index > posToCheck)
                    break;

                if (im.Index + im.Length >= posToCheck)
                {
                    value = im;
                    return true;
                }
            }

            return false;
        }
Beispiel #2
0
 /// <summary>
 /// Gets the issue references from the specified text
 /// </summary>
 /// <param name="text"></param>
 /// <param name="issues"></param>
 /// <returns></returns>
 public bool TryGetIssues(string text, out IEnumerable<IssueMarker> issues)
 {
     // potentially triggers
     // Issue Tracker Connector Package initialization
     IssueRepository repository = CurrentIssueRepository;
     if (repository != null)
     {
         if (_issueIdRegex == null)
         {
             string pattern = repository.IssueIdPattern;
             if (!string.IsNullOrEmpty(pattern))
             {
                 _issueIdRegex = new Regex(pattern, RegexOptions.CultureInvariant | RegexOptions.Multiline);
             }
         }
         if (_issueIdRegex != null)
         {
             issues = PerformRegex(text);
             return true;
         }
     }
     else if (GetService<IProjectCommitSettings>() != null)
     {
         issues = GetIssuesFromCommitSettings(text);
         return true;
     }
     // meaning
     // no solution
     // or no issue repository is associated with the solution
     // or issue repository does not provide an issue id pattern
     issues = new IssueMarker[0];
     return false;
 }