Method / Class Comments with Intellisense

Welcome Forums General PowerShell Q&A Method / Class Comments with Intellisense

This topic contains 5 replies, has 4 voices, and was last updated by

 
Participant
2 months, 2 weeks ago.

  • Author
    Posts
  • #163347

    Participant
    Topics: 1
    Replies: 9
    Points: 18
    Rank: Member

    I have written a PowerShell Class with static methods.  It works quite swiftly and efficiently.

    I would like the ability to add comments to the Class and the Methods which will appear in an IDE (e.g. VScode) while writing Advanced Functions that use the Class.  In Python one can surround the comments with three single quotes ("'comment"') as shown below. Those comments appear in VScode when writing against the class/function.

    Is there a Methodology (wink) for this in PowerShell? If so, what is it? I've tried /// and # and "' to no avail.

    Thanks,
    JoeyA

    Python....
    class MyClass():

    "'My Comments Here"'

    def my_function:

    "'More comments here"'

    PowerShell....
    Class myClass
    {
    # Comments here that are used by Intellisense?
    static [hashtable] myMethod ([string] $myVar)
    # Comments here that are used by Intellisense
    {}
    }

  • #163356

    Participant
    Topics: 0
    Replies: 44
    Points: 235
    Helping Hand
    Rank: Participant
  • #163368

    Participant
    Topics: 1
    Replies: 9
    Points: 18
    Rank: Member

    The link does not mention classes, methods, or how to make comments for them that appear in intellisense.  So no, not at all helpful.  Thanks tho.

  • #163371

    Participant
    Topics: 2
    Replies: 999
    Points: 1,946
    Helping Hand
    Rank: Community Hero

    Why not just look at the PowerShell classes MS provides that are already on your system as the examples to follow for your use case, or jump out to the PowerShell Core OSS repo and look at the source code for all the cmdlet for examples?

    This ' /// ' of course is not how you do comments in PowerShell proper. There is on '#' or '< ##>' , though the .Net stuff (C#, etc.) does use that, thus, well, you know.

    See also:

    Comment-based Help for classes
    https://github.com/PowerShell/PowerShell/issues/2225

    How To Document Your PowerShell Library

    How To Document Your PowerShell Library

     

  • #163545

    Participant
    Topics: 2
    Replies: 54
    Points: 278
    Helping Hand
    Rank: Contributor

    You're looking for the Insert XML Comments functionality to give you in-line IntelliSense descriptions. JavaScript has a similar feature called JSDoc. Unfortunately, this is a language-specific feature and even though PowerShell borrows some syntax from C# it does not include this feature.

  • #163659

    Participant
    Topics: 1
    Replies: 9
    Points: 18
    Rank: Member

    @grokkit – thanks for the response.  I came to the same conclusion, but thought I would ask just in case I missed something simple.  Fortunately its not a major item.  Thanks again!

You must be logged in to reply to this topic.