Method / Class Comments with Intellisense

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

Viewing 5 reply threads
  • 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: 45
      Points: 243
      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: 1013
      Points: 2,093
      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
      Senior Moderator
      Topics: 3
      Replies: 123
      Points: 655
      Helping Hand
      Rank: Major 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!

Viewing 5 reply threads
  • The topic ‘Method / Class Comments with Intellisense’ is closed to new replies.