示例#1
0
            public FloatingQuickFixIconWidget(
                CodeActionEditorExtension codeActionEditorExtension,
                LanguageItemWindow window,
                SourceEditorView sourceEditorView,
                CodeActionContainer fixes,
                Cairo.Point point) : base(Gtk.WindowType.Popup)
            {
                this.ext              = codeActionEditorExtension;
                this.window           = window;
                this.sourceEditorView = sourceEditorView;
                this.fixes            = fixes;
                this.point            = point;
                this.Decorated        = false;
                this.Events          |= EventMask.ButtonPressMask | EventMask.LeaveNotifyMask | EventMask.EnterNotifyMask;
                TypeHint              = Gdk.WindowTypeHint.Utility;
                var fr = new Gtk.HBox();

                fr.BorderWidth = 2;
                var view = new ImageView(SmartTagMarginMarker.GetIconId(fixes.GetSmartTagSeverity()), Gtk.IconSize.Menu);

                fr.PackStart(view, false, false, 0);
                fr.PackEnd(new RectangleMarker(), false, false, 0);
                Add(fr);
                ext.FixesMenuClosed += Ext_FixesMenuClosed;

                ShowAll();
            }
示例#2
0
        static async Task <Tuple <CodeActionEditorExtension, Projects.Solution> > GatherFixesNoDispose <T> (string input, Action <ResultsEditorExtension, TaskCompletionSource <T> > callback, params int[] caretLocations)
        {
            await Ide.Composition.CompositionManager.InitializeAsync();

            TestWorkbenchWindow tww     = new TestWorkbenchWindow();
            TestViewContent     content = new TestViewContent();

            tww.ViewContent       = content;
            content.ContentName   = "/a.cs";
            content.Data.MimeType = "text/x-csharp";

            var doc = new Ide.Gui.Document(tww);

            var text = input;

            content.Text = text;

            var project = Projects.Services.ProjectService.CreateProject("C#");

            project.Name     = "test";
            project.FileName = "test.csproj";
            project.Files.Add(new ProjectFile(content.ContentName, BuildAction.Compile));
            var solution = new Projects.Solution();

            solution.AddConfiguration("", true);
            solution.DefaultSolutionFolder.AddItem(project);
            content.Project = project;
            doc.SetProject(project);

            using (var monitor = new ProgressMonitor())
                await TypeSystemService.Load(solution, monitor);

            var resultsExt = new ResultsEditorExtension();

            resultsExt.Initialize(doc.Editor, doc);
            content.Contents.Add(resultsExt);

            var compExt = new CodeActionEditorExtension();

            compExt.Initialize(doc.Editor, doc);
            content.Contents.Add(compExt);

            var tcs = new TaskCompletionSource <T> ();

            var cts = new CancellationTokenSource();

            cts.CancelAfter(60 * 1000);
            cts.Token.Register(() => tcs.TrySetCanceled());

            resultsExt.TasksUpdated += delegate {
                callback(resultsExt, tcs);
            };

            await doc.UpdateParseDocument();

            await Task.Run(() => tcs.Task);

            return(Tuple.Create(compExt, solution));
        }
