{"action":"created","issue":{"url":"https://api.github.com/repos/PowerShell/PowerShellEditorServices/issues/672","repository_url":"https://api.github.com/repos/PowerShell/PowerShellEditorServices","labels_url":"https://api.github.com/repos/PowerShell/PowerShellEditorServices/issues/672/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/PowerShellEditorServices/issues/672/comments","events_url":"https://api.github.com/repos/PowerShell/PowerShellEditorServices/issues/672/events","html_url":"https://github.com/PowerShell/PowerShellEditorServices/pull/672","id":328830988,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkyMjQ5MDYy","number":672,"title":"PSReadLine integration","user":{"login":"SeeminglyScience","id":24977523,"node_id":"MDQ6VXNlcjI0OTc3NTIz","avatar_url":"https://avatars3.githubusercontent.com/u/24977523?v=4","gravatar_id":"","url":"https://api.github.com/users/SeeminglyScience","html_url":"https://github.com/SeeminglyScience","followers_url":"https://api.github.com/users/SeeminglyScience/followers","following_url":"https://api.github.com/users/SeeminglyScience/following{/other_user}","gists_url":"https://api.github.com/users/SeeminglyScience/gists{/gist_id}","starred_url":"https://api.github.com/users/SeeminglyScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SeeminglyScience/subscriptions","organizations_url":"https://api.github.com/users/SeeminglyScience/orgs","repos_url":"https://api.github.com/users/SeeminglyScience/repos","events_url":"https://api.github.com/users/SeeminglyScience/events{/privacy}","received_events_url":"https://api.github.com/users/SeeminglyScience/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":46,"created_at":"2018-06-03T13:57:50Z","updated_at":"2018-07-31T23:09:46Z","closed_at":null,"author_association":"COLLABORATOR","pull_request":{"url":"https://api.github.com/repos/PowerShell/PowerShellEditorServices/pulls/672","html_url":"https://github.com/PowerShell/PowerShellEditorServices/pull/672","diff_url":"https://github.com/PowerShell/PowerShellEditorServices/pull/672.diff","patch_url":"https://github.com/PowerShell/PowerShellEditorServices/pull/672.patch"},"body":"I messed up the merge conflict resolution in #671, many thanks to the great @markekraus for helping me resolve that ❤️ \r\n\r\n## PSReadLine Integration\r\n\r\nThis change brings integration of PSReadLine to the PSES integrated console. Here's a short list\r\nof the cool stuff this brings to the console experience\r\n\r\n- Multi-line editing support\r\n- Very customizable keybinds via `Set-PSReadLineKeyHandler`\r\n- Syntax highlighting\r\n- Persistent history\r\n- Easy interactive history search (default is <kbd>ctrl</kbd> + <kbd>r</kbd>)\r\n- A lot more, check out the [PSReadLine]() repo for more info\r\n\r\nAdditionally, integrating PSReadLine required reworking a large portion of our code around debugging\r\nand the way we manage invoking commands. Part of this rework required finding a lot of the places\r\nthe debugger would occasionally hang or crash. This should result in a big boost to stability for\r\nthose having issues with the debugger.\r\n\r\n## Maintainers/Contributers\r\n\r\nWith this change comes some complexity in the state of the runspace. There are now several different\r\ntypes of contexts in which a command can be ran.\r\n\r\n1. Normally - plain non-nested PowerShell instance\r\n1. Nested - A PowerShell instance belonging to a nested prompt. Nested PowerShell instances must run\r\n  on the pipeline thread.\r\n1. Event - PowerShell events are used to take over the pipeline thread from PSReadLine\r\n1. Debugger - When the debugger is stopped, commands are routed through `Debugger.ProcessCommand` which\r\n  must be invoked on the pipeline thread\r\n\r\nBecause of this complexity, when at all possible route any interactions with the runspace through\r\n`PowerShellContext.ExecuteCommand`.  All of the logic for determining what context to invoke the\r\ncommand in is handled via that method.  If it can't (or shouldn't) be invoked in PowerShell, but\r\nstill must be ran on the pipeline thread, you can use `PowerShellContext.InvokeOnPipelineThread`.\r\n\r\nAlong with these changes I also implemented `$Host.EnterNestedPrompt()`.  I did this because I already\r\nneeded a system to track multiple layers of \"context\" and what PowerShell instance to give them, what\r\nthread to send them to, etc.  So it with that requirement, it wasn't all that much extra work to throw\r\nthat in.\r\n\r\n## Installing to test\r\n\r\n### PSReadLine\r\n\r\n1. Download the build from [AppVeyor](https://ci.appveyor.com/api/buildjobs/cfioquswa7y64qvd/artifacts/bin%2FRelease%2FPSReadLine.zip)\r\n1. Close all PowerShell windows (`gps powershell | ? id -ne $pid | spps`)\r\n1. Extract the AppVeyor build into your module path.  Create a `2.0.0` directory if required. Should be\r\nsomething like `\"$(Split-Path $profile.CurrentUserAllHosts)/Modules/PSReadLine/2.0.0/<contents-here>\"`\r\n\r\n### The Extension\r\n\r\n#### Prebundled (easier)\r\n\r\nYou can grab the [PowerShell-v2-insiders.vsix from AppVeyor here](https://ci.appveyor.com/project/PowerShell/vscode-powershell/build/1.7.0-insiders-557/artifacts)\r\n\r\nTo install it:\r\n\r\n1. open VSCode\r\n1. open the command pallet (`ctrl/cmd+shift+p`) \r\n1. Type `VSIX` and select the install option and navigate to the vsix you downloaded\r\n1. Add this setting to your VSCode user settings:\r\n```json\r\n    \"powershell.developer.featureFlags\": [\r\n        \"PSReadLine\"\r\n    ],\r\n ```\r\n\r\n#### Bundle yourself (harder)\r\n\r\n1. Download the build from [AppVeyor](https://ci.appveyor.com/api/buildjobs/wy6l9n10ffnkgaxf/artifacts/PowerShellEditorServices-1.7.0-1272.zip)\r\n1. Find your VSCode extensions folder. An easy way is to run `gmo PowerShellEditorServices|% ModuleBase` within\r\nthe integrated console.\r\n1. Make sure all VSCode windows are closed (or at least the integrated console in them)\r\n1. Extract the contents of the build to `<yourExtensionsFolder>\\ms-vscode.powershell-1.7.0\\modules\\PowerShellEditorServices`\r\n1. Add this setting to your VSCode user settings\r\n    ```json\r\n    \"powershell.developer.featureFlags\": [\r\n        \"PSReadLine\"\r\n    ],\r\n    ```\r\n\r\n### Troubleshooting\r\n\r\nIf you start VSCode and the integrated console and PSReadLine doesn't load (easy way to tell is no syntax highlighting) then try the following\r\n\r\n1. Clear out any other versions of PSReadLine. The module import logic needs some refining, sometimes\r\n    this is especially a problem if you have other versions of the pre-release 2.0 installed.\r\n\r\n1. Ensure run/execute permission is enabled for the DLL's of both modules.  In Windows ensure they\r\n    are \"unblocked\" (`Unblock-File`).\r\n\r\n1. If running PowerShell Core, you need to replace the `Microsoft.PowerShell.ReadLine.dll` with the\r\n    `Microsoft.PowerShell.ReadLine2.dll` from the prerelease build.  Hopefully that's a bug in my\r\n    module import code and not something that will be required at release.\r\n\r\n## Known issues\r\n\r\nPlease note this is not being merged into `master`, but into `2.0.0`.  This needs a lot more testing\r\nand fixes before it can be recommended for use in production environments.\r\n\r\n* When selecting code in the editor and pressing F8 to send it to the console, the syntax of the script\r\n    is not highlighted\r\n\r\n* Unix platforms are probably a bit buggy at the moment.  We have to inject our `ReadKey` implementation\r\n    into PSReadLine, and I didn't get that working perfectly.  I'll need some help from @tylerl0706 and\r\n    @rjmholt with that as I don't have a great linux test environment.\r\n\r\n* The stream for the debug adapter occasionally closes unexpectedly which makes PSES hang.\r\n    Not sure if this is a new bug, or just one of the existing hangs I didn't get to fix yet.\r\n\r\n* Key bindings are a little different, closer to Unix based terminals. For example, to bind `ctrl+space`\r\n    you must use the chord `ctrl+@` and to bind `ctrl+backspace` you need to bind `ctrl+w`.  Most\r\n    notably, it does not appear that there is *any way* to get `shift+enter` to register.  I believe\r\n    that's an issue with nodepty.  This is more VSCode/Atom specific than PSES, but it's worth noting."},"comment":{"url":"https://api.github.com/repos/PowerShell/PowerShellEditorServices/issues/comments/409396951","html_url":"https://github.com/PowerShell/PowerShellEditorServices/pull/672#issuecomment-409396951","issue_url":"https://api.github.com/repos/PowerShell/PowerShellEditorServices/issues/672","id":409396951,"node_id":"MDEyOklzc3VlQ29tbWVudDQwOTM5Njk1MQ==","user":{"login":"JustinGrote","id":15258962,"node_id":"MDQ6VXNlcjE1MjU4OTYy","avatar_url":"https://avatars0.githubusercontent.com/u/15258962?v=4","gravatar_id":"","url":"https://api.github.com/users/JustinGrote","html_url":"https://github.com/JustinGrote","followers_url":"https://api.github.com/users/JustinGrote/followers","following_url":"https://api.github.com/users/JustinGrote/following{/other_user}","gists_url":"https://api.github.com/users/JustinGrote/gists{/gist_id}","starred_url":"https://api.github.com/users/JustinGrote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JustinGrote/subscriptions","organizations_url":"https://api.github.com/users/JustinGrote/orgs","repos_url":"https://api.github.com/users/JustinGrote/repos","events_url":"https://api.github.com/users/JustinGrote/events{/privacy}","received_events_url":"https://api.github.com/users/JustinGrote/received_events","type":"User","site_admin":false},"created_at":"2018-07-31T23:09:46Z","updated_at":"2018-07-31T23:09:46Z","author_association":"NONE","body":"### Environment\r\n[Powershell Extension Insiders 717](https://ci.appveyor.com/project/PowerShell/vscode-powershell/build/1.8.2-insiders-717/artifacts)\r\n[PSES 1.81.1345 (from commit ce49cd6 \"remove keyavailable query)](https://ci.appveyor.com/project/PowerShell/powershelleditorservices/build/1.8.1.1345/artifacts)\r\n\r\nI still saw the nullpointerexception when stopping the interactive session in the logs, but it so far hasn't crashed the terminal yet, so I'm guessing this is getting caught better. So far so good with very basic testing, hasn't crashed so far. Attached are verbose logs for reference, a few errors in there that could probably be caught and cleaned up.\r\n\r\n[1533078100-be4dac38-5a4f-41bb-b2df-1b9b427527c21533078092839.zip](https://github.com/PowerShell/PowerShellEditorServices/files/2247367/1533078100-be4dac38-5a4f-41bb-b2df-1b9b427527c21533078092839.zip)\r\n\r\n\r\n```\r\n2018-07-31 16:05:20.273 [ERROR] C:\\projects\\powershelleditorservices\\src\\PowerShellEditorServices.Protocol\\Server\\DebugAdapter.cs: In method 'OnExecutionCompleted', line 127:\r\n    Exception occurred while awaiting debug launch task.\r\n\r\nSystem.NullReferenceException: Object reference not set to an instance of an object.\r\n       at Microsoft.PowerShell.EditorServices.Protocol.Server.DebugAdapter.<OnExecutionCompleted>d__22.MoveNext()\r\n```"}}
{"actor":{"display_login":"JustinGrote"}}