Search code examples
powershell

In VSCode how to get intellisense working for PowerShell?


When developing in Powershell with .NET objects, I can't get the documentation from MSDN shown when hovering over a function, for example in this case I'd like to see all the params the func AuthenticateAsClient accepts, with info for each one: AuthAsClientCode

expected result:

something like IDEExample or IDEExample1

how can i get it working auto instead of manually browsing to the msdn docs every time?

I tried the official powershell extension in vscode per microsoft guielines.

this is what i get, a numb popup: IDESadness


Solution

  • As of v2024.0.0 of the PowerShell extension for Visual Studio Code:

    IntelliSense support for calling .NET methods is limited to:

    • read-only display of all overloads that is only shown while the method name is being type; once you tab-complete or start typing arguments, the display goes away.

      • To show the overloads again on demand, place the cursor before the opening ( and press Ctrl+Space
    • showing the method signatures only, i.e. the parameter names and types- no description of the method or its parameters is shown.

    In other words, there is currently no support for:

    • (a) showing an overload signature (parameter names) as arguments are being typed.

    • (b) allowing selecting one of the overloads so as to auto-complete a call to that overload with argument placeholders named for the parameters.

    • (c) showing concise method descriptions from the online documentation of built-in .NET types

    GitHub issue #1356 discusses potentially improving method-call IntelliSense in the future, but there are implementation challenges:

    • (a) is problematic, given PowerShell's lack of static typing, though it's conceivable to let the user manually cycle through available overloads in the same way that the C# extension does, albeit without type awareness.

    • (b) may be feasible, if the IntelliSense feature allows calling a Visual Studio Code snippet in response to a user selection.


    It is important to note that direct use of .NET APIs is an advanced use case in PowerShell; fortunately, support for PowerShell-native commands an operator is better:

    IntelliSense support for calling PowerShell-native commands:

    • Display of the syntax diagram(s) of a command being typed (parameter names, along with its synopsis (the concise description shown in the SYNOPSIS section of Get-Help's output):

      • You may have to click on the > at the right edge of the relevant line of the IntelliSense pop-up in order to show an additional panel with the syntax diagrams and the description.

      • As of v2024.0.0, there are the following limitations for commands implemented as script files (*.ps1), reported in GitHub issue #4904:

        • Their synopsis is not shown, because their comment-based help is seemingly not consulted.

        • The formatting of their syntax diagrams is broken: they individual diagrams aren't separated with empty lines and instead form one long string without line breaks, resulting in arbitrary line wrapping.

    • Completion of individual parameters, along with displaying their data type.

      • Limitation: Parameter descriptions aren't shown.
    • Once a command name has been completed or typed in full, you can invoke its online help in the default web browser, assuming the given command has a help URL associated with it, by default via Ctrl+F1