示例#3
0
        protected override void Update(CommandArrayInfo ainfo)
        {
            var doc = IdeApp.Workbench.ActiveDocument;

            if (doc == null || doc.FileName == FilePath.Null)
            {
                return;
            }

            var parsedDocument = doc.ParsedDocument;

            if (parsedDocument == null || parsedDocument.IsInvalid)
            {
                return;
            }

            ResolveResult resolveResult;
            object        item  = GetItem(doc, out resolveResult);
            bool          added = false;

            var options = new RefactoringOptions(doc)
            {
                ResolveResult = resolveResult,
                SelectedItem  = item
            };

            var ciset = new CommandInfoSet();

            ciset.Text = GettextCatalog.GetString("Refactor");

            bool canRename;

            if (item is IVariable || item is IParameter)
            {
                canRename = true;
            }
            else if (item is ITypeDefinition)
            {
                canRename = !((ITypeDefinition)item).Region.IsEmpty;
            }
            else if (item is IType)
            {
                canRename = ((IType)item).Kind == TypeKind.TypeParameter;
            }
            else if (item is IMember)
            {
                canRename = !((IMember)item).Region.IsEmpty;
            }
            else if (item is INamespace)
            {
                canRename = true;
            }
            else
            {
                canRename = false;
            }
            if (canRename)
            {
                ciset.CommandInfos.Add(IdeApp.CommandService.GetCommandInfo(MonoDevelop.Ide.Commands.EditCommands.Rename), new Action(delegate {
                    new MonoDevelop.Refactoring.Rename.RenameHandler().Start(null);
                }));
                added = true;
            }

            foreach (var refactoring in RefactoringService.Refactorings)
            {
                if (refactoring.IsValid(options))
                {
                    CommandInfo info = new CommandInfo(refactoring.GetMenuDescription(options));
                    info.AccelKey = refactoring.AccelKey;
                    ciset.CommandInfos.Add(info, new Action(new RefactoringOperationWrapper(refactoring, options).Operation));
                }
            }
            var refactoringInfo = doc.Annotation <RefactoringDocumentInfo> ();

            if (refactoringInfo == null)
            {
                refactoringInfo = new RefactoringDocumentInfo();
                doc.AddAnnotation(refactoringInfo);
            }
            var  loc   = doc.Editor.Caret.Location;
            bool first = true;

            if (refactoringInfo.lastDocument != doc.ParsedDocument || loc != lastLocation)
            {
                if (QuickTaskStrip.EnableFancyFeatures)
                {
                    var ext = doc.GetContent <CodeActionEditorExtension> ();
                    refactoringInfo.validActions = ext != null?ext.GetCurrentFixes() : null;
                }
                else
                {
                    refactoringInfo.validActions = RefactoringService.GetValidActions(doc, loc).Result;
                }

                lastLocation = loc;
                refactoringInfo.lastDocument = doc.ParsedDocument;
            }
            if (refactoringInfo.validActions != null && refactoringInfo.lastDocument != null && refactoringInfo.lastDocument.CreateRefactoringContext != null)
            {
                var context = refactoringInfo.lastDocument.CreateRefactoringContext(doc, CancellationToken.None);

                foreach (var fix_ in refactoringInfo.validActions.OrderByDescending(i => Tuple.Create(CodeActionEditorExtension.IsAnalysisOrErrorFix(i), (int)i.Severity, CodeActionEditorExtension.GetUsage(i.IdString))))
                {
                    if (CodeActionEditorExtension.IsAnalysisOrErrorFix(fix_))
                    {
                        continue;
                    }
                    var fix = fix_;
                    if (first)
                    {
                        first = false;
                        if (ciset.CommandInfos.Count > 0)
                        {
                            ciset.CommandInfos.AddSeparator();
                        }
                    }

                    ciset.CommandInfos.Add(fix.Title, new Action(() => RefactoringService.ApplyFix(fix, context)));
                }
            }

            if (ciset.CommandInfos.Count > 0)
            {
                ainfo.Add(ciset, null);
                added = true;
            }

            if (IdeApp.ProjectOperations.CanJumpToDeclaration(item))
            {
                var type = item as IType;
                if (type != null && type.GetDefinition().Parts.Count > 1)
                {
                    var declSet = new CommandInfoSet();
                    declSet.Text = GettextCatalog.GetString("_Go to Declaration");
                    var ct = type.GetDefinition();
                    foreach (var part in ct.Parts)
                    {
                        declSet.CommandInfos.Add(string.Format(GettextCatalog.GetString("{0}, Line {1}"), FormatFileName(part.Region.FileName), part.Region.BeginLine), new System.Action(new JumpTo(part).Run));
                    }
                    ainfo.Add(declSet);
                }
                else
                {
                    ainfo.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.GotoDeclaration), new System.Action(new JumpTo(item).Run));
                }
                added = true;
            }

            if (item is IMember)
            {
                var member = (IMember)item;
                if (member.IsOverride || member.ImplementedInterfaceMembers.Any())
                {
                    ainfo.Add(GettextCatalog.GetString("Go to _Base Symbol"), new System.Action(new GotoBase(member).Run));
                    added = true;
                }
            }

            if (!(item is IMethod && ((IMethod)item).SymbolKind == SymbolKind.Operator) && (item is IEntity || item is ITypeParameter || item is IVariable || item is INamespace))
            {
                ainfo.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.FindReferences), new System.Action(new FindRefs(item, false).Run));
                if (doc.HasProject && HasOverloads(doc.Project.ParentSolution, item))
                {
                    ainfo.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.FindAllReferences), new System.Action(new FindRefs(item, true).Run));
                }
                added = true;
            }

            if (item is IMember)
            {
                var member = (IMember)item;
                if (member.IsVirtual || member.IsAbstract || member.DeclaringType.Kind == TypeKind.Interface)
                {
                    var handler = new FindDerivedSymbolsHandler(doc, member);
                    if (handler.IsValid)
                    {
                        ainfo.Add(GettextCatalog.GetString("Find Derived Symbols"), new System.Action(handler.Run));
                        added = true;
                    }
                }
            }
            if (item is IMember)
            {
                var member = (IMember)item;
                if (member.SymbolKind == SymbolKind.Method || member.SymbolKind == SymbolKind.Indexer)
                {
                    var findMemberOverloadsHandler = new FindMemberOverloadsHandler(doc, member);
                    if (findMemberOverloadsHandler.IsValid)
                    {
                        ainfo.Add(GettextCatalog.GetString("Find Member Overloads"), new System.Action(findMemberOverloadsHandler.Run));
                        added = true;
                    }
                }
            }

            if (item is ITypeDefinition)
            {
                ITypeDefinition cls = (ITypeDefinition)item;
                foreach (var bc in cls.DirectBaseTypes)
                {
                    if (bc != null && bc.GetDefinition() != null && bc.GetDefinition().Kind != TypeKind.Interface /* TODO: && IdeApp.ProjectOperations.CanJumpToDeclaration (bc)*/)
                    {
                        ainfo.Add(GettextCatalog.GetString("Go to _Base"), new System.Action(new GotoBase((ITypeDefinition)item).Run));
                        break;
                    }
                }
                if ((cls.Kind == TypeKind.Class && !cls.IsSealed) || cls.Kind == TypeKind.Interface)
                {
                    ainfo.Add(cls.Kind != TypeKind.Interface ? GettextCatalog.GetString("Find _derived classes") : GettextCatalog.GetString("Find _implementor classes"), new System.Action(new FindDerivedClasses(cls).Run));
                }
                ainfo.Add(GettextCatalog.GetString("Find Extension Methods"), new System.Action(new FindExtensionMethodHandler(doc, cls).Run));
                added = true;
            }

            if (added)
            {
                ainfo.AddSeparator();
            }
        }