Description
System Details
Operating system name and version: Windows 10.0.14393
code -v
1.19.3
7c4205b5c6e52a53b81c69d2b2dc8a627abaa0ba
x64
$pseditor.EditorServicesVersion
Major Minor Build Revision
----- ----- ----- --------
1 5 1 0
code --list-extensions --show-versions
$PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.1944
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1944
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Issue Description
Environment. I have tho editors open
- "Launcher" file. Used to set some vars and execute the script I'm currently working on. I created a debug configuration that launches that file. It has 29 lines
- The script file. It has 100+ lines.
The issue itself. Sometimes when I edit the second file and then switch to the first one and start typing, the PowerShell Intergrated terminal crashes right before the IntelliSence autocomplete happens. Examining verbose log discovered the ArgumentOutOfRangeException (see below). Looks like that editor position (109:2) passed to the Microsoft.PowerShell.EditorServices.ScriptFile.ValidatePosition method is taken from the previous file. Since line number is bigger than actual line count in the currently open file, the Exception is thrown.
Empirically, this looks like that for some reason editor is not able to fully switch between editors in a timely fashion or the editor position is not updated on file change, but this is just a guess.
Sometimes it happens very often forcing me to restart the terminal loosing all the prepared environment which is very frustrating on long-running scripts that use cached values during development.
It looks like issue described in #918, which is not fixed yet.
Attached Logs
Nothing uncommon in the logs, except the last exception:
07.02.2018 8:27:20 [ERROR] - Method "OnListenTaskCompleted" at line 391 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs
ProtocolEndpoint message loop terminated due to unhandled exception:
System.AggregateException: One or more errors occurred. ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: Position 109:2 is outside of the line range of 1 to 29.
at Microsoft.PowerShell.EditorServices.ScriptFile.ValidatePosition(Int32 line, Int32 column)
at Microsoft.PowerShell.EditorServices.ScriptFile.ApplyChange(FileChange fileChange)
at Microsoft.PowerShell.EditorServices.Protocol.Server.LanguageServer.HandleDidChangeTextDocumentNotification(DidChangeTextDocumentParams textChangeParams, EventContext eventContext)
at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<>c__DisplayClass6_0`2.<SetEventHandler>b__0(Message eventMessage, MessageWriter messageWriter)
at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
at Microsoft.PowerShell.EditorServices.Utility.AsyncContextThread.<>c__DisplayClass4_0.<Run>b__0()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: Position 109:2 is outside of the line range of 1 to 29.
at Microsoft.PowerShell.EditorServices.ScriptFile.ValidatePosition(Int32 line, Int32 column)
at Microsoft.PowerShell.EditorServices.ScriptFile.ApplyChange(FileChange fileChange)
at Microsoft.PowerShell.EditorServices.Protocol.Server.LanguageServer.HandleDidChangeTextDocumentNotification(DidChangeTextDocumentParams textChangeParams, EventContext eventContext)
at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<>c__DisplayClass6_0`2.<SetEventHandler>b__0(Message eventMessage, MessageWriter messageWriter)
at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
at Microsoft.PowerShell.EditorServices.Utility.AsyncContextThread.<>c__DisplayClass4_0.<Run>b__0()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()<---
07.02.2018 8:27:20 [ERROR] - Method "ProtocolEndpoint_UnhandledException" at line 418 of C:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\EditorServicesHost.cs
PowerShell Editor Services is terminating due to an unhandled exception, see previous logs for details.