SourceCommand class

An action of the add-in’s that the code editor runs from a hover’s link or from a lens. Made by Integration.AddSourceCommand.

Private WithEvents Explain As SourceCommand
Private WithEvents Hovers As SourceHoverProvider

Private Sub Host_OnProjectLoaded()
    Set Explain = Host.Integration.AddSourceCommand("explain")
    Set Hovers = Host.Integration.AddSourceHoverProvider("explainHover")
End Sub

Private Sub Hovers_Hover(ByVal Uri As String, ByVal LineNumber As Long, ByVal CharOffset As Long, _
        ByVal IsDebugging As Boolean, ByVal ResultResolver As AsyncResultResolver)
    ResultResolver.Resolve "[Explain line " & LineNumber & "](command:" & Explain.CommandID & _
        "?%5B" & LineNumber & "%5D)"
End Sub

Private Sub Explain_Execute(ByVal JsonArgs As String)
    Host.DebugConsole.PrintText "Explain: " & JsonArgs     ' Explain: [12]
End Sub

Properties

CommandID

The name by which a hover or a lens runs the command: tbaddin., the command’s Name, a dot and a number the IDE gives it, as tbaddin.explain.1. String, read-only.

A lens names it in its command’s id; see SourceCodeLensProvider.GetResults. A hover’s markdown names it in a link to command: and the CommandID, with the arguments after a ? as a JSON array, its characters percent-encoded as in a URL: [Run it](command:tbaddin.explain.1?%5B%22a%22%2C2%5D) runs the command with ["a",2].

Enabled

Whether the command can run. Boolean, read/write. True when it is added.

Setting it to False removes the command from the code editor. A link or a lens that names it then runs nothing.

Name

The name given to AddSourceCommand. String, read-only.

Events

Execute

Fires when the code editor runs the command: a click on a hover’s link to it, or on a lens that names it.

Syntax: command_Execute( JsonArgs As String )

JsonArgs
The command’s arguments, as a JSON array: those after the ? of the link, or a lens’s arguments. [] when there are none.

See Also