diff options
author | Lluis Sanchez <llsan@microsoft.com> | 2019-03-21 00:29:49 +0300 |
---|---|---|
committer | Lluis Sanchez <llsan@microsoft.com> | 2019-03-21 00:29:49 +0300 |
commit | 228695e2dc646fb2ad812c06bebfe33ca9f69601 (patch) | |
tree | 89a6f3a75447bc4a202add057b05fb67b68ac762 /main/src/addins/MonoDevelop.Refactoring | |
parent | 935f47982ef658566f1b1af36acdd5ca46cdb323 (diff) | |
parent | b14cae42f57650e9de2dd31d1beab5f90a4d44ec (diff) |
Merge remote-tracking branch 'xamarin/master-vnext' into new-service-model
Diffstat (limited to 'main/src/addins/MonoDevelop.Refactoring')
31 files changed, 440 insertions, 161 deletions
diff --git a/main/src/addins/MonoDevelop.Refactoring/AddinInfo.cs b/main/src/addins/MonoDevelop.Refactoring/AddinInfo.cs index 82feeebed9..dd2f65ac3e 100644 --- a/main/src/addins/MonoDevelop.Refactoring/AddinInfo.cs +++ b/main/src/addins/MonoDevelop.Refactoring/AddinInfo.cs @@ -15,4 +15,5 @@ using Mono.Addins.Description; [assembly:AddinDependency ("Ide", MonoDevelop.BuildInfo.Version)] [assembly:AddinDependency ("DesignerSupport", MonoDevelop.BuildInfo.Version)] [assembly:AddinDependency ("SourceEditor2", MonoDevelop.BuildInfo.Version)] +[assembly:AddinDependency ("TextEditor", MonoDevelop.BuildInfo.Version)] [assembly:AddinDependency ("RegexToolkit", MonoDevelop.BuildInfo.Version)] diff --git a/main/src/addins/MonoDevelop.Refactoring/Makefile.am b/main/src/addins/MonoDevelop.Refactoring/Makefile.am deleted file mode 100644 index c9cc87438f..0000000000 --- a/main/src/addins/MonoDevelop.Refactoring/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -include $(top_srcdir)/xbuild.include diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultTooltipProvider.FloatingQuickFixIconWidget.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultTooltipProvider.FloatingQuickFixIconWidget.cs index 270a1ca5a6..da38d852b2 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultTooltipProvider.FloatingQuickFixIconWidget.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultTooltipProvider.FloatingQuickFixIconWidget.cs @@ -47,7 +47,12 @@ namespace MonoDevelop.AnalysisCore.Gui readonly Cairo.Point point; uint destroyTimeout; - public FloatingQuickFixIconWidget (CodeActionEditorExtension codeActionEditorExtension, LanguageItemWindow window, SourceEditorView sourceEditorView, CodeActionContainer fixes, Cairo.Point point) : base (Gtk.WindowType.Popup) + public FloatingQuickFixIconWidget ( + CodeActionEditorExtension codeActionEditorExtension, + LanguageItemWindow window, + SourceEditorView sourceEditorView, + CodeActionContainer fixes, + Cairo.Point point) : base (Gtk.WindowType.Popup) { this.ext = codeActionEditorExtension; this.window = window; @@ -94,7 +99,7 @@ namespace MonoDevelop.AnalysisCore.Gui ext.CancelSmartTagPopupTimeout (); ext.smartTagPopupTimeoutId = GLib.Timeout.Add (150, delegate { ext.PopupQuickFixMenu (null, fixes, menu => { }, new Xwt.Point ( - point.X, + point.X, point.Y + Allocation.Height + 10)); ext.smartTagPopupTimeoutId = 0; return false; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultTooltipProvider.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultTooltipProvider.cs index e72923f9c3..58bcf884e6 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultTooltipProvider.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultTooltipProvider.cs @@ -49,10 +49,11 @@ using MonoDevelop.Ide; namespace MonoDevelop.AnalysisCore.Gui { + [Obsolete ("Old editor")] partial class ResultTooltipProvider : TooltipProvider { #region ITooltipProvider implementation - public override async Task<TooltipItem> GetItem (TextEditor editor, DocumentContext ctx, int offset, CancellationToken token = default (CancellationToken)) + public override async Task<TooltipItem> GetItem (Ide.Editor.TextEditor editor, DocumentContext ctx, int offset, CancellationToken token = default (CancellationToken)) { var results = new List<Result> (); int markerOffset = -1, markerEndOffset = -1; @@ -149,7 +150,7 @@ namespace MonoDevelop.AnalysisCore.Gui return new TooltipItem (tooltipInfo, markerOffset, markerEndOffset - markerOffset); } - public override Window CreateTooltipWindow (TextEditor editor, DocumentContext ctx, TooltipItem item, int offset, Xwt.ModifierKeys modifierState) + public override Window CreateTooltipWindow (Ide.Editor.TextEditor editor, DocumentContext ctx, TooltipItem item, int offset, Xwt.ModifierKeys modifierState) { var result = item.Item as TooltipInformation; if (result == null) @@ -165,9 +166,9 @@ namespace MonoDevelop.AnalysisCore.Gui return window; } - public override void GetRequiredPosition (TextEditor editor, Window tipWindow, out int requiredWidth, out double xalign) + public override void GetRequiredPosition (Ide.Editor.TextEditor editor, Window tipWindow, out int requiredWidth, out double xalign) { - var win = (LanguageItemWindow) tipWindow; + var win = (LanguageItemWindow)tipWindow; requiredWidth = win.SetMaxWidth (win.Screen.Width / 4); xalign = 0.5; } @@ -176,7 +177,7 @@ namespace MonoDevelop.AnalysisCore.Gui const int xPadding = 4; const int windowSize = 36; - protected override Xwt.Point CalculateWindowLocation (TextEditor editor, TooltipItem item, Xwt.WindowFrame xwtWindow, int mouseX, int mouseY, Xwt.Point origin) + protected override Xwt.Point CalculateWindowLocation (Ide.Editor.TextEditor editor, TooltipItem item, Xwt.WindowFrame xwtWindow, int mouseX, int mouseY, Xwt.Point origin) { int w; double xalign; @@ -212,7 +213,7 @@ namespace MonoDevelop.AnalysisCore.Gui return new Xwt.Point (x, y); } - public override void ShowTooltipWindow (TextEditor editor, Components.Window tipWindow, TooltipItem item, Xwt.ModifierKeys modifierState, int mouseX, int mouseY) + public override void ShowTooltipWindow (Ide.Editor.TextEditor editor, Components.Window tipWindow, TooltipItem item, Xwt.ModifierKeys modifierState, int mouseX, int mouseY) { base.ShowTooltipWindow (editor, tipWindow, item, modifierState, mouseX, mouseY); var info = (TaggedTooltipInformation<CodeActions.CodeActionContainer>)item.Item; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultsEditorExtension.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultsEditorExtension.cs index b2768902cb..3db1c4740a 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultsEditorExtension.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/Gui/ResultsEditorExtension.cs @@ -52,13 +52,14 @@ using MonoDevelop.Ide.Gui; namespace MonoDevelop.AnalysisCore.Gui { + [Obsolete ("Old editor")] class AnalysisDocument { - public TextEditor Editor { get; private set; } + public Ide.Editor.TextEditor Editor { get; private set; } public DocumentLocation CaretLocation { get; private set; } public DocumentContext DocumentContext { get; private set; } - public AnalysisDocument (TextEditor editor, DocumentContext documentContext) + public AnalysisDocument (Ide.Editor.TextEditor editor, DocumentContext documentContext) { this.Editor = editor; this.CaretLocation = editor.CaretLocation; @@ -66,6 +67,7 @@ namespace MonoDevelop.AnalysisCore.Gui } } + [Obsolete ("Old editor")] public class ResultsEditorExtension : TextEditorExtension, IQuickTaskProvider { bool disposed; @@ -320,7 +322,7 @@ namespace MonoDevelop.AnalysisCore.Gui GLib.Idle.Add (IdleHandler); } - static Cairo.Color GetColor (TextEditor editor, Result result) + static Cairo.Color GetColor (Ide.Editor.TextEditor editor, Result result) { switch (result.Level) { case DiagnosticSeverity.Hidden: diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs index 6fb4d6c177..38dd1c42a4 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs @@ -54,6 +54,7 @@ using Gdk; namespace MonoDevelop.CodeActions { + [Obsolete ("Old editor")] class CodeActionEditorExtension : TextEditorExtension { const int menuTimeout = 150; @@ -425,8 +426,10 @@ namespace MonoDevelop.CodeActions [CommandHandler (RefactoryCommands.QuickFix)] void OnQuickFixCommand () { - if (!AnalysisOptions.EnableFancyFeatures || smartTagMarginMarker == null) { - //Fixes = RefactoringService.GetValidActions (Editor, DocumentContext, Editor.CaretLocation).Result; + if (!AnalysisOptions.EnableFancyFeatures + || smartTagMarginMarker == null + ) { + // Fixes = RefactoringService.GetValidActions (Editor, DocumentContext, Editor.CaretLocation).Result; PopupQuickFixMenu (null, null); return; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeFixMenuService.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeFixMenuService.cs index bb43e7b75f..c211e4d2a7 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeFixMenuService.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeFixMenuService.cs @@ -53,9 +53,10 @@ using MonoDevelop.AnalysisCore; namespace MonoDevelop.CodeActions { + [Obsolete ("Old editor")] internal static class CodeFixMenuService { - public static CodeFixMenu CreateFixMenu (TextEditor editor, CodeActionContainer fixes, CancellationToken cancellationToken = default(CancellationToken)) + public static CodeFixMenu CreateFixMenu (Ide.Editor.TextEditor editor, CodeActionContainer fixes, CancellationToken cancellationToken = default(CancellationToken)) { var menu = new CodeFixMenu (); @@ -155,7 +156,7 @@ namespace MonoDevelop.CodeActions return desc.CustomTags.Any (c => CultureInfo.InvariantCulture.CompareInfo.Compare (c, tag) == 0); } - static CodeFixMenuEntry CreateFixMenuEntry (TextEditor editor, CodeAction fix, ref int mnemonic) + static CodeFixMenuEntry CreateFixMenuEntry (Ide.Editor.TextEditor editor, CodeAction fix, ref int mnemonic) { var label = mnemonic < 0 ? fix.Title : CreateLabel (fix.Title, ref mnemonic); var item = new CodeFixMenuEntry (label, async delegate { @@ -169,7 +170,7 @@ namespace MonoDevelop.CodeActions return item; } - static CodeFixMenuEntry CreateFixAllMenuEntry (TextEditor editor, FixAllState fixState, ref int mnemonic, CancellationToken token) + static CodeFixMenuEntry CreateFixAllMenuEntry (Ide.Editor.TextEditor editor, FixAllState fixState, ref int mnemonic, CancellationToken token) { var provider = fixState?.FixAllProvider; if (provider == null) @@ -214,7 +215,7 @@ namespace MonoDevelop.CodeActions return item; } - static void AddFixMenuItem (TextEditor editor, CodeFixMenu menu, CodeFixMenu fixAllMenu, ref int mnemonic, CodeAction fix, FixAllState fixState, CancellationToken token) + static void AddFixMenuItem (Ide.Editor.TextEditor editor, CodeFixMenu menu, CodeFixMenu fixAllMenu, ref int mnemonic, CodeAction fix, FixAllState fixState, CancellationToken token) { if (fix is CodeAction.CodeActionWithNestedActions nested) { // Inline code actions if they are, otherwise add a nested fix menu @@ -244,7 +245,7 @@ namespace MonoDevelop.CodeActions } } - static void AddNestedFixMenu (TextEditor editor, CodeFixMenu menu, CodeFixMenu fixAllMenu, CodeAction.CodeActionWithNestedActions fixes, FixAllState fixState, CancellationToken token) + static void AddNestedFixMenu (Ide.Editor.TextEditor editor, CodeFixMenu menu, CodeFixMenu fixAllMenu, CodeAction.CodeActionWithNestedActions fixes, FixAllState fixState, CancellationToken token) { int subMnemonic = 0; var subMenu = new CodeFixMenu (fixes.Title); @@ -267,10 +268,10 @@ namespace MonoDevelop.CodeActions internal class ContextActionRunner { readonly CodeAction act; - readonly TextEditor editor; + readonly Ide.Editor.TextEditor editor; DocumentContext documentContext; - public ContextActionRunner (TextEditor editor, CodeAction act) + public ContextActionRunner (Ide.Editor.TextEditor editor, CodeAction act) { this.editor = editor; this.act = act; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/FixAllPreviewDialog.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/FixAllPreviewDialog.cs index c2dc09c9c7..857a319027 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/FixAllPreviewDialog.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/FixAllPreviewDialog.cs @@ -57,11 +57,11 @@ namespace MonoDevelop.CodeActions readonly DataField<int> nodeOffset = new DataField<int> (); readonly TreeView treeView; readonly TreeStore store; - readonly TextEditor baseEditor, changedEditor; + readonly Ide.Editor.TextEditor baseEditor, changedEditor; readonly ImmutableArray<CodeActionOperation> operations; CheckBoxCellView checkBox; - public FixAllPreviewDialog (string diagnosticId, string scopeLabel, FixAllScope scope, ImmutableArray<CodeActionOperation> operations, TextEditor baseEditor) + public FixAllPreviewDialog (string diagnosticId, string scopeLabel, FixAllScope scope, ImmutableArray<CodeActionOperation> operations, Ide.Editor.TextEditor baseEditor) { Width = 800; Height = 600; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeDiagnosticRunner.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeDiagnosticRunner.cs index 0eab63ff83..120e57762c 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeDiagnosticRunner.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeDiagnosticRunner.cs @@ -46,6 +46,7 @@ using System.Globalization; namespace MonoDevelop.CodeIssues { + [Obsolete ("Old editor")] static class CodeDiagnosticRunner { public static async Task<IEnumerable<Result>> Check (AnalysisDocument analysisDocument, CancellationToken cancellationToken, ImmutableArray<DiagnosticData> results) diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeRulePanel.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeRulePanel.cs index ae23d4bfec..bc23b96d2b 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeRulePanel.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeRulePanel.cs @@ -57,7 +57,7 @@ namespace MonoDevelop.CodeIssues readonly Encoding encoding; readonly bool loadingError; - public TextEditor TextEditor { get; private set; } + public Ide.Editor.TextEditor TextEditor { get; private set; } public CodeRulePanelWidget () { diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ExtractInterface/ExtractInterfaceDialog.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ExtractInterface/ExtractInterfaceDialog.cs index aa10121561..2c9032febf 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ExtractInterface/ExtractInterfaceDialog.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ExtractInterface/ExtractInterfaceDialog.cs @@ -23,18 +23,18 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. + using System; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Notification; -using Microsoft.CodeAnalysis.LanguageServices; using System.Collections.Generic; -using Xwt; -using MonoDevelop.Ide; -using MonoDevelop.Components; using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.LanguageServices; +using Microsoft.CodeAnalysis.Notification; +using MonoDevelop.Components.AtkCocoaHelper; using MonoDevelop.Core; +using MonoDevelop.Ide; +using Xwt; using Xwt.Drawing; -using MonoDevelop.Components.AtkCocoaHelper; namespace MonoDevelop.Refactoring.ExtractInterface { @@ -83,9 +83,16 @@ namespace MonoDevelop.Refactoring.ExtractInterface } } + public bool UseSameFile { + get { + return sameFileRadio.Active; + } + } + TextEntry entryFileName = new TextEntry (); TextEntry entryName = new TextEntry (); ListView listViewPublicMembers = new ListView (); + RadioButton sameFileRadio, newFileRadio; public ExtractInterfaceDialog () { @@ -144,14 +151,34 @@ namespace MonoDevelop.Refactoring.ExtractInterface entryName.Changed += delegate { UpdateOkButton (); }; - box.PackStart (new Label { - Markup = GettextCatalog.GetString ("File name:") - }); - box.PackStart (entryFileName); + sameFileRadio = new RadioButton (GettextCatalog.GetString ("Add to current file")) { + Name = "sameFileRadio.Name" + }; + sameFileRadio.Accessible.Description = GettextCatalog.GetString ("Add the new interface to the current file"); + + newFileRadio = new RadioButton (GettextCatalog.GetString ("File name:")) { + Group = sameFileRadio.Group, + Name = "newFileRadio.Name" + }; + newFileRadio.Accessible.Description = GettextCatalog.GetString ("Add the new interface to a new file"); + newFileRadio.Active = true; + newFileRadio.ActiveChanged += (sender, e) => entryFileName.Sensitive = newFileRadio.Active; + + var fileNameBox = new HBox (); + fileNameBox.PackStart (newFileRadio); + fileNameBox.PackStart (entryFileName, true, true); + + box.PackStart (new Label { Markup = GettextCatalog.GetString ("Select destination") }); + var radioBox = new VBox { Margin = new WidgetSpacing (12, 4, 4, 4) }; + radioBox.PackStart (sameFileRadio); + radioBox.PackStart (fileNameBox); + entryFileName.Name = "entryFileName.Name"; - entryFileName.SetCommonAccessibilityAttributes (entryFileName.Name, GettextCatalog.GetString ("Name of the new file"), - GettextCatalog.GetString ("The name of the file for the new interface")); + entryFileName.SetCommonAccessibilityAttributes ( + entryFileName.Name, + GettextCatalog.GetString ("Name of the new file"), + GettextCatalog.GetString ("The name of the file for the new interface")); entryFileName.Changed += delegate { UpdateOkButton (); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ExtractInterface/ExtractInterfaceOptionService.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ExtractInterface/ExtractInterfaceOptionService.cs index dff9b26458..c12bf94ebe 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ExtractInterface/ExtractInterfaceOptionService.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.ExtractInterface/ExtractInterfaceOptionService.cs @@ -23,38 +23,67 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System; + +using System.Collections.Generic; +using System.Composition; +using System.Threading.Tasks; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ExtractInterface; -using Microsoft.CodeAnalysis.Notification; using Microsoft.CodeAnalysis.Host.Mef; -using System.Composition; -using MonoDevelop.Core; using Microsoft.CodeAnalysis.LanguageServices; -using System.Collections.Generic; +using Microsoft.CodeAnalysis.Notification; namespace MonoDevelop.Refactoring.ExtractInterface { [ExportWorkspaceService (typeof (IExtractInterfaceOptionsService), ServiceLayer.Default), Shared] class ExtractInterfaceOptionsService : IExtractInterfaceOptionsService { - public ExtractInterfaceOptionsResult GetExtractInterfaceOptions (ISyntaxFactsService syntaxFactsService, INotificationService notificationService, List<ISymbol> extractableMembers, string defaultInterfaceName, List<string> conflictingTypeNames, string defaultNamespace, string generatedNameTypeParameterSuffix, string languageName) + readonly IThreadingContext threadingContext; + + [ImportingConstructor] + public ExtractInterfaceOptionsService (IThreadingContext threadingContext) + { + this.threadingContext = threadingContext; + } + + public async Task<ExtractInterfaceOptionsResult> GetExtractInterfaceOptionsAsync ( + ISyntaxFactsService syntaxFactsService, + INotificationService notificationService, + List<ISymbol> extractableMembers, + string defaultInterfaceName, + List<string> conflictingTypeNames, + string defaultNamespace, + string generatedNameTypeParameterSuffix, + string languageName) { + await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync (); var dialog = new ExtractInterfaceDialog (); - try { - dialog.Init (syntaxFactsService, notificationService, extractableMembers, defaultInterfaceName, conflictingTypeNames, defaultNamespace, generatedNameTypeParameterSuffix, languageName); - bool performChange = dialog.Run () == Xwt.Command.Ok; - if (!performChange) - return ExtractInterfaceOptionsResult.Cancelled; - - return new ExtractInterfaceOptionsResult (false, dialog.IncludedMembers, dialog.InterfaceName, dialog.FileName); - } catch (Exception ex) { - LoggingService.LogError ("Error while signature changing.", ex); + + dialog.Init ( + syntaxFactsService, + notificationService, + extractableMembers, + defaultInterfaceName, + conflictingTypeNames, + defaultNamespace, + generatedNameTypeParameterSuffix, + languageName); + + bool performChange = dialog.Run () == Xwt.Command.Ok; + if (!performChange) return ExtractInterfaceOptionsResult.Cancelled; - } finally { - dialog.Dispose (); - } + + return new ExtractInterfaceOptionsResult ( + false, + dialog.IncludedMembers.AsImmutable (), + dialog.InterfaceName, + dialog.FileName, + dialog.UseSameFile + ? ExtractInterfaceOptionsResult.ExtractLocation.SameFile + : ExtractInterfaceOptionsResult.ExtractLocation.NewFile + ); } } } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/AbstractOptionPreviewViewModel.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/AbstractOptionPreviewViewModel.cs index 43817ec03d..a014ea9992 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/AbstractOptionPreviewViewModel.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/AbstractOptionPreviewViewModel.cs @@ -1,4 +1,4 @@ -// +// // AbstractOptionPreviewViewModel.cs // // Author: @@ -49,7 +49,7 @@ namespace MonoDevelop.Refactoring.Options { internal abstract class AbstractOptionPreviewViewModel : AbstractNotifyPropertyChanged, IDisposable { - private TextEditor _textViewHost; + private Ide.Editor.TextEditor _textViewHost; private PreviewWorkspace curWorkspace; private Microsoft.CodeAnalysis.Project project; @@ -100,7 +100,7 @@ namespace MonoDevelop.Refactoring.Options UpdateDocument (preview); } - public TextEditor TextViewHost { + public Ide.Editor.TextEditor TextViewHost { get { return _textViewHost; } @@ -179,8 +179,10 @@ namespace MonoDevelop.Refactoring.Options public override MonoDevelop.Projects.Project Project => null; + [Obsolete]
public override Document AnalysisDocument => document; + [Obsolete]
public override ParsedDocument ParsedDocument => null; public override void AttachToProject (MonoDevelop.Projects.Project project) @@ -192,10 +194,12 @@ namespace MonoDevelop.Refactoring.Options return null; } + [Obsolete]
public override void ReparseDocument () { } + [Obsolete]
public override Task<ParsedDocument> UpdateParseDocument () { return new Task<ParsedDocument> (null); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/CheckBoxWithComboOptionViewModel.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/CheckBoxWithComboOptionViewModel.cs index 6c74fd5b07..a673902234 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/CheckBoxWithComboOptionViewModel.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/CheckBoxWithComboOptionViewModel.cs @@ -1,4 +1,4 @@ -// +// // CheckBoxWithComboOptionViewModel.cs // // Author: @@ -56,7 +56,7 @@ namespace MonoDevelop.Refactoring.Options var codeStyleOption = ((CodeStyleOption<bool>)options.GetOption (new OptionKey (option, option.IsPerLanguage ? info.Language : null))); SetProperty (ref _isChecked, codeStyleOption.Value); - var notificationViewModel = items.Where (i => i.Notification.Value == codeStyleOption.Notification.Value).Single (); + var notificationViewModel = items.Where (i => i.Notification.Severity == codeStyleOption.Notification.Severity).Single (); SetProperty (ref _selectedNotificationOption, notificationViewModel); } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/AbstractCodeStyleOptionViewModel.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/AbstractCodeStyleOptionViewModel.cs index a0191337f3..0d02d605c1 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/AbstractCodeStyleOptionViewModel.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/AbstractCodeStyleOptionViewModel.cs @@ -92,7 +92,8 @@ namespace MonoDevelop.Refactoring.Options new NotificationOptionViewModel(NotificationOption.None, "issues-hide"), new NotificationOptionViewModel(NotificationOption.Suggestion, "issues-suggestion"), new NotificationOptionViewModel(NotificationOption.Warning, "issues-warning"), - new NotificationOptionViewModel(NotificationOption.Error, "issues-error") + new NotificationOptionViewModel(NotificationOption.Error, "issues-error"), + new NotificationOptionViewModel(NotificationOption.Silent, "issues-hide") }; } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/BooleanCodeStyleOptionViewModel.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/BooleanCodeStyleOptionViewModel.cs index 6d17a84268..a45c931394 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/BooleanCodeStyleOptionViewModel.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/BooleanCodeStyleOptionViewModel.cs @@ -1,4 +1,4 @@ -// +// // BooleanCodeStyleOptionViewModel.cs // // Author: @@ -28,6 +28,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.CodeAnalysis.CodeStyle; using Microsoft.CodeAnalysis.Options; +using System; namespace MonoDevelop.Refactoring.Options { @@ -58,11 +59,13 @@ namespace MonoDevelop.Refactoring.Options _truePreview = truePreview; _falsePreview = falsePreview; - var codeStyleOption = ((CodeStyleOption<bool>)options.GetOption (new OptionKey (option, option.IsPerLanguage ? info.Language : null))); + var optionValue = options.GetOption (new OptionKey (option, option.IsPerLanguage ? info.Language : null)); + if (!(optionValue is CodeStyleOption<bool> codeStyleOption)) + throw new InvalidOperationException (optionValue + " is no CodeStyleOption<bool>. Queried option: " + option); _selectedPreference = Preferences.Single (c => c.IsChecked == codeStyleOption.Value); - var notificationViewModel = NotificationPreferences.Single (i => i.Notification.Value == codeStyleOption.Notification.Value); - _selectedNotificationPreference = NotificationPreferences.Single (p => p.Notification.Value == notificationViewModel.Notification.Value); + var notificationViewModel = NotificationPreferences.Single (i => i.Notification.Severity == codeStyleOption.Notification.Severity); + _selectedNotificationPreference = NotificationPreferences.Single (p => p.Notification.Severity == notificationViewModel.Notification.Severity); NotifyPropertyChanged (nameof (SelectedPreference)); NotifyPropertyChanged (nameof (SelectedNotificationPreference)); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/EnumCodeStyleOptionViewModel.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/EnumCodeStyleOptionViewModel.cs index a7a51b92d2..bfd129309f 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/EnumCodeStyleOptionViewModel.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Options/Style/EnumCodeStyleOptionViewModel.cs @@ -1,4 +1,4 @@ -// +// // EnumCodeStyleOptionViewModel.cs // // Author: @@ -114,8 +114,8 @@ namespace MonoDevelop.Refactoring.Options _selectedPreference = Preferences [enumIndex]; - var notificationViewModel = NotificationPreferences.Single (i => i.Notification.Value == codeStyleOption.Notification.Value); - _selectedNotificationPreference = NotificationPreferences.Single (p => p.Notification.Value == notificationViewModel.Notification.Value); + var notificationViewModel = NotificationPreferences.Single (i => i.Notification.Severity == codeStyleOption.Notification.Severity); + _selectedNotificationPreference = NotificationPreferences.Single (p => p.Notification.Severity == notificationViewModel.Notification.Severity); NotifyPropertyChanged (nameof (SelectedPreference)); NotifyPropertyChanged (nameof (SelectedNotificationPreference)); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.PackageInstaller/PackageInstallerService.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.PackageInstaller/PackageInstallerService.cs index ea499f5c42..cbcc70072a 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.PackageInstaller/PackageInstallerService.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.PackageInstaller/PackageInstallerService.cs @@ -96,6 +96,12 @@ namespace MonoDevelop.Refactoring.PackageInstaller { readonly ConcurrentDictionary<ProjectId, Dictionary<string, string>> _projectToInstalledPackageAndVersion = new ConcurrentDictionary<ProjectId, Dictionary<string, string>> (); + /// <summary> + /// Get package sources. + /// + /// NOTE: This method is known to be called from the threadpool, while the UI thread is blocking. + /// Therefore, it must be thread-safe and not defer to and then block other threads. + /// </summary> public ImmutableArray<PackageSource> PackageSources { get { return PackageServices.GetSources (false, false).Select (kv => new PackageSource (kv.Key, kv.Value)) .ToImmutableArray (); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs index 8a680f9e83..76fe400248 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs @@ -69,7 +69,7 @@ namespace MonoDevelop.Refactoring.Rename } } - static void Rollback (TextEditor editor, List<MonoDevelop.Core.Text.TextChangeEventArgs> textChanges) + static void Rollback (Ide.Editor.TextEditor editor, List<MonoDevelop.Core.Text.TextChangeEventArgs> textChanges) { for (int i = textChanges.Count - 1; i >= 0; i--) {
for (int j = 0; j < textChanges [i].TextChanges.Count; ++j) {
diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.SignatureChange/SignatureChangeDialog.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.SignatureChange/SignatureChangeDialog.cs index a97aa2097e..726848a419 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.SignatureChange/SignatureChangeDialog.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.SignatureChange/SignatureChangeDialog.cs @@ -1,4 +1,4 @@ -// +// // SignatureChangeDialog.cs // // Author: @@ -39,7 +39,7 @@ namespace MonoDevelop.Refactoring.SignatureChange { partial class SignatureChangeDialog : Gtk.Dialog { - TextEditor previewEditor; + Ide.Editor.TextEditor previewEditor; ISymbol symbol; ParameterConfiguration parameters; ListStore store = new ListStore (typeof (IParameterSymbol)); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.addin.xml b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.addin.xml index 7799c98405..48ee77a37a 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.addin.xml +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.addin.xml @@ -1,4 +1,4 @@ -<ExtensionModel> +<ExtensionModel> <Runtime> <Import assembly="RefactoringEssentials.dll" /> </Runtime> @@ -52,6 +52,16 @@ <Extension path = "/MonoDevelop/Ide/Commands"> <Category _name = "Code Navigation" id = "CodeNavigation"> + <Command id = "MonoDevelop.Refactoring.RefactoryCommands.GotoDeclaration" + _label = "_Go to Declaration" + shortcut = "F12" + macShortcut = "Meta|D F12"/> + + <Command id = "MonoDevelop.Refactoring.RefactoryCommands.GotoImplementation" + _label = "Go to Implementation" + shortcut="Ctrl|F12" + macShortcut=""/> + <Command id = "MonoDevelop.Refactoring.RefactoryCommands.FindReferences" _label = "_Find References" shortcut = "Shift|F12" @@ -171,4 +181,32 @@ <Assembly file="Microsoft.CodeAnalysis.VisualBasic.Features" /> </Extension> + <Extension path = "/MonoDevelop/TextEditor/CommandMapping"> + <Map id="MonoDevelop.Refactoring.RefactoryCommands.GotoDeclaration" argsType="Microsoft.VisualStudio.Text.Editor.Commanding.Commands.GoToDefinitionCommandArgs" /> + <Map id="MonoDevelop.Refactoring.RefactoryCommands.FindReferences" argsType="Microsoft.VisualStudio.Text.Editor.Commanding.Commands.FindReferencesCommandArgs" /> + <Map id="MonoDevelop.Refactoring.RefactoryCommands.GotoImplementation" argsType="@MonoDevelop.Refactoring.CommandArgsFactories.CreateGoToImplementationCommandArgs" /> + + <!-- These mappings exist to ensure the new editor calls the new commands --> + <Map id="MonoDevelop.Refactoring.RefactoryCommands.FindAllReferences" argsType="Microsoft.VisualStudio.Text.Editor.Commanding.Commands.Navigation.FindReferencesOfOverloadsCommandArgs" /> + <Map id="MonoDevelop.Refactoring.Navigation.FindBaseSymbols" argsType="Microsoft.VisualStudio.Text.Editor.Commanding.Commands.Navigation.FindBaseSymbolsCommandArgs" /> + <Map id="MonoDevelop.Refactoring.Navigation.FindDerivedSymbols" argsType="Microsoft.VisualStudio.Text.Editor.Commanding.Commands.Navigation.FindDerivedSymbolsCommandArgs" /> + + <Map id="MonoDevelop.CSharp.Navigation.FindExtensionMethods" argsType="Microsoft.VisualStudio.Text.Editor.Commanding.Commands.Navigation.FindExtensionMethodsCommandArgs" /> + <Map id="MonoDevelop.CSharp.Navigation.FindMemberOverloads" argsType="Microsoft.VisualStudio.Text.Editor.Commanding.Commands.Navigation.FindMemberOverloadsCommandArgs" /> + <Map id="MonoDevelop.CSharp.Navigation.FindImplementingMembers" argsType="Microsoft.VisualStudio.Text.Editor.Commanding.Commands.Navigation.FindImplementingMembersCommandArgs" /> + </Extension> + + <Extension path="/MonoDevelop/TextEditor/ContextMenu/Editor"> + <Condition id="FileType" mimeTypes="text/x-csharp"> + <ItemSet id="Navigate" _label="Navigate" insertbefore="Separator1"> + <CommandItem id="MonoDevelop.Refactoring.RefactoryCommands.FindAllReferences" /> + <CommandItem id="MonoDevelop.Refactoring.Navigation.FindBaseSymbols" /> + <CommandItem id="MonoDevelop.Refactoring.Navigation.FindDerivedSymbols" /> + <SeparatorItem id="SeparatorNavigate1" /> + <CommandItem id="MonoDevelop.CSharp.Navigation.FindExtensionMethods" /> + <CommandItem id="MonoDevelop.CSharp.Navigation.FindMemberOverloads" /> + <CommandItem id="MonoDevelop.CSharp.Navigation.FindImplementingMembers" /> + </ItemSet> + </Condition> + </Extension> </ExtensionModel> diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.csproj b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.csproj index ec4728fa34..9dbaaeb982 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.csproj +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.csproj @@ -1,7 +1,6 @@ <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> <Import Project="..\..\..\MonoDevelop.props" /> <Import Project="$(ReferencesGtk)" /> - <Import Project="$(ReferencesRoslyn)" /> <Import Project="$(ReferencesVSEditor)" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> @@ -26,38 +25,7 @@ <HintPath>..\..\..\external\Xamarin.Mac.dll</HintPath> <Private>False</Private> </Reference> - <Reference Include="System.Composition.AttributedModel"> - <HintPath>..\..\..\build\bin\System.Composition.AttributedModel.dll</HintPath> - <Private>False</Private> - </Reference> - <Reference Include="System.Composition.Runtime"> - <HintPath>..\..\..\build\bin\System.Composition.Runtime.dll</HintPath> - <Private>False</Private> - </Reference> - <Reference Include="System.Collections.Immutable"> - <HintPath>..\..\..\build\bin\System.Collections.Immutable.dll</HintPath> - <Private>False</Private> - </Reference> - <Reference Include="System.ValueTuple"> - <HintPath>..\..\..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll</HintPath> - <Private>False</Private> - </Reference> - <Reference Include="System.Composition.TypedParts"> - <HintPath>..\..\..\build\bin\System.Composition.TypedParts.dll</HintPath> - <Private>False</Private> - </Reference> - <Reference Include="System.Composition.Hosting"> - <HintPath>..\..\..\build\bin\System.Composition.Hosting.dll</HintPath> - <Private>False</Private> - </Reference> - <Reference Include="System.Threading.Tasks.Extensions"> - <HintPath>..\..\..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\netstandard1.0\System.Threading.Tasks.Extensions.dll</HintPath> - <Private>False</Private> - </Reference> - <Reference Include="Microsoft.VisualStudio.Composition"> - <HintPath>..\..\..\build\bin\Microsoft.VisualStudio.Composition.dll</HintPath> - <Private>False</Private> - </Reference> + <IncludeCopyLocal Include="RefactoringEssentials.dll" /> </ItemGroup> <ItemGroup> <Compile Include="AssemblyInfo.cs" /> @@ -136,6 +104,8 @@ <Compile Include="MonoDevelop.CodeActions\FixAllPreviewDialog.cs" /> <Compile Include="MonoDevelop.AnalysisCore\Gui\ResultTooltipProvider.FloatingQuickFixIconWidget.cs" /> <Compile Include="MonoDevelop.AnalysisCore\Gui\ResultTooltipProvider.RectangleMarker.cs" /> + <Compile Include="MonoDevelop.Refactoring\StreamingFindUsagesPresenter.cs" /> + <Compile Include="MonoDevelop.Refactoring\CommandArgsFactories.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="MonoDevelop.Refactoring.addin.xml" /> @@ -210,6 +180,11 @@ <Name>RefactoringEssentials</Name> <Private>True</Private> </ProjectReference> + <ProjectReference Include="..\MonoDevelop.TextEditor\MonoDevelop.TextEditor\MonoDevelop.TextEditor.csproj"> + <Project>{3f5b5bda-69d5-441a-8142-aa25c998a997}</Project> + <Name>MonoDevelop.TextEditor</Name> + <Private>False</Private> + </ProjectReference> </ItemGroup> <ItemGroup> <InternalsVisibleTo Include="FSharpBinding" /> diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Change.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Change.cs index 61d74fbf85..41d35c70a5 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Change.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Change.cs @@ -83,7 +83,7 @@ namespace MonoDevelop.Refactoring set; } - static List<TextEditor> textEditorDatas = new List<TextEditor> (); + static List<Ide.Editor.TextEditor> textEditorDatas = new List<Ide.Editor.TextEditor> (); static List<IDisposable> undoGroups = new List<IDisposable> (); public static void FinishRefactoringOperation () @@ -93,7 +93,7 @@ namespace MonoDevelop.Refactoring undoGroups.Clear (); } - internal static TextEditor GetTextEditorData (string fileName) + internal static Ide.Editor.TextEditor GetTextEditorData (string fileName) { if (IdeApp.Workbench == null) return null; @@ -113,7 +113,7 @@ namespace MonoDevelop.Refactoring } return null; } - protected virtual TextEditor TextEditorData { + protected virtual Ide.Editor.TextEditor TextEditorData { get { return GetTextEditorData (FileName); } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/CommandArgsFactories.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/CommandArgsFactories.cs new file mode 100644 index 0000000000..d9b3915571 --- /dev/null +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/CommandArgsFactories.cs @@ -0,0 +1,36 @@ +// +// CommandArgsFactories.cs +// +// +// Copyright (c) 2019 Microsoft +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using Microsoft.VisualStudio.Text; +using Microsoft.VisualStudio.Text.Editor; +using Microsoft.CodeAnalysis.Editor.Commanding.Commands; + +namespace MonoDevelop.Refactoring +{ + static class CommandArgsFactories + { + public static GoToImplementationCommandArgs CreateGoToImplementationCommandArgs (ITextView v, ITextBuffer b) + => new GoToImplementationCommandArgs (v, b); + } +} diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Commands.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Commands.cs index a07a27ec68..a8f7586837 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Commands.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Commands.cs @@ -32,6 +32,8 @@ namespace MonoDevelop.Refactoring { CurrentRefactoryOperations, GotoDeclaration, // in 'referenced' in IdeViMode.cs as string + GotoImplementation, + SortAndRemoveUnnecessaryImports, FindReferences, FindAllReferences, FindDerivedClasses, diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/InsertionPointService.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/InsertionPointService.cs index 88df7bd27c..fb4fafba84 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/InsertionPointService.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/InsertionPointService.cs @@ -1,4 +1,4 @@ -// +// // InsertionPointService.cs // // Author: @@ -37,27 +37,9 @@ using MonoDevelop.Ide.TypeSystem; namespace MonoDevelop.Refactoring { + [Obsolete ("Not supported in new editor")] public static class InsertionPointService { - [Obsolete ("Use overload that takes a SemanticModel")] - public static List<InsertionPoint> GetInsertionPoints (IReadonlyTextDocument data, ParsedDocument parsedDocument, ITypeSymbol type, int position) - { - if (data == null) - throw new ArgumentNullException (nameof (data)); - if (parsedDocument == null) - throw new ArgumentNullException (nameof (parsedDocument)); - if (type == null) - throw new ArgumentNullException (nameof (type)); - if (!type.IsDefinedInSource ()) - throw new ArgumentException ("The given type needs to be defined in source code.", nameof (type)); - - // update type from parsed document, since this is always newer. - //type = parsedDocument.GetInnermostTypeDefinition (type.GetLocation ()) ?? type; - //var realStartLocation = data.OffsetToLocation (offset); - var model = parsedDocument.GetAst<SemanticModel> (); - return GetInsertionPoints (data, model, type, position); - } - public static List<InsertionPoint> GetInsertionPoints (IReadonlyTextDocument data, SemanticModel model, ITypeSymbol type, Location location) { return GetInsertionPoints (data, model, type, location.SourceSpan.Start); @@ -153,12 +135,6 @@ namespace MonoDevelop.Refactoring return result; } - [Obsolete ("Use overload that takes a SemanticModel")] - public static List<InsertionPoint> GetInsertionPoints (IReadonlyTextDocument data, ParsedDocument parsedDocument, ITypeSymbol type, Location location) - { - return GetInsertionPoints (data, parsedDocument, type, location.SourceSpan.Start); - } - static void CheckEndPoint (IReadonlyTextDocument doc, InsertionPoint point, bool isStartPoint) { var line = doc.GetLine (point.Location.Line); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOptions.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOptions.cs index d8dad6141f..a6c039dd19 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOptions.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringOptions.cs @@ -43,7 +43,7 @@ namespace MonoDevelop.Refactoring { public class RefactoringOptions { - public TextEditor Editor { + public Ide.Editor.TextEditor Editor { get; private set; } @@ -85,7 +85,7 @@ namespace MonoDevelop.Refactoring { } - public RefactoringOptions (TextEditor editor, DocumentContext doc) + public RefactoringOptions (Ide.Editor.TextEditor editor, DocumentContext doc) { this.DocumentContext = doc; this.Editor = editor; @@ -98,12 +98,12 @@ namespace MonoDevelop.Refactoring }*/ } - public TextEditor GetTextEditorData () + public Ide.Editor.TextEditor GetTextEditorData () { return Editor; } - public static string GetWhitespaces (TextEditor editor, int insertionOffset) + public static string GetWhitespaces (Ide.Editor.TextEditor editor, int insertionOffset) { StringBuilder result = new StringBuilder (); for (int i = insertionOffset; i < editor.Length; i++) { @@ -117,7 +117,7 @@ namespace MonoDevelop.Refactoring return result.ToString (); } - public static string GetIndent (TextEditor editor, Microsoft.CodeAnalysis.SyntaxNode member) + public static string GetIndent (Ide.Editor.TextEditor editor, Microsoft.CodeAnalysis.SyntaxNode member) { return GetWhitespaces (editor, member.SpanStart); } @@ -132,7 +132,7 @@ namespace MonoDevelop.Refactoring return GetUsedNamespacesAsync (Editor, DocumentContext, Editor.LocationToOffset (Location)); } - public static async Task<ImmutableArray<string>> GetUsedNamespacesAsync (TextEditor editor, DocumentContext doc, int offset, CancellationToken cancellationToken = default (CancellationToken)) + public static async Task<ImmutableArray<string>> GetUsedNamespacesAsync (Ide.Editor.TextEditor editor, DocumentContext doc, int offset, CancellationToken cancellationToken = default (CancellationToken)) { if (editor == null) throw new System.ArgumentNullException (nameof (editor)); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewTooltipWindow.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewTooltipWindow.cs index 705bb142ae..97248f635b 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewTooltipWindow.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewTooltipWindow.cs @@ -1,4 +1,4 @@ -// +// // RefactoringPreviewTooltipWindow.cs // // Author: @@ -45,7 +45,7 @@ namespace MonoDevelop.Refactoring { class RefactoringPreviewTooltipWindow : PopoverWindow { - TextEditor editor; + Ide.Editor.TextEditor editor; CodeAction codeAction; DocumentContext documentContext; CancellationTokenSource popupSrc = new CancellationTokenSource (); @@ -57,7 +57,7 @@ namespace MonoDevelop.Refactoring static RefactoringPreviewTooltipWindow currentPreviewWindow; - RefactoringPreviewTooltipWindow (TextEditor editor, CodeAction codeAction) + RefactoringPreviewTooltipWindow (Ide.Editor.TextEditor editor, CodeAction codeAction) { this.editor = editor; this.documentContext = documentContext = editor.DocumentContext; @@ -72,7 +72,7 @@ namespace MonoDevelop.Refactoring } } - public static void ShowPreviewTooltip (TextEditor editor, CodeAction fix, Xwt.Rectangle rect) + public static void ShowPreviewTooltip (Ide.Editor.TextEditor editor, CodeAction fix, Xwt.Rectangle rect) { HidePreviewTooltip (); currentPreviewWindow = new RefactoringPreviewTooltipWindow (editor, fix); @@ -179,12 +179,12 @@ namespace MonoDevelop.Refactoring class DiffProcessor { - readonly TextEditor baseDocument; + readonly Ide.Editor.TextEditor baseDocument; readonly IReadonlyTextDocument changedTextDocument; public int IndentLength { get; set; } - public DiffProcessor (TextEditor baseDocument, IReadonlyTextDocument changedTextDocument) + public DiffProcessor (Ide.Editor.TextEditor baseDocument, IReadonlyTextDocument changedTextDocument) { this.baseDocument = baseDocument; this.changedTextDocument = changedTextDocument; @@ -277,7 +277,7 @@ namespace MonoDevelop.Refactoring var length = Math.Max (0, line.Length - correctedIndentLength); string text = null; - if (lineKind != LineKind.Normal || !(document is TextEditor)) { + if (lineKind != LineKind.Normal || !(document is Ide.Editor.TextEditor)) { text = Ambience.EscapeText (document.GetTextAt (offset, length)); } // Ignore markup items as the markup needs to be requested on the UI thread. diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs index 6b42941106..459f0d8a32 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs @@ -52,7 +52,7 @@ namespace MonoDevelop.Refactoring { public static class RefactoringService { - internal static Func<TextEditor, DocumentContext, OptionSet> OptionSetCreation; + internal static Func<Ide.Editor.TextEditor, DocumentContext, OptionSet> OptionSetCreation; static ImmutableList<FindReferencesProvider> findReferencesProvider = ImmutableList<FindReferencesProvider>.Empty; static ImmutableList<FindReferenceUsagesProvider> findReferenceUsagesProviders = ImmutableList<FindReferenceUsagesProvider>.Empty; static List<JumpToDeclarationHandler> jumpToDeclarationHandler = new List<JumpToDeclarationHandler> (); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringSymbolInfo.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringSymbolInfo.cs index 2fef3d01d7..09180834e0 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringSymbolInfo.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringSymbolInfo.cs @@ -37,34 +37,31 @@ using System.Threading; using System; using System.Linq; using Microsoft.CodeAnalysis.CSharp; +using Microsoft.VisualStudio.Text.Editor; +using Microsoft.CodeAnalysis.Text; namespace MonoDevelop.Refactoring { - + [Obsolete ("Old editor")] class RefactoringSymbolInfo { public readonly static RefactoringSymbolInfo Empty = new RefactoringSymbolInfo (new SymbolInfo ()); SymbolInfo symbolInfo; - public ISymbol Symbol - { - get - { + public ISymbol Symbol { + get { return symbolInfo.Symbol; } } - public ImmutableArray<ISymbol> CandidateSymbols - { - get - { + public ImmutableArray<ISymbol> CandidateSymbols { + get { return symbolInfo.CandidateSymbols; } } - public ISymbol DeclaredSymbol - { + public ISymbol DeclaredSymbol { get; internal set; } @@ -91,11 +88,11 @@ namespace MonoDevelop.Refactoring } } - public static Task<RefactoringSymbolInfo> GetSymbolInfoAsync (DocumentContext document, TextEditor editor, CancellationToken cancellationToken = default (CancellationToken)) + public static Task<RefactoringSymbolInfo> GetSymbolInfoAsync (DocumentContext document, Ide.Editor.TextEditor editor, CancellationToken cancellationToken = default (CancellationToken)) { if (editor.IsSomethingSelected) { var selectionRange = editor.SelectionRange; - if (editor.GetTextAt (selectionRange).Any (ch => !char.IsLetterOrDigit (ch) && ch !='_')) { + if (editor.GetTextAt (selectionRange).Any (ch => !char.IsLetterOrDigit (ch) && ch != '_')) { return Task.FromResult (RefactoringSymbolInfo.Empty); } return GetSymbolInfoAsync (document, selectionRange.Offset, cancellationToken); @@ -126,6 +123,40 @@ namespace MonoDevelop.Refactoring } return RefactoringSymbolInfo.Empty; } + + public static async Task<RefactoringSymbolInfo> GetSymbolInfoAsync (ITextView textView, CancellationToken cancellationToken = default) + { + int offset = 0; + + if (!(textView.Selection?.IsEmpty).GetValueOrDefault (false)) { + var selectionSpan = textView.Selection.SelectedSpans.FirstOrDefault (); + var selectedText = textView.TextBuffer.CurrentSnapshot.GetText (selectionSpan); + if (selectedText.Any (ch => !char.IsLetterOrDigit (ch) && ch != '_')) { + return Empty; + } + + offset = selectionSpan.Start.Position; + } + + offset = textView.Caret.Position.BufferPosition.Position; + + return await GetSymbolInfoAsync (textView, offset, cancellationToken); + } + + private static async Task<RefactoringSymbolInfo> GetSymbolInfoAsync (ITextView textView, int offset, CancellationToken cancellationToken = default) + { + var analysisDocument = textView.TextBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges (); + + if (analysisDocument == null) + return Empty; + + if (Runtime.IsMainThread) { + //InternalGetSymbolInfoAsync can be CPU heavy, go to ThreadPool if we are on UI thread + return await Task.Run (() => InternalGetSymbolInfoAsync (analysisDocument, offset, cancellationToken)); + } + + return await InternalGetSymbolInfoAsync (analysisDocument, offset, cancellationToken); + } } } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/StreamingFindUsagesPresenter.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/StreamingFindUsagesPresenter.cs new file mode 100644 index 0000000000..242de31148 --- /dev/null +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/StreamingFindUsagesPresenter.cs @@ -0,0 +1,138 @@ +using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.CodeAnalysis.Editor.Host;
+using Microsoft.CodeAnalysis.FindUsages;
+using MonoDevelop.Core; +using MonoDevelop.Core.Instrumentation; +using MonoDevelop.Ide; +using MonoDevelop.Ide.FindInFiles; +using MonoDevelop.Ide.TypeSystem;
+using Roslyn.Utilities; + +namespace MonoDevelop.Refactoring
+{
+ [Export (typeof (IStreamingFindUsagesPresenter))]
+ class StreamingFindUsagesPresenter : IStreamingFindUsagesPresenter
+ {
+ public void ClearAll ()
+ {
+ }
+
+ public FindUsagesContext StartSearch (string title, bool supportsReferences)
+ {
+ return new MonoDevelopFindUsagesContext ();
+ }
+ }
+
+ sealed class MonoDevelopFindUsagesContext : FindUsagesContext + { + ConcurrentSet<SearchResult> antiDuplicatesSet = new ConcurrentSet<SearchResult> (new SearchResultComparer ()); + SearchProgressMonitor monitor; + int reportedProgress = 0; + ITimeTracker timer = null; + Counters.FindReferencesMetadata metadata;
+ + public MonoDevelopFindUsagesContext ()
+ {
+ monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true);
+ monitor.BeginTask (GettextCatalog.GetString ("Searching..."), 100);
+ CancellationToken = monitor.CancellationToken; + CancellationToken.Register (Finished); + metadata = Counters.CreateFindReferencesMetadata (); + timer = Counters.FindReferences.BeginTiming (metadata); + }
+
+ public override CancellationToken CancellationToken { get; } + + void Finished () + { + if (!CancellationToken.IsCancellationRequested) {
+ monitor?.ReportResults (antiDuplicatesSet); + metadata.SetUserCancel ();
+ }
+ monitor?.Dispose ();
+ monitor = null;
+ + timer?.Dispose ();
+ timer = null; + }
+
+ public override Task ReportMessageAsync (string message) + { + return base.ReportMessageAsync (message); + }
+
+ public override Task ReportProgressAsync (int current, int maximum) + { + int newProgress = current * 100 / maximum; + monitor?.Step (newProgress - reportedProgress);
+ return Task.CompletedTask; + }
+ + public override Task OnDefinitionFoundAsync (DefinitionItem definition) + {
+ var locations = definition.SourceSpans; + foreach (var loc in locations) { + var fileName = loc.Document.FilePath; + var offset = loc.SourceSpan.Start; + string projectedName; + int projectedOffset;
+ var workspace = loc.Document.Project.Solution.Workspace as MonoDevelopWorkspace; + if (workspace != null && workspace.TryGetOriginalFileFromProjection (fileName, offset, out projectedName, out projectedOffset)) { + fileName = projectedName; + offset = projectedOffset; + } + var sr = new MemberReference (loc, fileName, offset, loc.SourceSpan.Length); + sr.ReferenceUsageType = ReferenceUsageType.Declaration; + antiDuplicatesSet.Add (sr); + } + return Task.CompletedTask; + }
+
+ public override Task OnReferenceFoundAsync (SourceReferenceItem reference) + {
+ var loc = reference.SourceSpan; + var fileName = loc.Document.FilePath; + var offset = loc.SourceSpan.Start; + string projectedName; + int projectedOffset; + var workspace = loc.Document.Project.Solution.Workspace as MonoDevelopWorkspace; + if (workspace != null && workspace.TryGetOriginalFileFromProjection (fileName, offset, out projectedName, out projectedOffset)) { + fileName = projectedName; + offset = projectedOffset; + } + var sr = new MemberReference (loc, fileName, offset, loc.SourceSpan.Length); + if (antiDuplicatesSet.Add (sr)) { + sr.ReferenceUsageType = reference.IsWrittenTo ? ReferenceUsageType.Write : ReferenceUsageType.Read; + } + return Task.CompletedTask; + }
+
+ public override Task OnCompletedAsync () + { + Finished (); + return Task.CompletedTask; + } + + class SearchResultComparer : IEqualityComparer<SearchResult> + { + public bool Equals (SearchResult x, SearchResult y) + { + return x.FileName == y.FileName && + x.Offset == y.Offset && + x.Length == y.Length; + } + + public int GetHashCode (SearchResult obj) + { + int hash = 17; + hash = hash * 23 + obj.Offset.GetHashCode (); + hash = hash * 23 + obj.Length.GetHashCode (); + hash = hash * 23 + (obj.FileName ?? "").GetHashCode (); + return hash; + } + } + }
+}
|