Skip to content

deactivate() fails to execute #3586

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
4 tasks done
CrendKing opened this issue Sep 24, 2021 · 3 comments · Fixed by #3592
Closed
4 tasks done

deactivate() fails to execute #3586

CrendKing opened this issue Sep 24, 2021 · 3 comments · Fixed by #3592
Labels
Issue-Bug A bug to squash. Resolution-Fixed Will close automatically. Up for Grabs Will shepherd PRs.

Comments

@CrendKing
Copy link
Contributor

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

In the exported deactivate() function, it first calls to all languageClientConsumers' dispose(). I noticed that two of them are throwing error, and preventing the rest of the deactivate() logic from running (e.g. the session manager's stop() is never run).

The two offenders are ShowHelp and DebugSession. The common reason of their failure is that, in the ts file a command variable is declared but never assigned. When the ts is compiled to js file, these variables got omitted. Therefore, when the consumer's dispose() tries to dispose these command variables, variable can't be found.

For example, ShowHelpFeature has a deprecatedCommand. It is accessed here. Here is the relevant part of the js file from vsix:

...
    constructor(log) {
        super();
        this.log = log;
        this.command = vscode.commands.registerCommand("PowerShell.ShowHelp", (item) => {
            if (!item || !item.Name) {
...
    }
    dispose() {
        this.command.dispose();
        this.deprecatedCommand.dispose();
    }
}

The one from DebugSession is this one.

If I comment out the dispose() calls in the installed js file, I can verify from log file that things are back to work (these two lines are currently missing):

9/24/2021 6:49:23 AM [NORMAL] - Shutting down language client...
9/24/2021 6:49:23 AM [NORMAL] - Terminating PowerShell process...

PowerShell Version

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

Visual Studio Code Version

1.60.2
7f6ab5485bbc008386c4386d08766667e155244e
x64

Extension Version

Steps to Reproduce

  • Install the extension
  • Open an ps1 file, wait for a few seconds
  • Close VSCode
  • Look at the log file

Visuals

No response

Logs

Current:

9/24/2021 6:54:35 AM [NORMAL] - Language server starting --
9/24/2021 6:54:35 AM [NORMAL] -     PowerShell executable: <redacted>\pwsh\current\pwsh.exe
9/24/2021 6:54:35 AM [NORMAL] - pwsh.exe started.
9/24/2021 6:54:35 AM [NORMAL] - Waiting for session file
9/24/2021 6:54:35 AM [NORMAL] -     PowerShell Editor Services args: Import-Module '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2021.9.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\modules' -EnableConsoleRepl -StartupBanner '' -LogLevel 'Normal' -LogPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\logs\1632491675-0e14938c-3cc1-4020-b3c2-a6bc8bac2b1a1632491673928\EditorServices.log' -SessionDetailsPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\sessions\PSES-VSCode-10176-190235' -FeatureFlags @() 
9/24/2021 6:54:35 AM [NORMAL] -     PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2021.9.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\modules' -EnableConsoleRepl -StartupBanner '' -LogLevel 'Normal' -LogPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\logs\1632491675-0e14938c-3cc1-4020-b3c2-a6bc8bac2b1a1632491673928\EditorServices.log' -SessionDetailsPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\sessions\PSES-VSCode-10176-190235' -FeatureFlags @() 
9/24/2021 6:54:37 AM [NORMAL] - Session file found
9/24/2021 6:54:37 AM [NORMAL] - Registering terminal close callback
9/24/2021 6:54:37 AM [NORMAL] - Registering terminal PID log callback
9/24/2021 6:54:37 AM [NORMAL] - pwsh.exe PID: 14764
9/24/2021 6:54:37 AM [NORMAL] - {"status":"started","languageServiceTransport":"NamedPipe","languageServicePipeName":"\\\\.\\pipe\\PSES_40lewdxk.4yb","debugServiceTransport":"NamedPipe","debugServicePipeName":"\\\\.\\pipe\\PSES_kabzcodf.m3n"}
9/24/2021 6:54:37 AM [NORMAL] - Language server started.
9/24/2021 6:54:37 AM [NORMAL] - Language service connected.
9/24/2021 6:54:37 AM [NORMAL] - Connecting to language service on pipe \\.\pipe\PSES_40lewdxk.4yb...

After my local fix:

9/24/2021 6:55:42 AM [NORMAL] - Language server starting --
9/24/2021 6:55:42 AM [NORMAL] -     PowerShell executable: <redacted>\pwsh\current\pwsh.exe
9/24/2021 6:55:42 AM [NORMAL] - pwsh.exe started.
9/24/2021 6:55:42 AM [NORMAL] - Waiting for session file
9/24/2021 6:55:42 AM [NORMAL] -     PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2021.9.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\modules' -EnableConsoleRepl -StartupBanner '' -LogLevel 'Normal' -LogPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\logs\1632491742-bbb95136-8abe-4aa3-9b77-77978365b52e1632491741204\EditorServices.log' -SessionDetailsPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\sessions\PSES-VSCode-3188-935947' -FeatureFlags @() 
9/24/2021 6:55:42 AM [NORMAL] -     PowerShell Editor Services args: Import-Module '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2021.9.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\modules' -EnableConsoleRepl -StartupBanner '' -LogLevel 'Normal' -LogPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\logs\1632491742-bbb95136-8abe-4aa3-9b77-77978365b52e1632491741204\EditorServices.log' -SessionDetailsPath '<redacted>\vscode\data\extensions\ms-vscode.powershell-2021.9.0\sessions\PSES-VSCode-3188-935947' -FeatureFlags @() 
9/24/2021 6:55:44 AM [NORMAL] - Session file found
9/24/2021 6:55:44 AM [NORMAL] - Registering terminal close callback
9/24/2021 6:55:44 AM [NORMAL] - Registering terminal PID log callback
9/24/2021 6:55:44 AM [NORMAL] - Language server started.
9/24/2021 6:55:44 AM [NORMAL] - {"status":"started","languageServiceTransport":"NamedPipe","languageServicePipeName":"\\\\.\\pipe\\PSES_x0artraj.suh","debugServiceTransport":"NamedPipe","debugServicePipeName":"\\\\.\\pipe\\PSES_huxxuiys.jgi"}
9/24/2021 6:55:44 AM [NORMAL] - Connecting to language service on pipe \\.\pipe\PSES_x0artraj.suh...
9/24/2021 6:55:44 AM [NORMAL] - pwsh.exe PID: 14076
9/24/2021 6:55:44 AM [NORMAL] - Language service connected.
9/24/2021 6:55:45 AM [NORMAL] - Shutting down language client...
9/24/2021 6:55:45 AM [NORMAL] - Terminating PowerShell process...
@CrendKing CrendKing added the Issue-Bug A bug to squash. label Sep 24, 2021
@ghost ghost added the Needs: Triage Maintainer attention needed! label Sep 24, 2021
@andyleejordan
Copy link
Member

Oh interesting! @CrendKing would you open a PR with your fix? I'll happily take it.

@andyleejordan andyleejordan added Up for Grabs Will shepherd PRs. and removed Needs: Triage Maintainer attention needed! labels Sep 28, 2021
@andyleejordan andyleejordan added this to the Committed-vNext milestone Sep 28, 2021
@CrendKing
Copy link
Contributor Author

@andschwa PR is #3592

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Sep 28, 2021
@andyleejordan andyleejordan removed the Needs: Maintainer Attention Maintainer attention needed! label Sep 29, 2021
@andyleejordan andyleejordan linked a pull request Sep 29, 2021 that will close this issue
3 tasks
@andyleejordan andyleejordan added the Resolution-Fixed Will close automatically. label Sep 29, 2021
@ghost ghost closed this as completed Sep 29, 2021
@ghost
Copy link

ghost commented Sep 29, 2021

This issue has been marked as fixed. It has been automatically closed for housekeeping purposes.

This issue was closed.
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. Resolution-Fixed Will close automatically. Up for Grabs Will shepherd PRs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants