Skip to content

Release 0.7.2 #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# PowerShell Editor Services Release History

## 0.7.2
### Friday, September 2, 2016

- Fixed #284: PowerShellContext.AbortException crashes when called more than once
- Fixed #285: PSScriptAnalyzer settings are not being passed to Invoke-ScriptAnalyzer
- Fixed #287: Language service crashes when invalid path chars are used in dot-sourced script reference

## 0.7.1
### Tuesday, August 23, 2016

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ clone_depth: 10
skip_tags: true

environment:
core_version: '0.7.1'
core_version: '0.7.2'
prerelease_name: '-beta'

branches:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PowerShellEditorServices.psm1'

# Version number of this module.
ModuleVersion = '0.7.1'
ModuleVersion = '0.7.2'

# ID used to uniquely identify this module
GUID = '9ca15887-53a2-479a-9cda-48d26bcb6c47'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ private void OnListenTaskCompleted(Task listenTask)
{
if (listenTask.IsFaulted)
{
Logger.Write(
LogLevel.Error,
string.Format(
"MessageDispatcher loop terminated due to unhandled exception:\r\n\r\n{0}",
listenTask.Exception.ToString()));

this.OnUnhandledException(listenTask.Exception);
}
else if (listenTask.IsCompleted || listenTask.IsCanceled)
Expand Down
11 changes: 8 additions & 3 deletions src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,20 @@ protected Task HandleDisconnectRequest(
if (e.NewSessionState == PowerShellContextState.Ready)
{
await requestContext.SendResult(null);
editorSession.PowerShellContext.SessionStateChanged -= handler;
this.editorSession.PowerShellContext.SessionStateChanged -= handler;

// Stop the server
await this.Stop();
}
};

editorSession.PowerShellContext.SessionStateChanged += handler;
editorSession.PowerShellContext.AbortExecution();
// In some rare cases, the EditorSession will already be disposed
// so we shouldn't try to abort because PowerShellContext will be null
if (this.editorSession != null && this.editorSession.PowerShellContext != null)
{
this.editorSession.PowerShellContext.SessionStateChanged += handler;
this.editorSession.PowerShellContext.AbortExecution();
}

return Task.FromResult(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ protected async Task HandleDidChangeConfigurationNotification(
string newSettingsPath = this.currentSettings.ScriptAnalysis.SettingsPath;
if (!string.Equals(oldScriptAnalysisSettingsPath, newSettingsPath, StringComparison.OrdinalIgnoreCase))
{
this.editorSession.RestartAnalysisService(newSettingsPath);
this.editorSession.AnalysisService.SettingsPath = newSettingsPath;
settingsPathChanged = true;
}

Expand Down
40 changes: 33 additions & 7 deletions src/PowerShellEditorServices/Analysis/AnalysisService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using Microsoft.PowerShell.EditorServices.Utility;
using System;
using System.IO;
using System.Linq;
using System.Management.Automation.Runspaces;
using System.Threading;
Expand Down Expand Up @@ -44,6 +43,21 @@ public class AnalysisService : IDisposable

#endregion // Private Fields


#region Properties

/// <summary>
/// Gets or sets the path to a settings file (.psd1)
/// containing PSScriptAnalyzer settings.
/// </summary>
public string SettingsPath
{
get;
set;
}

#endregion

#region Constructors

/// <summary>
Expand All @@ -56,6 +70,7 @@ public AnalysisService(IConsoleHost consoleHost, string settingsPath = null)
{
try
{
this.SettingsPath = settingsPath;
this.analysisRunspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault2());
this.analysisRunspace.ThreadOptions = PSThreadOptions.ReuseThread;
this.analysisRunspace.Open();
Expand Down Expand Up @@ -219,17 +234,28 @@ private IEnumerable<PSObject> GetDiagnosticRecords(ScriptFile file)

if (this.scriptAnalyzerModuleInfo != null)
{
using (var ps = System.Management.Automation.PowerShell.Create())
using (var powerShell = System.Management.Automation.PowerShell.Create())
{
ps.Runspace = this.analysisRunspace;
powerShell.Runspace = this.analysisRunspace;
Logger.Write(
LogLevel.Verbose,
String.Format("Running PSScriptAnalyzer against {0}", file.FilePath));

diagnosticRecords = ps.AddCommand("Invoke-ScriptAnalyzer")
.AddParameter("ScriptDefinition", file.Contents)
.AddParameter("IncludeRule", IncludedRules)
.Invoke();
powerShell
.AddCommand("Invoke-ScriptAnalyzer")
.AddParameter("ScriptDefinition", file.Contents);

// Use a settings file if one is provided, otherwise use the default rule list.
if (!string.IsNullOrWhiteSpace(this.SettingsPath))
{
powerShell.AddParameter("Settings", this.SettingsPath);
}
else
{
powerShell.AddParameter("IncludeRule", IncludedRules);
}

diagnosticRecords = powerShell.Invoke();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
{
if (commandAst.InvocationOperator.Equals(TokenKind.Dot))
{
string fileName = commandAst.CommandElements[0].Extent.Text;
// Strip any quote characters off of the string
string fileName = commandAst.CommandElements[0].Extent.Text.Trim('\'', '"');
DotSourcedFiles.Add(fileName);
}

return base.VisitCommand(commandAst);
}
}
Expand Down
10 changes: 0 additions & 10 deletions src/PowerShellEditorServices/Session/EditorSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,6 @@ public void StartDebugSession(HostDetails hostDetails, ProfilePaths profilePaths
this.Workspace = new Workspace(this.PowerShellContext.PowerShellVersion);
}

/// <summary>
/// Restarts the AnalysisService so it can be configured with a new settings file.
/// </summary>
/// <param name="settingsPath">Path to the settings file.</param>
public void RestartAnalysisService(string settingsPath)
{
this.AnalysisService?.Dispose();
InstantiateAnalysisService(settingsPath);
}

internal void InstantiateAnalysisService(string settingsPath = null)
{
// Only enable the AnalysisService if the machine has PowerShell
Expand Down
6 changes: 4 additions & 2 deletions src/PowerShellEditorServices/Session/PowerShellContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ public async Task LoadHostProfiles()
/// </summary>
public void AbortExecution()
{
if (this.SessionState != PowerShellContextState.Aborting)
if (this.SessionState != PowerShellContextState.Aborting &&
this.SessionState != PowerShellContextState.Disposed)
{
Logger.Write(LogLevel.Verbose, "Execution abort requested...");

Expand All @@ -587,7 +588,8 @@ public void AbortExecution()
{
Logger.Write(
LogLevel.Verbose,
"Execution abort requested while already aborting");
string.Format(
$"Execution abort requested when already aborted (SessionState = {this.SessionState})"));
}
}

Expand Down
55 changes: 46 additions & 9 deletions src/PowerShellEditorServices/Workspace/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ private void RecursivelyFindReferences(
baseFilePath,
referencedFileName);

// If there was an error resolving the string, skip this reference
if (resolvedScriptPath == null)
{
continue;
}

Logger.Write(
LogLevel.Verbose,
string.Format(
Expand Down Expand Up @@ -287,18 +293,49 @@ private string GetBaseFilePath(string filePath)

private string ResolveRelativeScriptPath(string baseFilePath, string relativePath)
{
if (Path.IsPathRooted(relativePath))
string combinedPath = null;
Exception resolveException = null;

try
{
return relativePath;
// If the path is already absolute there's no need to resolve it relatively
// to the baseFilePath.
if (Path.IsPathRooted(relativePath))
{
return relativePath;
}

// Get the directory of the original script file, combine it
// with the given path and then resolve the absolute file path.
combinedPath =
Path.GetFullPath(
Path.Combine(
baseFilePath,
relativePath));
}
catch (NotSupportedException e)
{
// Occurs if the path is incorrectly formatted for any reason. One
// instance where this occurred is when a user had curly double-quote
// characters in their source instead of normal double-quotes.
resolveException = e;
}
catch (ArgumentException e)
{
// Occurs if the path contains invalid characters, specifically those
// listed in System.IO.Path.InvalidPathChars.
resolveException = e;
}

// Get the directory of the original script file, combine it
// with the given path and then resolve the absolute file path.
string combinedPath =
Path.GetFullPath(
Path.Combine(
baseFilePath,
relativePath));
if (resolveException != null)
{
Logger.Write(
LogLevel.Error,
$"Could not resolve relative script path\r\n" +
$" baseFilePath = {baseFilePath}\r\n " +
$" relativePath = {relativePath}\r\n\r\n" +
$"{resolveException.ToString()}");
}

return combinedPath;
}
Expand Down
2 changes: 1 addition & 1 deletion test/PowerShellEditorServices.Test.Host/ServerTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected async Task<Tuple<int, int>> LaunchService(
string scriptPath = Path.Combine(modulePath, "Start-EditorServices.ps1");

// TODO: Need to determine the right module version programmatically!
string editorServicesModuleVersion = "0.7.1";
string editorServicesModuleVersion = "0.7.2";

string scriptArgs =
string.Format(
Expand Down