# SourceCommand class
{: .no_toc }

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**](/tB/Packages/tbIDE/Integration.md#addsourcecommand).

```tb check_build
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
```

* TOC
{:toc}

## Properties

### CommandID
{: .no_toc }

The name by which a hover or a lens runs the command: `tbaddin.`, the command's [**Name**](#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**](/tB/Packages/tbIDE/SourceCodeLensProvider.md#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
{: .no_toc }

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.

> [!WARNING] BETA 1052
> **Enabled** reads **True** whatever was set, and once **False** has removed the command, setting **True** does not add it again: the command stays removed until the compiler restarts and the add-in adds it again. To stop a command for a while, have its [**Execute**](#execute) handler test a flag of the add-in's own instead.

### Name
{: .no_toc }

The name given to [**AddSourceCommand**](/tB/Packages/tbIDE/Integration.md#addsourcecommand). **String**, read-only.

## Events

### Execute
{: .no_toc }

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

- [Integration.AddSourceCommand](/tB/Packages/tbIDE/Integration.md#addsourcecommand) method
- [SourceHoverProvider](/tB/Packages/tbIDE/SourceHoverProvider.md) class
- [SourceCodeLensProvider](/tB/Packages/tbIDE/SourceCodeLensProvider.md) class
