Skip to content

Commit 50ab29f

Browse files
authored
Merge pull request #286 from PowerShell/release/0.7.2
Release 0.7.2
2 parents 30f246b + 70c7f73 commit 50ab29f

File tree

12 files changed

+111
-36
lines changed

12 files changed

+111
-36
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# PowerShell Editor Services Release History
22

3+
## 0.7.2
4+
### Friday, September 2, 2016
5+
6+
- Fixed #284: PowerShellContext.AbortException crashes when called more than once
7+
- Fixed #285: PSScriptAnalyzer settings are not being passed to Invoke-ScriptAnalyzer
8+
- Fixed #287: Language service crashes when invalid path chars are used in dot-sourced script reference
9+
310
## 0.7.1
411
### Tuesday, August 23, 2016
512

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ clone_depth: 10
55
skip_tags: true
66

77
environment:
8-
core_version: '0.7.1'
8+
core_version: '0.7.2'
99
prerelease_name: '-beta'
1010

1111
branches:

module/PowerShellEditorServices/PowerShellEditorServices.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'PowerShellEditorServices.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.7.1'
15+
ModuleVersion = '0.7.2'
1616

1717
# ID used to uniquely identify this module
1818
GUID = '9ca15887-53a2-479a-9cda-48d26bcb6c47'

src/PowerShellEditorServices.Protocol/MessageProtocol/MessageDispatcher.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ private void OnListenTaskCompleted(Task listenTask)
331331
{
332332
if (listenTask.IsFaulted)
333333
{
334+
Logger.Write(
335+
LogLevel.Error,
336+
string.Format(
337+
"MessageDispatcher loop terminated due to unhandled exception:\r\n\r\n{0}",
338+
listenTask.Exception.ToString()));
339+
334340
this.OnUnhandledException(listenTask.Exception);
335341
}
336342
else if (listenTask.IsCompleted || listenTask.IsCanceled)

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,20 @@ protected Task HandleDisconnectRequest(
201201
if (e.NewSessionState == PowerShellContextState.Ready)
202202
{
203203
await requestContext.SendResult(null);
204-
editorSession.PowerShellContext.SessionStateChanged -= handler;
204+
this.editorSession.PowerShellContext.SessionStateChanged -= handler;
205205

206206
// Stop the server
207207
await this.Stop();
208208
}
209209
};
210210

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

214219
return Task.FromResult(true);
215220
}

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ protected async Task HandleDidChangeConfigurationNotification(
366366
string newSettingsPath = this.currentSettings.ScriptAnalysis.SettingsPath;
367367
if (!string.Equals(oldScriptAnalysisSettingsPath, newSettingsPath, StringComparison.OrdinalIgnoreCase))
368368
{
369-
this.editorSession.RestartAnalysisService(newSettingsPath);
369+
this.editorSession.AnalysisService.SettingsPath = newSettingsPath;
370370
settingsPathChanged = true;
371371
}
372372

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
using Microsoft.PowerShell.EditorServices.Utility;
77
using System;
8-
using System.IO;
98
using System.Linq;
109
using System.Management.Automation.Runspaces;
1110
using System.Threading;
@@ -44,6 +43,21 @@ public class AnalysisService : IDisposable
4443

4544
#endregion // Private Fields
4645

46+
47+
#region Properties
48+
49+
/// <summary>
50+
/// Gets or sets the path to a settings file (.psd1)
51+
/// containing PSScriptAnalyzer settings.
52+
/// </summary>
53+
public string SettingsPath
54+
{
55+
get;
56+
set;
57+
}
58+
59+
#endregion
60+
4761
#region Constructors
4862

4963
/// <summary>
@@ -56,6 +70,7 @@ public AnalysisService(IConsoleHost consoleHost, string settingsPath = null)
5670
{
5771
try
5872
{
73+
this.SettingsPath = settingsPath;
5974
this.analysisRunspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault2());
6075
this.analysisRunspace.ThreadOptions = PSThreadOptions.ReuseThread;
6176
this.analysisRunspace.Open();
@@ -219,17 +234,28 @@ private IEnumerable<PSObject> GetDiagnosticRecords(ScriptFile file)
219234

220235
if (this.scriptAnalyzerModuleInfo != null)
221236
{
222-
using (var ps = System.Management.Automation.PowerShell.Create())
237+
using (var powerShell = System.Management.Automation.PowerShell.Create())
223238
{
224-
ps.Runspace = this.analysisRunspace;
239+
powerShell.Runspace = this.analysisRunspace;
225240
Logger.Write(
226241
LogLevel.Verbose,
227242
String.Format("Running PSScriptAnalyzer against {0}", file.FilePath));
228243

229-
diagnosticRecords = ps.AddCommand("Invoke-ScriptAnalyzer")
230-
.AddParameter("ScriptDefinition", file.Contents)
231-
.AddParameter("IncludeRule", IncludedRules)
232-
.Invoke();
244+
powerShell
245+
.AddCommand("Invoke-ScriptAnalyzer")
246+
.AddParameter("ScriptDefinition", file.Contents);
247+
248+
// Use a settings file if one is provided, otherwise use the default rule list.
249+
if (!string.IsNullOrWhiteSpace(this.SettingsPath))
250+
{
251+
powerShell.AddParameter("Settings", this.SettingsPath);
252+
}
253+
else
254+
{
255+
powerShell.AddParameter("IncludeRule", IncludedRules);
256+
}
257+
258+
diagnosticRecords = powerShell.Invoke();
233259
}
234260
}
235261

src/PowerShellEditorServices/Language/FindDotSourcedVisitor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
3434
{
3535
if (commandAst.InvocationOperator.Equals(TokenKind.Dot))
3636
{
37-
string fileName = commandAst.CommandElements[0].Extent.Text;
37+
// Strip any quote characters off of the string
38+
string fileName = commandAst.CommandElements[0].Extent.Text.Trim('\'', '"');
3839
DotSourcedFiles.Add(fileName);
3940
}
41+
4042
return base.VisitCommand(commandAst);
4143
}
4244
}

src/PowerShellEditorServices/Session/EditorSession.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,6 @@ public void StartDebugSession(HostDetails hostDetails, ProfilePaths profilePaths
104104
this.Workspace = new Workspace(this.PowerShellContext.PowerShellVersion);
105105
}
106106

107-
/// <summary>
108-
/// Restarts the AnalysisService so it can be configured with a new settings file.
109-
/// </summary>
110-
/// <param name="settingsPath">Path to the settings file.</param>
111-
public void RestartAnalysisService(string settingsPath)
112-
{
113-
this.AnalysisService?.Dispose();
114-
InstantiateAnalysisService(settingsPath);
115-
}
116-
117107
internal void InstantiateAnalysisService(string settingsPath = null)
118108
{
119109
// Only enable the AnalysisService if the machine has PowerShell

src/PowerShellEditorServices/Session/PowerShellContext.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ public async Task LoadHostProfiles()
571571
/// </summary>
572572
public void AbortExecution()
573573
{
574-
if (this.SessionState != PowerShellContextState.Aborting)
574+
if (this.SessionState != PowerShellContextState.Aborting &&
575+
this.SessionState != PowerShellContextState.Disposed)
575576
{
576577
Logger.Write(LogLevel.Verbose, "Execution abort requested...");
577578

@@ -587,7 +588,8 @@ public void AbortExecution()
587588
{
588589
Logger.Write(
589590
LogLevel.Verbose,
590-
"Execution abort requested while already aborting");
591+
string.Format(
592+
$"Execution abort requested when already aborted (SessionState = {this.SessionState})"));
591593
}
592594
}
593595

0 commit comments

Comments
 (0)