Skip to content
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

Support ConstrainedLanguage mode #1269

Conversation

TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Apr 22, 2020

With this PR, we have some support of ConstrainedLanguage mode. The LanguageMode is inherited from the initial runspace that starts Start-EditorServices

Windows PowerShell is started without PSRL and it is working... but there's more work that will need to be done here. Here are notes I've made from this:

  • Custom Clear-Host doesn't work... probably because $psEditor doesn't work
    • Fixed by only calling $psEditor.....Clear() on FullLanguage
  • $psEditor doesn't work because of method invoking
    • ISE has same problem... aka by-design
  • Diagnostics aren't showing up (on Windows PowerShell, but show up on PSCore probably because of different definitions of "Trusted")
    • PSSA is being loaded with ConstrainedLanguage mode in Windows PowerShell to this proves my theory.
  • Windows PowerShell is started without PSRL (this is also happening in a console outside of VS Code)
    • NOTE: idk why but PSReadLine doesn't show up in Get-Module -list in Windows PowerShell
    • Since we won't offer PSRL for ConstrainedLanguage mode initially, this isn't a problem atm
  • PS 6.2+ loads PSRL... and it seems to work (syntax highlighting, readline all works)... but it emits a System.NotSupportedException: Cannot dot-source this command because it was defined in a different language mode... over and over and over so not sure if it's PSRL's fault or PSES's yet...
    • For now, I'm offering the legacy readline for ConstrainedLanguage mode.
  • debugging does not work
    • The file is run, but the setting of breakpoints fails silently. I think this is ok for now... ideally we put up a warning... but that's hard to do from the DebugServer.
  • Expand Alias doesn't work

@TylerLeonhardt TylerLeonhardt force-pushed the add-additional-execution-options branch from e7fdca2 to 16fa1d0 Compare April 22, 2020 18:38
@TylerLeonhardt TylerLeonhardt force-pushed the add-additional-execution-options branch from 16fa1d0 to 3bf1bac Compare April 22, 2020 23:18
@TylerLeonhardt TylerLeonhardt changed the title Use useLocalScope: true or .AddCommand in a few places Support ConstrainedLanguage mode Apr 22, 2020
@TylerLeonhardt TylerLeonhardt marked this pull request as draft April 22, 2020 23:23
@TylerLeonhardt TylerLeonhardt requested a review from rjmholt April 22, 2020 23:27
@TylerLeonhardt
Copy link
Member Author

TylerLeonhardt commented Apr 22, 2020

This is now a "Support ConstrainedLanguage mode" PR... Ultimately:

  • PSRL doesn't work fully
  • Debugging runs the code but breakpoints don't work
    we could say debugging won't be possible and offer the legacy readline...

there's a piece of me that would like to get this out the door to have customers try in (in Preview) and see where we can improve.

@TylerLeonhardt
Copy link
Member Author

It looks like this is by design:

PS C:\Users\tyleonha\Code\PowerShell\Misc> Set-PSBreakpoint -Line 3 -Script .\foo.ps1
Set-PSBreakpoint : Specified method is not supported.
At line:1 char:1
+ Set-PSBreakpoint -Line 3 -Script .\foo.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotImplemented: (:) [Set-PSBreakpoint], PSNotSupportedException
+ FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.SetPSBreakpointCommand

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 🙂 what a wild ride that was eh?

@TylerLeonhardt TylerLeonhardt marked this pull request as ready for review April 23, 2020 19:53
@TylerLeonhardt
Copy link
Member Author

Codacy Here is an overview of what got changed by this pull request:

Complexity increasing per file
==============================
- src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs  2
         

See the complete overview on Codacy

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@TylerLeonhardt TylerLeonhardt merged commit 03bca8d into PowerShell:master Apr 28, 2020
@TylerLeonhardt TylerLeonhardt deleted the add-additional-execution-options branch April 28, 2020 17:14
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.

5 participants