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

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

Open
DarkLite1 opened this issue Aug 2, 2019 · 10 comments
Open
Labels

Comments

@DarkLite1
Copy link

DarkLite1 commented Aug 2, 2019

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.

  • When using intellisense in the editor pane it keeps on loading and nothing is suggested for the second/last dynamic parameter (in this example -Type)

image

  • Observe that the same function with intellisense works fine in the Terminal or in the editor of the PowerShell ISE.

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.

@ghost ghost added the Needs: Triage Maintainer attention needed! label Aug 2, 2019
@rjmholt
Copy link
Collaborator

rjmholt commented Aug 6, 2019

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

@SydneyhSmith
Copy link
Collaborator

@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"

@SydneyhSmith SydneyhSmith added Needs-Repro-Info and removed Needs: Triage Maintainer attention needed! labels Aug 6, 2019
@DarkLite1
Copy link
Author

@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

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Aug 7, 2019
@DarkLite1
Copy link
Author

DarkLite1 commented Aug 7, 2019

@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
Copy link
Author

DarkLite1 commented Aug 7, 2019

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
Copy link
Author

DarkLite1 commented Aug 7, 2019

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
Copy link
Collaborator

rjmholt commented Aug 8, 2019

@DarkLite1 based on your response, I suspect you're hitting PowerShell/PowerShellEditorServices#762 (comment). @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
Copy link
Collaborator

@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
Copy link

ghost commented Aug 15, 2019

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

@ghost ghost added the Resolution-Inactive Will close automatically. label Aug 15, 2019
@ghost ghost closed this as completed Aug 15, 2019
@TylerLeonhardt
Copy link
Member

Bot is trigger happy...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants