Ejemplo n.º 1
0
        public TacticReplacerActor(ITextBuffer tb, int position = -1)
        {
            Contract.Requires(tb != null);
            string currentFileName;

            LoadStatus = RefactoringUtil.LoadAndCheckDocument(tb, out currentFileName) ? TacticReplaceStatus.Success : TacticReplaceStatus.NoDocumentPersistence;
            if (LoadStatus != TacticReplaceStatus.Success)
            {
                return;
            }
            var program = RefactoringUtil.GetReparsedProgram(tb, currentFileName, true);

            _tld        = RefactoringUtil.GetTld(program);
            _tldMembers = _tld?.Members.GetEnumerator();
            LoadStatus  = _tld != null ? TacticReplaceStatus.Success : TacticReplaceStatus.NotResolved;
            if (LoadStatus != TacticReplaceStatus.Success)
            {
                return;
            }
            if (position == -1)
            {
                return;
            }
            SetMember(position);
            SetTacticCall(position);
        }
Ejemplo n.º 2
0
        private void ProcessSomeMembers()
        {
            Begin();
            var p = RefactoringUtil.GetNewProgram(_tb);

            if (p == null)
            {
                NotifyStatusbar(DeadAnnotationStatus.NoProgram);
                Finish();
                return;
            }
            UpdateFilename(p.FullName);
            var notProcessedMembers = new List <MemberDecl>();
            var tld = RefactoringUtil.GetTld(p);

            _changesSinceLastSuccessfulRun.ForEach(i => {
                MemberDecl md;
                RefactoringUtil.GetMemberFromPosition(tld, i, out md);
                if (md != null && !notProcessedMembers.Contains(md))
                {
                    notProcessedMembers.Add(md);
                }
            });
            if (tld == null || notProcessedMembers.Count == 0)
            {
                NotifyStatusbar(DeadAnnotationStatus.NoChanges);
                Finish();
                return;
            }
            _thread = new Thread(ProcessSomeMembersThreaded);
            _thread.Start(new ThreadParams {
                P = p, M = notProcessedMembers, S = Snapshot, Stop = _currentStopper
            });
        }
Ejemplo n.º 3
0
        public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken)
        {
            var actionList      = new List <ISuggestedAction>();
            var currentSnapshot = range.Snapshot;

            var first = _agg.GetTags(range).FirstOrDefault();

            if (first != null)
            {
                actionList.Add(new RemoveDeadAnnotationSuggestedAction(currentSnapshot, first.Tag));
            }

            Program p;

            RefactoringUtil.GetExistingProgram(currentSnapshot.TextBuffer, out p);
            if (p == null)
            {
                return(Enumerable.Empty <SuggestedActionSet>());
            }
            var        tld = RefactoringUtil.GetTld(p);
            MemberDecl md;

            RefactoringUtil.GetMemberFromPosition(tld, range.Start, out md);
            if (md != null)
            {
                var methodSpan = RefactoringUtil.GetRangeOfMember(currentSnapshot, md);
                var tagSpans   = _agg.GetTags(methodSpan);
                var tags       = (from ts in tagSpans
                                  select new RemoveDeadAnnotationSuggestedAction(currentSnapshot, ts.Tag)).ToList();
                if (tags.Count > 0)
                {
                    actionList.Add(new RemoveMultipleDeadAnnotationsSuggestedAction(currentSnapshot.TextBuffer, tags, DeadAnnotationLocation.Block));
                }
            }

            var snapshotWideSpan = new SnapshotSpan(currentSnapshot, 0, currentSnapshot.Length);
            var allTags          = _agg.GetTags(snapshotWideSpan);
            var list             = allTags.Select(ts => new RemoveDeadAnnotationSuggestedAction(currentSnapshot, ts.Tag)).ToList();

            if (list.Count > 0)
            {
                actionList.Add(new RemoveMultipleDeadAnnotationsSuggestedAction(currentSnapshot.TextBuffer, list, DeadAnnotationLocation.File));
            }

            return(actionList.Count > 0 ?
                   new [] { new SuggestedActionSet(actionList.ToArray()) }
        : Enumerable.Empty <SuggestedActionSet>());
        }