diff --git a/src/PowerShellEditorServices.Host/Program.cs b/src/PowerShellEditorServices.Host/Program.cs index b8be3ff07..dc2429823 100644 --- a/src/PowerShellEditorServices.Host/Program.cs +++ b/src/PowerShellEditorServices.Host/Program.cs @@ -17,29 +17,6 @@ class Program [STAThread] static void Main(string[] args) { -#if DEBUG - // In the future, a more robust argument parser will be added here - bool waitForDebugger = - args.Any( - arg => - string.Equals( - arg, - "/waitForDebugger", - StringComparison.InvariantCultureIgnoreCase)); - - // Should we wait for the debugger before starting? - if (waitForDebugger) - { - // Wait for 15 seconds and then continue - int waitCountdown = 15; - while (!Debugger.IsAttached && waitCountdown > 0) - { - Thread.Sleep(1000); - waitCountdown--; - } - } -#endif - string logPath = null; string logPathArgument = args.FirstOrDefault( @@ -80,6 +57,43 @@ static void Main(string[] args) // TODO: Set the level based on command line parameter Logger.Initialize(logPath, LogLevel.Verbose); +#if DEBUG + bool waitForDebugger = + args.Any( + arg => + string.Equals( + arg, + "/waitForDebugger", + StringComparison.InvariantCultureIgnoreCase)); + + // Should we wait for the debugger before starting? + if (waitForDebugger) + { + Logger.Write(LogLevel.Normal, "Waiting for debugger to attach before continuing..."); + + // Wait for 15 seconds and then continue + int waitCountdown = 15; + while (!Debugger.IsAttached && waitCountdown > 0) + { + Thread.Sleep(1000); + waitCountdown--; + } + + if (Debugger.IsAttached) + { + Logger.Write( + LogLevel.Normal, + "Debugger attached, continuing startup sequence"); + } + else if (waitCountdown == 0) + { + Logger.Write( + LogLevel.Normal, + "Timed out while waiting for debugger to attach, continuing startup sequence"); + } + } +#endif + Logger.Write(LogLevel.Normal, "PowerShell Editor Services Host starting..."); // Start the server diff --git a/src/PowerShellEditorServices/Analysis/AnalysisService.cs b/src/PowerShellEditorServices/Analysis/AnalysisService.cs index 87ac6c0a1..a1ec5a0d4 100644 --- a/src/PowerShellEditorServices/Analysis/AnalysisService.cs +++ b/src/PowerShellEditorServices/Analysis/AnalysisService.cs @@ -23,6 +23,21 @@ public class AnalysisService : IDisposable private Runspace analysisRunspace; private ScriptAnalyzer scriptAnalyzer; + /// + /// Defines the list of Script Analyzer rules to include by default. + /// In the future, a default rule set from Script Analyzer may be used. + /// + private static readonly string[] IncludedRules = new string[] + { + "PSUseApprovedVerbs", + "PSReservedCmdletChar", + "PSReservedParams", + "PSShouldProcess", + "PSMissingModuleManifestField", + "PSAvoidDefaultValueSwitchParameter", + "PSUseDeclaredVarsMoreThanAssigments" + }; + #endregion #region Constructors @@ -32,8 +47,6 @@ public class AnalysisService : IDisposable /// public AnalysisService() { - // TODO: Share runspace with PowerShellContext? Probably should always - // run analysis in a local session. this.analysisRunspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault2()); this.analysisRunspace.ApartmentState = ApartmentState.STA; this.analysisRunspace.ThreadOptions = PSThreadOptions.ReuseThread; @@ -44,8 +57,7 @@ public AnalysisService() this.analysisRunspace, new AnalysisOutputWriter(), null, - null, - new string[] { "DscTestsPresent", "DscExamplesPresent" }); + IncludedRules); } #endregion