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

Comment Based Help Keywords and Their Parameters Not Highlighting Correctly #194

Open
RobertKlohr opened this issue Jan 26, 2020 · 2 comments

Comments

@RobertKlohr
Copy link

RobertKlohr commented Jan 26, 2020

Environment

  • Editor and Version (VS Code, Atom, Sublime): VS Code 1.41.1
  • OS: Windows 10
  • PowerShell: 5.1
  • Theme: Dark+

I tested the code snippet below with all extensions disabled using both the stable and preview versions of the PowerShell extension. In all cases the behavior was the same.

Issue Description

The following keywords and their parameters used in the Comment-Based-Help section of
a script or module not highlight correctly when compared to the other keywords that do not take parameters nor consistently when compared the .PARAMETER keyword.

.LINK
.FORWARDHELPTARGETNAME
.FORWARDHELPCATEGORY
.REMOTEHELPRUNSPACE
.EXTERNALHELP

The one keyword that does seem to at least partially work is the .PARAMETER keyword. It only highlights as a keyword if it has the required parameters and both the keyword and parameters highlight as the same type of syntax. (same color)

I was able to manually edit the powershell.tmLanguage.json file to get the highlighting to work but adjusting the moving all the keywords to the second "captures" under "commentEmbeddedDocs" and making some edits to the regex statement to include characters needed to create URI patterns.

When working against my local files I also created a new third "captures" group and moved the .FORWARDHELPCATEGORY to that group and added the regex to test for the list of valid categories that the keyword would take: (Alias|Cmdlet|HelpFile|Function|Provider|General|FAQ|Glossary|ScriptCommand|ExternalScript|Filter|All)

I don't have the knowledge to do the pull and edit XML and do the regression testing. I can test if someone is able to make the edits.

Screenshots

image

image

Expected Behavior

The keywords would highlight as comments if they did not have the required parameters (the ".PARAMETER" keyword is the only one that currently works) and the keywords and parameters would both highlight as keywords, as the ".PARAMETER" keyword and parameter does now or highlight as a keyword and parameter with two different colors.

Code Samples - Snippet:

function verb-noun {

    <#
        .SYNOPSIS
            A brief description of the function or script.
            This keyword can be used only once in each topic.

        .DESCRIPTION
            A detailed description of the function or script.
            This keyword can be used only once in each topic.

        .EXAMPLE
            A sample command that uses the function or script, optionally followed by sample output and a description.
            Repeat this keyword for each example.

        .INPUTS
            The Microsoft .NET Framework types of objects that can be piped to the function or script.
            You can also include a description of the input objects.

        .OUTPUTS
            The .NET Framework type of the objects that the cmdlet returns.
            You can also include a description of the returned objects.

        .NOTES
            Additional information about the function or script.

        .COMPONENT
            The technology or feature that the function or script uses, or to which it is related.
            This content appears when the Get-Help command includes the Component parameter of Get-Help.

        .ROLE
            The user role for the help topic.
            This content appears when the Get-Help command includes the Role parameter of Get-Help.

        .FUNCTIONALITY
            The intended use of the function.
            This content appears when the Get-Help command includes the Functionality parameter of Get-Help.

        .PARAMETER Inputs
            The description of a parameter. Add a keyword for each parameter in the function or script syntax.

            Type the parameter name on the same line as the keyword. Type the parameter description on the lines following the keyword.

            Windows PowerShell interprets all text between the keyword line and the next keyword or the end of the comment block as part of the parameter description.
            The description can include paragraph breaks.

            The Parameter keywords can appear in any order in the comment block, but the function or script syntax determines the order in which the parameters (and their descriptions) appear in help topic.
            To change the order, change the syntax.

            You can also specify a parameter description by placing a comment in the function or script syntax immediately before the parameter variable name.
            If you use both a syntax comment and a Parameter keyword, the description associated with the Parameter keyword is used, and the syntax comment is ignored.

        .LINK https://www.example.com/
            The name of a related topic. The value appears on the line below the '.LINK' keyword and must be preceded by a comment symbol # or included in the comment block.
            Repeat the keyword for each related topic. This content appears in the Related Links section of the help topic. 
            The keyword content can also include a Uniform Resource Identifier (URI) to an online version of the same help topic.
            The online version opens when you use the Online parameter of Get-Help. The URI must begin with 'http' or 'https'.

        .FORWARDHELPTARGETNAME Get-Help
            Redirects to the help topic for the specified command.
            You can redirect users to any help topic, including help topics for a function, script, cmdlet, or provider.

        .FORWARDHELPCATEGORY All
            Specifies the help category of the item in 'ForwardHelpTargetName'.
            Valid values are 'Alias', 'Cmdlet', 'HelpFile', 'Function', 'Provider', 'General', 'FAQ', 'Glossary', 'ScriptCommand', 'ExternalScript', 'Filter', or 'All'.
            Use this keyword to avoid conflicts when there are commands with the same name.

        .REMOTEHELPRUNSPACE PSSessionVariable
            Specifies a session that contains the help topic. Enter a variable that contains a 'PSSession'.
            This keyword is used by the Export-PSSession cmdlet to find the help topics for the exported commands.

        .EXTERNALHELP c:\external-Help.xml
            Specifies an XML-based help file for the script or function.

            The keyword is required when a function or script is documented in XML files.
            Without this keyword, Get-Help cannot find the XML-based help file for the function or script.

            The keyword takes precedence over other comment-based help keywords.
            If present, Get-Help does not display comment-based help, even if it cannot find a help topic that matches the value of the keyword.

            If the function is exported by a module, set the value of the  keyword to a file name without a path.
            Get-Help looks for the specified file name in a language-specific subdirectory of the module directory.
            There are no requirements for the name of the XML-based help file for a function, but a best practice is to use the following format: <ScriptModule.psm1>-help.xml.
    #>

    [CmdletBinding()]
    [OutputType([int])]

    param(
        [Parameter(Mandatory=true)]
        [string]
        Param1
    )
    
    begin {
    }
    
    process {
        
    }
    
    end {
        Return ${Return}
    }
}
@msftrncs
Copy link
Contributor

Noting #136 as a related issue.

Have you checked out PR #155 or #156 for bahavior?

Are you expecting .Link to accept a parameter, or not? PowerShell does not accept .Link if you attempt to pass a parameter (URL) on the same line, and will actually invalidate the entire comment-based-help.

@RobertKlohr
Copy link
Author

You are correct about the .LINK parameter I was not paying attention when I was building the generic file to make the screenshots.

Issue #136 definitely related.

I looked at #155 and #156 and loaded the powershell.tmLanguage.json file into my system. In it's current state the changes fix most of the issues but not all of them.

  1. The parameter for .PARAMETER do not highlight
  2. The parameter for .LINK (on the line below) do not highlight.

All of the other keywords function and highlight as excepted with the changes in #156.

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

No branches or pull requests

2 participants