PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.71k stars 488 forks source link

Intellisense not working when more than one DynamicParameter is used #2117

Open DarkLite1 opened 5 years ago

DarkLite1 commented 5 years ago

Version: 1.37.0-insider (user setup) Commit: 92da68a71cfb60bd3b9b0d7fbfb2a7e1fff9dbaf Date: 2019-08-01T05:37:54.848Z Electron: 4.2.7 Chrome: 69.0.3497.128 Node.js: 10.11.0 V8: 6.9.427.31-electron.0 OS: Windows_NT x64 6.2.9200

Steps to Reproduce:

Consider the following example function:

Function Test-Stuff {
    Param (
        [Parameter(Mandatory, ValueFromPipeline)]
        [Object[]]$Ticket,
        [Switch]$PassThru
    )
    DynamicParam {
        $DynamicParameters = @(
            @{
                Name        = 'Environment'
                Type        = [Array]
                Position    = 0
                Mandatory   = $true
                ValidateSet = @('Test', 'Prod', 'Stage', 'Dev')
            }
            ,
            @{
                Name        = 'Type'
                Type        = [Array]
                Position    = 0
                Mandatory   = $true
                ValidateSet = @('Incident', 'Request', 'Project')
            }
        )
        $DynamicParameters | ForEach-Object { New-Object PSObject -Property $_ } | New-DynamicParameter
    }
    Begin {
        New-DynamicParameter -CreateVariables -BoundParameters $PSBoundParameters
    }
    Process {
        'yes'
    }
}

The function `New-DynamicParamter' can be downloaded here.

image

image

I was going nuts about this, because I thought my code was broken. Seems after a bit of stressing it's a bug in the editor pane. Thank you for looking at this.

rjmholt commented 5 years ago

@DarkLite1 do other IDE features continue to work after you hit this? e.g. do you continue to get completions for other things?

SydneyhSmith commented 5 years ago

@DarkLite1 thanks for reporting this...interestingly the editor and terminal are using the same API so it could be a performance reason as to why the parameters are not loading It would be really helpful if you could also attach the logs--instructions for how to do that are here and please use diagnostic logging "powershell.developer.editorServicesLogLevel": "Diagnostic"

DarkLite1 commented 5 years ago

@rjmholt when this happens and I try another function to complete in the editor pane, like type Get-Pr hit CTRL+I and expect it to complete to Get-Process, it wont work anymore. When intellisense is invoked it keeps showing the text Loading... but nothing happens. image

DarkLite1 commented 5 years ago

@SydneyhSmith you can find the logs here: logs.zip

Notice that on the first try the function executed intellisense correctly, the second time I tried it it kept showing the text Loading... and nothing happened.

DarkLite1 commented 5 years ago

This is strange... When I try it manually it works fine, like this:

Function Test-Stuff {
    Param (
        [Parameter(Mandatory, ValueFromPipeline)]
        [Object[]]$Ticket,
        [Switch]$PassThru
    )
    DynamicParam {
        $EnvCustomAttribute = New-Object System.Management.Automation.ParameterAttribute
        $EnvCustomAttribute.Position = 0
        $EnvCustomAttribute.Mandatory = $true
        $EnvAttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
        $EnvAttributeCollection.Add($EnvCustomAttribute)
        $EnvAttribValidateSet = New-Object System.Management.Automation.ValidateSetAttribute(@('Test', 'Prod', 'Stage', 'Dev'))
        $EnvAttributeCollection.Add($EnvAttribValidateSet)
        $EnvEnvironmentParam = New-Object System.Management.Automation.RuntimeDefinedParameter(
            'Environment', [String], $EnvAttributeCollection)

        $TypeCustomAttribute = New-Object System.Management.Automation.ParameterAttribute
        $TypeCustomAttribute.Position = 0
        $TypeCustomAttribute.Mandatory = $true
        $TypeAttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
        $TypeAttributeCollection.Add($TypeCustomAttribute)
        $TypeAttribValidateSet = New-Object System.Management.Automation.ValidateSetAttribute(@('Incident', 'Request', 'Project'))
        $TypeAttributeCollection.Add($TypeAttribValidateSet)
        $TypeEnvironmentParam = New-Object System.Management.Automation.RuntimeDefinedParameter(
            'Type', [String], $TypeAttributeCollection)

        $ParamDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $ParamDictionary.Add('Environment', $EnvEnvironmentParam)
        $ParamDictionary.Add('Type', $TypeEnvironmentParam)
        $ParamDictionary
    }

    Process {
        'yes'
    }
}

But when I use the example code from my first post with DynamicParams created by the function it doesn't work as desired in vscode, but it does in PowerShell ISE: image

So somewhere there's a difference in the dynamic parameters that make intellisense crash.

DarkLite1 commented 5 years ago

I made an export of both dynamic parameters, one that is generated by the function and one that is made manually. This will allow someone with more knowledge to see what the difference in them is and why intellisense doesn't work in vscode but does in the PowerShell ISE for the dynamic parameters generated by the function.

DynamicParams.zip

rjmholt commented 5 years ago

@DarkLite1 based on your response, I suspect you're hitting https://github.com/PowerShell/PowerShellEditorServices/issues/762#issuecomment-428756484. @SeeminglyScience might have some insight there.

This is something we don't have much control over; the fix lies in PackageManagement, but we're investigating how to fix it since it also affects PSScriptAnalyzer

SeeminglyScience commented 5 years ago

@DarkLite1 based on your response, I suspect you're hitting PowerShell/PowerShellEditorServices#762 (comment). @SeeminglyScience might have some insight there.

Yeah the OP doesn't hang for me, so there's a good chance it's related.

ghost commented 5 years ago

This issue is being closed as inactive, if this issue is still occurring it will be re-opened

TylerLeonhardt commented 5 years ago

Bot is trigger happy...