Skip to content

useLocalScope to true so that it works in CLM #1527

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 2 commits into from
May 14, 2020

Conversation

TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented May 14, 2020

.AddScript("0") dot sources the script. Since it's created in C#, the script is considered trusted... You can't dot source trusted scripts into a runspace that is running in ConstrainedLanguage mode otherwise it throws an exception.

This allows PSReadLine to be loaded in the PowerShell extension for VS Code when running in ConstrainedLanguage mode.

@TylerLeonhardt TylerLeonhardt marked this pull request as ready for review May 14, 2020 20:22
@TylerLeonhardt
Copy link
Member Author

cc @daxian-dbw if this could be backported to 2.0.x I'd really appreciate it. Then I can ship a PowerShell stable extension with ConstrainedLanguage mode support with PSRL.

@daxian-dbw
Copy link
Member

daxian-dbw commented May 14, 2020

@TylerLeonhardt The change is benign, but there is another use of AddScript here that happens at the initialization of PSReadLine. Since you didn't change that one, I assume it didn't cause a problem, so I'm not sure if your change in this PR is the root cause of your problem or something else more fundamental is wrong.

@TylerLeonhardt
Copy link
Member Author

@daxian-dbw that code you shared is wrapped in a try/catch. The error is probably swallowed. This change I made is the only change needed to prevent a "classic PSRL exception" from showing up in my console over and over again.

@TylerLeonhardt
Copy link
Member Author

After my last commit, the history file is "Visual Studio Code Host_history.txt"

@daxian-dbw
Copy link
Member

daxian-dbw commented May 14, 2020

When a script runs from within a nested pipeline, the script will be treated as FullLanguage, see the code here.

PSReadLine is invoked directly from within PS extension, whose pipeline thread (default Runspace) runs in ConstrainedLanguage when the machine is locked down.
.AddScript will make the script FullLanguge but the default Runspace is ConstrainedLanguage, so the invocation will fail due to AddScript(string) is dot-sourcing.

So adding useLocalScope: true is necessary for PS extension to use PSReadLine in constrained language mode.
I will publish version 2.0.2 to service this change. @TylerLeonhardt Can you please verify if there is anything else in PSReadLine that will be required for it to work in PSES in CLM?

@TylerLeonhardt
Copy link
Member Author

@daxian-dbw can you get that 2.0.2 version out for me?

@daxian-dbw
Copy link
Member

@TylerLeonhardt Will do. I'm currently busy on the .NET CAP work, can it wait till early next week?

@TylerLeonhardt
Copy link
Member Author

Yeah that's fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants