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

Use a provided shell integration script directly #2156

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

andyleejordan
Copy link
Member

@andyleejordan andyleejordan commented Apr 2, 2024

Instead of having to maintain an edited copy (which was really annoying) I stubbed out PSConsoleHostReadLine to do what's expected. So now we can just use the existing shell integration script directly!

Since we can't reliably find the script using code --locate-shell-integration-path pwsh we now rely on it being sent by the client on initialization. Its presence implies the feature is on.

This is pretty VS Code specific, but not necessarily so.

@andyleejordan andyleejordan added the Issue-Enhancement A feature request (enhancement). label Apr 2, 2024
@andyleejordan andyleejordan requested a review from a team April 2, 2024 20:11
@andyleejordan
Copy link
Member Author

This was prompted by a) being annoyed at having to keep doing this and b) the changes in microsoft/vscode@d60e424 being much more difficult to incorporate except by doing it this way! /cc @Tyriar

_shellIntegrationEnabled = true;
await EnableShellIntegrationAsync(cancellationToken).ConfigureAwait(false);
// TODO: Make the __psEditorServices prefix shared (it's used elsewhere too).
string setupShellIntegration = $$"""
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 like C# 11's triple-quote double-dollar thing. Very useful.

@andyleejordan andyleejordan force-pushed the shell-integration branch 2 times, most recently from da3894a to 400dce5 Compare April 3, 2024 18:20
@andyleejordan andyleejordan changed the title Use VS Code's built-in shell integration script Use a provided shell integration script directly Apr 3, 2024
Comment on lines +1092 to +1098
// Invoke the PSConsoleHostReadLine wrapper. We don't write the output because it
// returns the command line (user input) which would then be duplicate noise. Fortunately
// it writes the shell integration sequences directly using [Console]::Write.
InvokePSCommand(
new PSCommand().AddScript("PSConsoleHostReadLine"),
new PowerShellExecutionOptions { ThrowOnError = false, WriteOutputToHost = false },
cancellationToken);
Copy link
Member Author

Choose a reason for hiding this comment

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

@Tyriar just a heads-up here that your PSConsoleHostReadLine wrapper must continue to write those escape sequences directly, as we're intentionally not emitting the output (like the returned value) to the host. Write-Host might work (though you don't use it), but we'd need to test.

}

InvokePSCommand(
new PSCommand().AddScript(input, useLocalScope: false),
Copy link
Member Author

Choose a reason for hiding this comment

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

No real change, it's the default.

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.

Lookin' good, just two fixes real quick

@andyleejordan andyleejordan disabled auto-merge April 3, 2024 19:55
Instead of having to maintain an edited copy (which was really annoying)
I stubbed out `PSConsoleHostReadLine` to do what's expected.
So now we can just use the existing shell integration script directly!

Since we can't reliably find the script using
`code --locate-shell-integration-path pwsh` we now rely on it being sent
by the client on initialization. Its presence implies the feature is on.

This is pretty VS Code specific, but not necessarily so.

Apply suggestions from code review

Thanks Patrick!

Co-authored-by: Patrick Meinecke <SeeminglyScience@users.noreply.github.com>
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!

@andyleejordan andyleejordan enabled auto-merge April 3, 2024 20:26
@andyleejordan andyleejordan added this pull request to the merge queue Apr 3, 2024
Merged via the queue into main with commit 5b30599 Apr 3, 2024
8 checks passed
@andyleejordan andyleejordan deleted the shell-integration branch April 3, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement A feature request (enhancement).
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants