public override IEnumerable <CodeIssue> GetIssues(object ctx, CancellationToken cancellationToken)
        {
            var context = ctx as MDRefactoringContext;

            if (context == null || context.IsInvalid || context.RootNode == null || context.ParsedDocument.HasErrors)
            {
                return(new CodeIssue[0]);
            }

            // Holds all the actions in a particular sibling group.
            IList <ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue> issues;

            using (var timer = counter.BeginTiming()) {
                // We need to enumerate here in order to time it.
                // This shouldn't be a problem since there are current very few (if any) lazy providers.
                var _issues = issueProvider.GetIssues(context);
                issues = _issues as IList <ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue> ?? _issues.ToList();
            }
            return(ToMonoDevelopRepresentation(cancellationToken, context, issues));
        }
Пример #2
0
        public override IEnumerable <CodeIssue> GetIssues(object ctx, CancellationToken cancellationToken)
        {
            var context = ctx as MDRefactoringContext;

            if (context == null || context.IsInvalid || context.RootNode == null || context.ParsedDocument.HasErrors)
            {
                yield break;
            }

            // Holds all the actions in a particular sibling group.
            var actionGroups = new Dictionary <object, IList <ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction> > ();

            foreach (var action in issueProvider.GetIssues(context))
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    yield break;
                }
                if (action.Actions == null)
                {
                    LoggingService.LogError("NRefactory actions == null in :" + Title);
                    continue;
                }
                var actions = new List <NRefactoryCodeAction> ();
                foreach (var act in action.Actions)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        yield break;
                    }
                    if (act == null)
                    {
                        LoggingService.LogError("NRefactory issue action was null in :" + Title);
                        continue;
                    }
                    var nrefactoryCodeAction = new NRefactoryCodeAction(IdString, act.Description, act, act.SiblingKey);
                    if (act.SiblingKey != null)
                    {
                        // make sure the action has a list of its siblings
                        IList <ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction> siblingGroup;
                        if (!actionGroups.TryGetValue(act.SiblingKey, out siblingGroup))
                        {
                            siblingGroup = new List <ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction> ();
                            actionGroups.Add(act.SiblingKey, siblingGroup);
                        }
                        siblingGroup.Add(act);
                        nrefactoryCodeAction.SiblingActions = siblingGroup;
                    }
                    actions.Add(nrefactoryCodeAction);
                }
                var issue = new CodeIssue(
                    GettextCatalog.GetString(action.Description ?? ""),
                    context.TextEditor.FileName,
                    action.Start,
                    action.End,
                    IdString,
                    actions
                    );
                yield return(issue);
            }
        }