Skip to content

RequestRefactor hotkey throws an InternalError when calling $CommandSuite.RequestRefactor($PSCmdlet) #1959

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
3 tasks done
ninmonkey opened this issue Nov 20, 2022 · 4 comments · Fixed by #1980
Closed
3 tasks done
Assignees
Labels
Area-API Issue-Bug A bug to squash.

Comments

@ninmonkey
Copy link

ninmonkey commented Nov 20, 2022

Theorized Causes?

It seems to always be about a cancellation, and the UI was flickering back and forth.
Could the new quick fix feature be fighting for control with the PSES?

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

Refactor is crashing.

As far as I can tell I can't get more exception information (using powershell)

Location of the exception:

Documents\PowerShell\Modules\EditorServicesCommandSuite\1.0.0\EditorServicesCommandSuite.psm1

$null = $CommandSuite.RequestRefactor($PSCmdlet).
    ConfigureAwait($true).
    GetAwaiter().
    GetResult()

single exception

using a key with nothing bound to it other than this

   {        
        "key": "ctrl+k",
        "when": "editorLangId == 'powershell'",
        "command": "PowerShell.InvokeRegisteredEditorCommand",
        "args": {
            "commandName": "Invoke-DocumentRefactor"
        },
    },
    {
        "key": "ctrl+shift+s",
        "command": "PowerShell.InvokeRegisteredEditorCommand",
        "args": {
            "commandName": "ConvertTo-SplatExpression"
        },
        "when": "editorLangId == 'powershell'"
    },

to reproduce

import-module EditorServicesCommandSuite -Force
Import-CommandSuite
  • hit ctrl+shift+s to splat something ... it works
  • hit ctrl+k to refactor something ... exception

Expected behavior

Show the refactor menu

Actual behavior

