Skip to content

Ctrl-space results in writing a character #4939

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

Closed
5 of 6 tasks
cveld opened this issue Mar 5, 2024 · 17 comments
Closed
5 of 6 tasks

Ctrl-space results in writing a character #4939

cveld opened this issue Mar 5, 2024 · 17 comments
Assignees
Labels
Issue-Bug A bug to squash. Needs: Fix Verification Please verify the fix for us! Resolution-Fixed Will close automatically.

Comments

@cveld
Copy link

cveld commented Mar 5, 2024

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

After having run at least one command, ctrl-space starts resulting in writing the a character.

PowerShell Version

$PSVersionTable; $host

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2024.0.0
InstanceId       : d6120c4f-e131-4116-8466-5b2ead5f2d8c
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : nl-NL
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

code --version
1.87.2
863d2581ecda6849923a2118d93a088b0745d9d6
x64

Extension Version

code --list-extensions --show-versions | Select-String powershell

[email protected]

Steps to Reproduce

  1. Start an integrated shell.
  2. Run a random command, e.g. dir
  3. Start pressing ctrl-space. Every ctrl-space results in a a

Visuals

image

Logs

No response

@cveld cveld added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Mar 5, 2024
@andyleejordan
Copy link
Member

Hi, can you please file a bug upstream with VS Code? The value of your $host indicates this is happening in a regular VS Code integrated terminal running PowerShell, not (just) in the unique PowerShell Extension Terminal. Thanks!

@andyleejordan andyleejordan added the Resolution-External Will close automatically. label Mar 5, 2024
Copy link
Contributor

github-actions bot commented Mar 5, 2024

This issue has been labeled as resolved, please verify the provided fix (or other reason).

@github-actions github-actions bot added Needs: Fix Verification Please verify the fix for us! and removed Needs: Triage Maintainer attention needed! labels Mar 5, 2024
@cveld
Copy link
Author

cveld commented Mar 5, 2024

@andyleejordan
I have created a new ticket from within vscode: #4940
Why is #4939 marked as resolved?

But I think I read your comment wrong. The issue does not happen with the regular PowerShell terminal. Only with the extension integrated terminal.
I will update the description text. I erroneously run the command from the wrong prompt.

@github-actions github-actions bot removed the Needs: Fix Verification Please verify the fix for us! label Mar 5, 2024
Copy link
Contributor

github-actions bot commented Mar 5, 2024

This issue has been labeled as resolved, please verify the provided fix (or other reason).

@github-actions github-actions bot added the Needs: Fix Verification Please verify the fix for us! label Mar 5, 2024
@andyleejordan andyleejordan added Needs: Triage Maintainer attention needed! and removed Needs: Fix Verification Please verify the fix for us! Resolution-External Will close automatically. labels Mar 5, 2024
@andyleejordan
Copy link
Member

Thanks for confirming the terminal. In that case we'll get this triaged.

@cveld
Copy link
Author

cveld commented Mar 27, 2024

@andyleejordan any update? the issue is still present.

@cveld
Copy link
Author

cveld commented Mar 27, 2024

I found this line in Microsoft.PowerShell_profile.ps1; which I assume is not directly related to the integrated shell but with the regular shell which does not have the issue:

if ($env:TERM_PROGRAM -eq "vscode") { . "$(code --locate-shell-integration-path pwsh)" }

Path:
C:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\contrib\terminal\browser\media\shellIntegration.ps1

It contains this exciting piece of code:

function Send-Completions {
        $commandLine = ""
        $cursorIndex = 0
        # TODO: Since fuzzy matching exists, should completions be provided only for character after the
        #       last space and then filter on the client side? That would let you trigger ctrl+space
        #       anywhere on a word and have full completions available
        [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$commandLine, [ref]$cursorIndex)
        $completionPrefix = $commandLine

        # Get completions
        $result = "`e]633;Completions"
        if ($completionPrefix.Length -gt 0) {
                # Get and send completions
                $completions = TabExpansion2 -inputScript $completionPrefix -cursorColumn $cursorIndex
                if ($null -ne $completions.CompletionMatches) {
                        $result += ";$($completions.ReplacementIndex);$($completions.ReplacementLength);$($cursorIndex);"
                        $result += $completions.CompletionMatches | ConvertTo-Json -Compress
                }
        }
        $result += "`a"

        Write-Host -NoNewLine $result
}

Do you see the $result += "\`a" ?

I am on to something.........

@andyleejordan
Copy link
Member

So...we don't add anything to Microsoft.PowerShell_profile.ps1. That's certainly the name of the VS Code-specific profile which we'll load if present. The shell integration script is automatically loaded in the extension's host (and can be turned off). You're right, I think this is the culprit because the contents of your profile are causing the integration to get setup twice, which I think would result in what you're seeing. Perhaps you added that to the profile once-upon-a-time to manually enable shell integrations. Try removing it!

@cveld
Copy link
Author

cveld commented Mar 27, 2024

I ran vscode / PowerShell extension with a clean Microsoft.PowerShell_profile.ps1 and C:\Users\username\Documents\PowerShell\Microsoft.VSCode_profile.ps1 but the issue is still there.
I assume only the latter plays a role in the extension's shell.

@cveld
Copy link
Author

cveld commented Apr 2, 2024

@andyleejordan ctrl+space matches with

{ "key": "ctrl+space",            "command": "workbench.action.terminal.sendSequence",
                                     "when": "terminalFocus && terminalShellIntegrationEnabled && !accessibilityModeEnabled && terminalShellType == 'pwsh'",
                                     "args": {"text":"\u001b[24~a"} },

Based on this log record from the shortcut key diagnostics:

INFO [KeybindingService]: \ From 5 keybinding entries, matched workbench.action.terminal.sendSequence, when: terminalFocus && terminalShellIntegrationEnabled && !accessibilityModeEnabled && terminalShellType == 'pwsh', source: built-in.

and this yields the a character.

On Discord (PowerShell/#vscode) there is this helpful user @ninmonkey which shared his shortcut key diagnostics. At his/her side ctrl+space does not match any when clause ("no when clauses matches the context").

@andyleejordan
Copy link
Member

Did you try disabling terminalShellIntegrationEnabled?

@cveld
Copy link
Author

cveld commented Apr 3, 2024

I added "terminal.integrated.shellIntegration.enabled": false and that works. Also disabling the key binding works:

 {
        "key": "ctrl+space",
        "command": "-workbench.action.terminal.sendSequence",
        "when": "terminalFocus && terminalShellIntegrationEnabled && !accessibilityModeEnabled && terminalShellType == 'pwsh'"
    }

But it sounds illogical that shell integration should be disabled?

@andyleejordan
Copy link
Member

It sounds like there's a mismatch between Code's keybinding and the extension terminal's shell integration logic which is supposed to interpret it into something other than writing a character. I'm updating the extension terminal to use VS Code's shell integration script directly: PowerShell/PowerShellEditorServices#2156

@andyleejordan
Copy link
Member

@cveld can you test the latest pre-release, v2024.3.2-preview and let me know if it still happens?

@cveld
Copy link
Author

cveld commented Apr 11, 2024

I believe the issue went away with vscode 1.88.1 and PowerShell extension 2024.2 🥳

@andyleejordan andyleejordan added Resolution-Fixed Will close automatically. and removed Needs: Triage Maintainer attention needed! labels Apr 15, 2024
@andyleejordan andyleejordan self-assigned this Apr 15, 2024
@andyleejordan andyleejordan moved this to Done in Flying Fox Apr 15, 2024
Copy link
Contributor

This issue has been labeled as resolved, please verify the provided fix (or other reason).

@github-actions github-actions bot added the Needs: Fix Verification Please verify the fix for us! label Apr 15, 2024
Copy link
Contributor

This issue has been labeled as needing fix verification and has not had any activity a week. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash. Needs: Fix Verification Please verify the fix for us! Resolution-Fixed Will close automatically.
Projects
Status: Done
Development

No branches or pull requests

2 participants