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

Move PSReadLine logic to cmdlets #1255

Merged

Conversation

TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Apr 9, 2020

fixes PowerShell/vscode-powershell#2623

This should enable the ability to start up with ConstrainedLanguage mode (though I didn't remove the check because I wasn't sure if I could set it on non-Windows). There are features that won't work though - expand alias, remoting, Command explorer, etc.

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.

Great idea! Couple requests

/// The Start-EditorServices command, the conventional entrypoint for PowerShell Editor Services.
/// </summary>
[Cmdlet("__Invoke", "ReadLineForEditorServices")]
public sealed class InvokeReadLineForEditorServicesCommand : PSCmdlet
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can drop the Cmdlet decoration and make this internal. When you go to invoke it, use:

ps.AddCommand(
    new CmdletInfo(
        "any-hyphenseparatedname",
        typeof(InvokeReadLineForEditorServicesCommand)))

(and probably staticly store the CmdletInfo)

Edit: hmm I guess the direct CommandInfo route isn't accessible from PSCommand directly for some reason. Either PSCommand.AddCommand needs an overload for CommandInfo, or the Runspaces.Command ctor that takes it needs to be made public.

I'd honestly still recommend going this route, and use reflection to access the Command.ctor(CommandInfo) overload. Then add an internal extension method PSCommand.AddCommand(CommandInfo) so we can use this as necessary.

I really dislike adding global state, though I understand if other folks aren't against it enough to think this approach is warranted.

Copy link
Member Author

@TylerLeonhardt TylerLeonhardt Apr 9, 2020

Choose a reason for hiding this comment

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

I'm going to pass on this one for now...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I don't think I explained that well. That part in particular should be pretty easy, this is what I mean:

internal static PSCommand AddCommand(this PSCommand command, CommandInfo commandInfo)
{
    var rsCommand = (Command)typeof(Command)
        .GetConstructor(
            BindingFlags.Instance | BindingFlags.NonPublic,
            binder: null,
            new[] { typeof(CommandInfo) },
            modifiers: null)
        .Invoke(new object[] { commandInfo });

    return command.AddCommand(rsCommand);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually can't do this without breaking the contract between the PSES.Host proj and PSES proj.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess I can put the command in PSES...

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually then that loads it in a different ALC... ok there's a bit too much going on here. I'm gonna defer this.

@TylerLeonhardt
Copy link
Member Author

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

Issues
======
- Added 1
           

Complexity increasing per file
==============================
- src/PowerShellEditorServices.Hosting/Commands/InvokeReadLineConstructorCommand.cs  1
- src/PowerShellEditorServices.Hosting/Commands/InvokeReadLineForEditorServicesCommand.cs  1
         

See the complete overview on Codacy


// TODO: Handle method being null here. This shouldn't ever happen.

return (ReadLineInvoker)method.CreateDelegate(typeof(ReadLineInvoker));
Copy link
Member Author

Choose a reason for hiding this comment

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

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.

PSReadLine cannot be started Preview extension MacOS
3 participants