The SplatExpression hotkey works
The Refactor one throws.

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     1.0.0      beta4      EditorServicesCommandSuite          {Get-CommandSuiteSetting, New-CommandSuiteSettingF…
Script     0.2.0                 PowerShellEditorServices.Commands   {Clear-Host, ConvertFrom-ScriptExtent, ConvertTo-S…
Binary     0.2.0                 PowerShellEditorServices.VSCode     {Close-VSCodeHtmlContentView, New-VSCodeHtmlConten

Version

[email protected]

Visuals

image

@ghost ghost added the Needs: Triage Maintainer attention needed! label Nov 20, 2022
@SeeminglyScience
Copy link
Collaborator

Thanks Jake! Lookin' into it

@SeeminglyScience
Copy link
Collaborator

Non-ESCS repro:

$eoeType = [Microsoft.PowerShell.EditorServices.Extensions.EditorObjectExtensions, Microsoft.PowerShell.EditorServices]
$pcdType = [Microsoft.PowerShell.EditorServices.Extensions.Services.PromptChoiceDetails, Microsoft.PowerShell.EditorServices]

$task = $eoeType::GetExtensionServiceProvider($psEditor).EditorUI.PromptSelectionAsync(
    'Example message',
    @(
        $pcdType::new('Label 1', 'Greyed out bit I think'),
        $pcdType::new('Label 2', 'woooot')
    ) -as $pcdType.MakeArrayType())

while (-not $task.AsyncWaitHandle.WaitOne(200)) { }
$result = $task.GetAwaiter().GetResult()
$result

@ninmonkey
Copy link
Author

I get the same behavior with v2022.11.1 of ms-vscode.powershell-preview .

  • I made sure quick fix and PowerShell.InvokeRegisteredEditorCommand have totally different hotkeys.
  • I thought maybe refactor and the new quick fix were colliding
  • quick fix works
    image

[Warn  - 10:13:08 PM] OmniSharp.Extensions.LanguageServer.Server.LspServerOutputFilter: Tried to send request or notification before initialization was completed and will be sent later OutgoingNotification { Method = powerShell/extensionCommandAdded, Params = Microsoft.PowerShell.EditorServices.Extensions.ExtensionCommandAddedNotification, TraceParent = , TraceState =  } | @Request='OutgoingNotification { Method = powerShell/extensionCommandAdded, Params = Microsoft.PowerShell.EditorServices.Extensions.ExtensionCommandAddedNotification, TraceParent = , TraceState =  }'
# ... repeats 10 times

[Warn  - 10:13:14 PM] OmniSharp.Extensions.LanguageServer.Server.LspServerOutputFilter: Tried to send request or notification before initialization was completed and will be sent later OutgoingNotification { Method = powerShell/extensionCommandUpdated, Params = Microsoft.PowerShell.EditorServices.Extensions.ExtensionCommandUpdatedNotification, TraceParent = , TraceState =  } | @Request='OutgoingNotification { Method = powerShell/extensionCommandUpdated, Params = Microsoft.PowerShell.EditorServices.Extensions.ExtensionCommandUpdatedNotification, TraceParent = , TraceState =  }'
[Warn  - 10:13:14 PM] OmniSharp.Extensions.LanguageServer.Server.Configuration.DidChangeConfigurationProvider: No ConfigurationItems have been defined, configuration won't surface any configuration from the client! | 
[Warn  - 10:21:02 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Vistors\AstOperations.cs:line 86
   at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 205
   at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 74 | 
[Warn  - 10:21:03 PM] Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Exception occurred while running handling completion request - System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.PowerShell.EditorServices.Services.Symbols.AstOperations.GetCompletionsAsync(Ast scriptAst, Token[] currentTokens, Int32 fileOffset, IInternalPowerShellExecutionService executionService, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\Symbols\Vistors\AstOperations.cs:line 131
   at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.GetCompletionsInFileAsync(ScriptFile scriptFile, Int32 lineNumber, Int32 columnNumber, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 205
   at Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler.Handle(CompletionParams request, CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\TextDocument\Handlers\CompletionHandler.cs:line 74 | 
[Warn  - 10:21:34 PM] Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost: Runtime exception occurred while executing command:

System.Management.Automation.RuntimeException: Exception calling "RequestRefactor" with "1" argument(s): "Internal error. "
 ---> System.Management.Automation.MethodInvocationException: Exception calling "RequestRefactor" with "1" argument(s): "Internal error. "
 ---> OmniSharp.Extensions.JsonRpc.Server.InternalErrorException: Internal error. 
   at OmniSharp.Extensions.JsonRpc.ResponseRouter.ResponseRouterReturnsImpl.Returning[TResponse](CancellationToken cancellationToken)
   at Microsoft.PowerShell.EditorServices.Extensions.Services.EditorUIService.PromptSelectionAsync(String message, IReadOnlyList`1 choices, Int32 defaultChoiceIndex) in D:\a\_work\1\s\src\PowerShellEditorServices\Extensions\Api\EditorUIService.cs:line 163
   at EditorServicesCommandSuite.EditorServices.UIService.ShowChoicePromptAsync[TItem](String caption, String message, TItem[] items, Func`2 labelSelector, Func`2 helpMessageSelector) in D:\a\1\s\src\EditorServicesCommandSuite.EditorServices\UIService.cs:line 97
   at EditorServicesCommandSuite.EditorServices.UIService.ShowChoicePromptAsync[TItem](String caption, String message, TItem[] items, Func`2 labelSelector) in D:\a\1\s\src\EditorServicesCommandSuite.EditorServices\UIService.cs:line 77
   at EditorServicesCommandSuite.Internal.CommandSuite.RequestRefactor(PSCmdlet cmdlet, DocumentContextBase request) in D:\a\1\s\src\EditorServicesCommandSuite\Internal\CommandSuite.cs:line 163
   at EditorServicesCommandSuite.Internal.CommandSuite.<>c__DisplayClass30_0.<<RequestRefactor>b__0>d.MoveNext() in D:\a\1\s\src\EditorServicesCommandSuite\Internal\CommandSuite.cs:line 127
--- End of stack trace from previous location ---
   at EditorServicesCommandSuite.Utility.ThreadController.GiveControl(Task requestTask, CancellationToken cancellationToken) in D:\a\1\s\src\EditorServicesCommandSuite\Utility\ThreadController.cs:line 55
   at EditorServicesCommandSuite.Internal.CommandSuite.RequestRefactor(PSCmdlet cmdlet) in D:\a\1\s\src\EditorServicesCommandSuite\Internal\CommandSuite.cs:line 136
   at CallSite.Target(Closure, CallSite, Object, PSScriptCmdlet)
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, PSInvocationSettings settings)
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear[TResult](PowerShell pwsh, PSInvocationSettings invocationSettings) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 82
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask`1.ExecuteNormally(CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousPowerShellTask.cs:line 187 | 
[Warn  - 10:23:22 PM] Microsoft.PowerShell.EditorServices.Services.PowerShell.Host.PsesInternalHost: Runtime exception occurred while executing command:

System.Management.Automation.RuntimeException: Exception calling "RequestRefactor" with "1" argument(s): "Internal error. "
 ---> System.Management.Automation.MethodInvocationException: Exception calling "RequestRefactor" with "1" argument(s): "Internal error. "
 ---> OmniSharp.Extensions.JsonRpc.Server.InternalErrorException: Internal error. 
   at OmniSharp.Extensions.JsonRpc.ResponseRouter.ResponseRouterReturnsImpl.Returning[TResponse](CancellationToken cancellationToken)
   at Microsoft.PowerShell.EditorServices.Extensions.Services.EditorUIService.PromptSelectionAsync(String message, IReadOnlyList`1 choices, Int32 defaultChoiceIndex) in D:\a\_work\1\s\src\PowerShellEditorServices\Extensions\Api\EditorUIService.cs:line 163
   at EditorServicesCommandSuite.EditorServices.UIService.ShowChoicePromptAsync[TItem](String caption, String message, TItem[] items, Func`2 labelSelector, Func`2 helpMessageSelector) in D:\a\1\s\src\EditorServicesCommandSuite.EditorServices\UIService.cs:line 97
   at EditorServicesCommandSuite.EditorServices.UIService.ShowChoicePromptAsync[TItem](String caption, String message, TItem[] items, Func`2 labelSelector) in D:\a\1\s\src\EditorServicesCommandSuite.EditorServices\UIService.cs:line 77
   at EditorServicesCommandSuite.Internal.CommandSuite.RequestRefactor(PSCmdlet cmdlet, DocumentContextBase request) in D:\a\1\s\src\EditorServicesCommandSuite\Internal\CommandSuite.cs:line 163
   at EditorServicesCommandSuite.Internal.CommandSuite.<>c__DisplayClass30_0.<<RequestRefactor>b__0>d.MoveNext() in D:\a\1\s\src\EditorServicesCommandSuite\Internal\CommandSuite.cs:line 127
--- End of stack trace from previous location ---
   at EditorServicesCommandSuite.Utility.ThreadController.GiveControl(Task requestTask, CancellationToken cancellationToken) in D:\a\1\s\src\EditorServicesCommandSuite\Utility\ThreadController.cs:line 55
   at EditorServicesCommandSuite.Internal.CommandSuite.RequestRefactor(PSCmdlet cmdlet) in D:\a\1\s\src\EditorServicesCommandSuite\Internal\CommandSuite.cs:line 136
   at CallSite.Target(Closure, CallSite, Object, PSScriptCmdlet)
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, PSInvocationSettings settings)
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear[TResult](PowerShell pwsh, PSInvocationSettings invocationSettings) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 82
   at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPowerShellTask`1.ExecuteNormally(CancellationToken cancellationToken) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Execution\SynchronousPowerShellTask.cs:line 187 | 

@SeeminglyScience
Copy link
Collaborator

Nah nothing like that, it's just the ShowChoicePromptAsync public API that is broken. Still workin' on it.

@SeeminglyScience SeeminglyScience self-assigned this Dec 28, 2022
SeeminglyScience added a commit to SeeminglyScience/PowerShellEditorServices that referenced this issue Dec 28, 2022
Fixes PowerShell#1959

The code on the client expects DefaultChoices to never be `null`. If you
send `null`, it tries to access the property `length` on what would be
an array.
@andyleejordan andyleejordan added Issue-Bug A bug to squash. Area-API and removed Needs: Triage Maintainer attention needed! labels Jan 3, 2023
andyleejordan pushed a commit that referenced this issue Jan 3, 2023
Fixes #1959

The code on the client expects DefaultChoices to never be `null`. If you
send `null`, it tries to access the property `length` on what would be
an array.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-API Issue-Bug A bug to squash.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants