Skip to content

Commit ac80790

Browse files
committed
WIP: InvocationInfo is null?!
1 parent 6443e78 commit ac80790

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,8 @@ private static string TrimScriptListingLine(PSObject scriptLineObj, ref int pref
953953
internal async void OnDebuggerStopAsync(object sender, DebuggerStopEventArgs e)
954954
{
955955
bool noScriptName = false;
956-
string localScriptPath = e.InvocationInfo.ScriptName;
956+
// TODO: Why is InvocationInfo sometimes null?
957+
string localScriptPath = e.InvocationInfo?.ScriptName;
957958

958959
// If there's no ScriptName, get the "list" of the current source
959960
if (remoteFileManager is not null && string.IsNullOrEmpty(localScriptPath))
@@ -1013,7 +1014,8 @@ await remoteFileManager.FetchRemoteFileAsync(
10131014
{
10141015
// Augment the top stack frame with details from the stop event
10151016

1016-
if (invocationTypeScriptPositionProperty.GetValue(e.InvocationInfo) is IScriptExtent scriptExtent)
1017+
if (e.InvocationInfo is not null
1018+
&& invocationTypeScriptPositionProperty.GetValue(e.InvocationInfo) is IScriptExtent scriptExtent)
10171019
{
10181020
stackFrameDetails[0].StartLineNumber = scriptExtent.StartLineNumber;
10191021
stackFrameDetails[0].EndLineNumber = scriptExtent.EndLineNumber;

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/DebuggerStoppedEventArgs.cs

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using System.Management.Automation;
5+
using System.Security.Cryptography;
46
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Runspace;
57
using Microsoft.PowerShell.EditorServices.Utility;
6-
using System.Management.Automation;
78

89
namespace Microsoft.PowerShell.EditorServices.Services.DebugAdapter
910
{
@@ -46,7 +47,14 @@ public int LineNumber
4647
{
4748
get
4849
{
49-
return this.OriginalEvent.InvocationInfo.ScriptLineNumber;
50+
if (OriginalEvent.InvocationInfo is not null)
51+
{
52+
return OriginalEvent.InvocationInfo.ScriptLineNumber;
53+
}
54+
else
55+
{
56+
return 1;
57+
}
5058
}
5159
}
5260

@@ -57,7 +65,14 @@ public int ColumnNumber
5765
{
5866
get
5967
{
60-
return this.OriginalEvent.InvocationInfo.OffsetInLine;
68+
if (OriginalEvent.InvocationInfo is not null)
69+
{
70+
return OriginalEvent.InvocationInfo.OffsetInLine;
71+
}
72+
else
73+
{
74+
return 1;
75+
}
6176
}
6277
}
6378

@@ -99,11 +114,11 @@ public DebuggerStoppedEventArgs(
99114
if (!string.IsNullOrEmpty(localScriptPath))
100115
{
101116
this.ScriptPath = localScriptPath;
102-
this.RemoteScriptPath = originalEvent.InvocationInfo.ScriptName;
117+
this.RemoteScriptPath = originalEvent.InvocationInfo?.ScriptName;
103118
}
104119
else
105120
{
106-
this.ScriptPath = originalEvent.InvocationInfo.ScriptName;
121+
this.ScriptPath = originalEvent.InvocationInfo?.ScriptName;
107122
}
108123

109124
this.OriginalEvent = originalEvent;

src/PowerShellEditorServices/Services/PowerShell/Debugging/PowerShellDebugContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private void RaiseDebuggerStoppedEvent()
159159
{
160160
if (!IsDebugServerActive)
161161
{
162-
_languageServer.SendNotification("powerShell/startDebugger");
162+
_languageServer?.SendNotification("powerShell/startDebugger");
163163
}
164164

165165
DebuggerStopped?.Invoke(this, LastStopEventArgs);

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public DebugServiceTests()
5353

5454
debugService = new DebugService(
5555
_psesHost,
56-
new PowerShellDebugContext(NullLoggerFactory.Instance, null, _psesHost),
56+
_psesHost.DebugContext,
57+
// new PowerShellDebugContext(NullLoggerFactory.Instance, null, _psesHost),
5758
null,
5859
new BreakpointService(
5960
NullLoggerFactory.Instance,
@@ -1029,7 +1030,15 @@ private void AssertDebuggerStopped(
10291030
debuggerStoppedQueue.Take(new CancellationTokenSource(10000).Token);
10301031

10311032
// TODO: Why does the casing of the path change? Specifically the Drive letter on Windows.
1032-
Assert.Equal(scriptPath.ToLower(), eventArgs.ScriptPath.ToLower());
1033+
if (eventArgs.ScriptPath is not null)
1034+
{
1035+
Assert.Equal(scriptPath.ToLower(), eventArgs.ScriptPath.ToLower());
1036+
}
1037+
else
1038+
{
1039+
Assert.Equal("", scriptPath);
1040+
}
1041+
10331042
if (lineNumber > -1)
10341043
{
10351044
Assert.Equal(lineNumber, eventArgs.LineNumber);

0 commit comments

Comments
 (0)