diff --git a/Rubberduck.CodeAnalysis/QuickFixes/Concrete/ChangeProcedureToFunctionQuickFix.cs b/Rubberduck.CodeAnalysis/QuickFixes/Concrete/ChangeProcedureToFunctionQuickFix.cs index d355ac16f2..bce7c03a0f 100644 --- a/Rubberduck.CodeAnalysis/QuickFixes/Concrete/ChangeProcedureToFunctionQuickFix.cs +++ b/Rubberduck.CodeAnalysis/QuickFixes/Concrete/ChangeProcedureToFunctionQuickFix.cs @@ -59,23 +59,31 @@ public override void Fix(IInspectionResult result, IRewriteSession rewriteSessio var arg = parameterizedDeclaration.Parameters.First(p => p.IsByRef || p.IsImplicitByRef); var argIndex = parameterizedDeclaration.Parameters.IndexOf(arg); - UpdateSignature(result.Target, arg, rewriteSession); + UpdateProcedure(result.Target, arg, rewriteSession); foreach (var reference in result.Target.References.Where(reference => !reference.IsDefaultMemberAccess)) { UpdateCall(reference, argIndex, rewriteSession); } } - private void UpdateSignature(Declaration target, ParameterDeclaration arg, IRewriteSession rewriteSession) + private void UpdateProcedure(Declaration target, ParameterDeclaration arg, IRewriteSession rewriteSession) { var subStmt = (VBAParser.SubStmtContext) target.Context; var argContext = (VBAParser.ArgContext)arg.Context; - + var argName = argContext.unrestrictedIdentifier().GetText(); var rewriter = rewriteSession.CheckOutModuleRewriter(target.QualifiedModuleName); + UpdateSignature(subStmt, arg, rewriter); + AddReturnStatement(subStmt, argName, rewriter); + ReplaceExitSubs(subStmt, argName, rewriter); + } + + private void UpdateSignature(VBAParser.SubStmtContext subStmt, ParameterDeclaration arg, IModuleRewriter rewriter) + { rewriter.Replace(subStmt.SUB(), Tokens.Function); rewriter.Replace(subStmt.END_SUB(), "End Function"); + var argContext = (VBAParser.ArgContext)arg.Context; rewriter.InsertAfter(subStmt.argList().Stop.TokenIndex, $" As {arg.AsTypeName}"); if (arg.IsByRef) @@ -86,11 +94,26 @@ private void UpdateSignature(Declaration target, ParameterDeclaration arg, IRewr { rewriter.InsertBefore(argContext.unrestrictedIdentifier().Start.TokenIndex, Tokens.ByVal); } + } - var returnStmt = $" {subStmt.subroutineName().GetText()} = {argContext.unrestrictedIdentifier().GetText()}{Environment.NewLine}"; + private void AddReturnStatement(VBAParser.SubStmtContext subStmt, string argName, IModuleRewriter rewriter) + { + var returnStmt = $" {subStmt.subroutineName().GetText()} = {argName}{Environment.NewLine}"; + // This exploits that the VBE will realign the End Function statement automatically. rewriter.InsertBefore(subStmt.END_SUB().Symbol.TokenIndex, returnStmt); } + private void ReplaceExitSubs(VBAParser.SubStmtContext subStmt, string argName, IModuleRewriter rewriter) + { + // We use a statement separator here to be able to deal with single line if statments without too much issues. + var exitFunctionCode = $"{subStmt.subroutineName().GetText()} = {argName}: Exit Function"; + foreach (var exitSub in subStmt.GetDescendents()) + { + rewriter.Replace(exitSub, exitFunctionCode); + } + } + + private void UpdateCall(IdentifierReference reference, int argIndex, IRewriteSession rewriteSession) { var rewriter = rewriteSession.CheckOutModuleRewriter(reference.QualifiedModuleName); diff --git a/Rubberduck.Core/Properties/Settings.Designer.cs b/Rubberduck.Core/Properties/Settings.Designer.cs index 017f2c6c14..90eeb2cf96 100644 --- a/Rubberduck.Core/Properties/Settings.Designer.cs +++ b/Rubberduck.Core/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace Rubberduck.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.6.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/Rubberduck.Core/Rubberduck.Core.csproj b/Rubberduck.Core/Rubberduck.Core.csproj index 9c4dc78bb9..cda42e9170 100644 --- a/Rubberduck.Core/Rubberduck.Core.csproj +++ b/Rubberduck.Core/Rubberduck.Core.csproj @@ -93,4 +93,17 @@ 2.0.20525 + + + True + True + Settings.settings + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + diff --git a/Rubberduck.Core/Settings/GeneralSettings.cs b/Rubberduck.Core/Settings/GeneralSettings.cs index aac14af9fa..f9b9664735 100644 --- a/Rubberduck.Core/Settings/GeneralSettings.cs +++ b/Rubberduck.Core/Settings/GeneralSettings.cs @@ -13,6 +13,7 @@ public interface IGeneralSettings DisplayLanguageSetting Language { get; set; } bool CanShowSplash { get; set; } bool CanCheckVersion { get; set; } + string ApiBaseUrl { get; set; } bool IncludePreRelease { get; set; } bool CompileBeforeParse { get; set; } bool IsSmartIndenterPrompted { get; set; } @@ -45,6 +46,7 @@ public DisplayLanguageSetting Language public bool CanShowSplash { get; set; } public bool CanCheckVersion { get; set; } + public string ApiBaseUrl { get; set; } public bool IncludePreRelease { get; set; } public bool CompileBeforeParse { get; set; } public bool IsSmartIndenterPrompted { get; set; } @@ -103,7 +105,8 @@ public bool Equals(GeneralSettings other) EnableExperimentalFeatures.Count == other.EnableExperimentalFeatures.Count && EnableExperimentalFeatures.All(other.EnableExperimentalFeatures.Contains) && SetDpiUnaware == other.SetDpiUnaware && - EnableFolderDragAndDrop == other.EnableFolderDragAndDrop; + EnableFolderDragAndDrop == other.EnableFolderDragAndDrop && + ApiBaseUrl == other.ApiBaseUrl; } } } \ No newline at end of file diff --git a/Rubberduck.Core/UI/About/AboutControl.xaml b/Rubberduck.Core/UI/About/AboutControl.xaml index 71d2f43e7b..0890bcb495 100644 --- a/Rubberduck.Core/UI/About/AboutControl.xaml +++ b/Rubberduck.Core/UI/About/AboutControl.xaml @@ -19,7 +19,7 @@ - + - - + + + + + @@ -88,7 +91,7 @@ - + @@ -107,57 +110,90 @@ - - - - - - - - - - - - rubberduckvba.com + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + rubberduckvba.com + + + + + + + + + + - - - - Code Review (Stack Exchange) + + + + Code Review (Stack Exchange) Stack Overflow Digital Ocean Hacktoberfest JetBrains ReSharper Community Team Microsoft MVP Award Program - + - Abraham Hosch + Style="{StaticResource NormalLabel}" FontWeight="Bold" /> + Abraham Hosch Andrew Jackson Andrew Zschetzsche Andrew Mansell @@ -203,13 +239,11 @@ Wayne Phillips (vbWatchdog, twinBASIC) FontSize="10" HorizontalAlignment="Left" TextWrapping="WrapWithOverflow" - Margin="15,0,0,0"/> + Margin="15,0,0,0" /> - - diff --git a/Rubberduck.Core/UI/AddRemoveReferences/AddRemoveReferencesWindow.xaml b/Rubberduck.Core/UI/AddRemoveReferences/AddRemoveReferencesWindow.xaml index e2e3f1a5a5..4368c49a64 100644 --- a/Rubberduck.Core/UI/AddRemoveReferences/AddRemoveReferencesWindow.xaml +++ b/Rubberduck.Core/UI/AddRemoveReferences/AddRemoveReferencesWindow.xaml @@ -85,7 +85,7 @@ @@ -106,12 +106,12 @@ - + - - + + @@ -152,8 +152,8 @@ - @@ -416,7 +416,7 @@ - + - + - + @@ -485,7 +485,7 @@ Command="{Binding CodeExplorerExtractInterfaceCommand}" CommandParameter="{Binding SelectedItem, Mode=OneWay}"> - + @@ -493,7 +493,7 @@ Command="{Binding AddRemoveReferencesCommand}" CommandParameter="{Binding SelectedItem, Mode=OneWay}"> - + - + + ItemsSource="{StaticResource AddModuleCommands}"> - + - + - + - + - + - + @@ -589,7 +589,7 @@ Command="{Binding PrintCommand}" CommandParameter="{Binding SelectedItem, Mode=OneWay}"> - + @@ -608,7 +608,7 @@ - @@ -621,10 +621,10 @@ - - + @@ -640,15 +640,15 @@ - - + + - + @@ -660,10 +660,10 @@ - - + + - + - + - + @@ -78,7 +78,7 @@ - + @@ -89,9 +89,9 @@ - + - + diff --git a/Rubberduck.Core/UI/Command/MenuItems/ParentMenus/ParentMenuItemBase.cs b/Rubberduck.Core/UI/Command/MenuItems/ParentMenus/ParentMenuItemBase.cs index 7e5c9a3123..d73dc4faa2 100644 --- a/Rubberduck.Core/UI/Command/MenuItems/ParentMenus/ParentMenuItemBase.cs +++ b/Rubberduck.Core/UI/Command/MenuItems/ParentMenus/ParentMenuItemBase.cs @@ -154,8 +154,8 @@ public async Task EvaluateCanExecuteAsync(RubberduckParserState state, Cancellat } catch (Exception exception) { - value.IsEnabled = false; Logger.Error(exception, "Could not evaluate availability of commmand menu item {0}.", value.Tag ?? "{Unknown}"); + value.IsEnabled = false; } }); break; diff --git a/Rubberduck.Core/UI/Command/VersionCheckCommand.cs b/Rubberduck.Core/UI/Command/VersionCheckCommand.cs index ed6fd27e6c..1a00fc42f5 100644 --- a/Rubberduck.Core/UI/Command/VersionCheckCommand.cs +++ b/Rubberduck.Core/UI/Command/VersionCheckCommand.cs @@ -53,40 +53,31 @@ protected override async void OnExecute(object parameter) Logger.Info("Executing version check..."); var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5)); - await _versionCheck - .GetLatestVersionAsync(settings, tokenSource.Token) - .ContinueWith(t => - { - if (t.IsFaulted) - { - Logger.Warn(t.Exception); - return; - } + var latest = await _versionCheck.GetLatestVersionAsync(settings, tokenSource.Token); - if (_versionCheck.CurrentVersion < t.Result) - { - var proceed = true; - if (_versionCheck.IsDebugBuild || !settings.IncludePreRelease) - { - // if the latest version has a revision number and isn't a pre-release build, - // avoid prompting since we can't know if the build already includes the latest version. - proceed = t.Result.Revision == 0; - } + if (_versionCheck.CurrentVersion < latest) + { + var proceed = true; + if (_versionCheck.IsDebugBuild || !settings.IncludePreRelease) + { + // if the latest version has a revision number and isn't a pre-release build, + // avoid prompting since we can't know if the build already includes the latest version. + proceed = latest.Revision == 0; + } - if (proceed) - { - PromptAndBrowse(t.Result, settings.IncludePreRelease); - } - else - { - Logger.Info("Version check skips notification of an existing newer version available."); - } - } - else - { - Logger.Info("Version check completed: running current latest."); - } - }); + if (proceed) + { + PromptAndBrowse(latest, settings.IncludePreRelease); + } + else + { + Logger.Info("Version check skips notification of an existing newer version available."); + } + } + else if (latest != default) + { + Logger.Info("Version check completed: running current latest."); + } } private void PromptAndBrowse(Version latestVersion, bool includePreRelease) diff --git a/Rubberduck.Core/UI/Controls/BusyIndicator.xaml b/Rubberduck.Core/UI/Controls/BusyIndicator.xaml index cabaf9c198..cec9e023b2 100644 --- a/Rubberduck.Core/UI/Controls/BusyIndicator.xaml +++ b/Rubberduck.Core/UI/Controls/BusyIndicator.xaml @@ -43,31 +43,31 @@ - + - + - + - + - + - + - + - + - + diff --git a/Rubberduck.Core/UI/Controls/EmptyUIRefresh.xaml b/Rubberduck.Core/UI/Controls/EmptyUIRefresh.xaml index df0ff40823..49709a5844 100644 --- a/Rubberduck.Core/UI/Controls/EmptyUIRefresh.xaml +++ b/Rubberduck.Core/UI/Controls/EmptyUIRefresh.xaml @@ -14,13 +14,13 @@ - + - @@ -106,8 +106,8 @@