# Integration class
{: .no_toc }

Extends the IDE's code editor: commands, text shown when the mouse rests on code, and CodeLens lines above it. Reached through [**Host.Integration**](/tB/Packages/tbIDE/Host.md#integration).

```tb check_build
Private WithEvents RunCommand As SourceCommand
Private WithEvents Lenses As SourceCodeLensProvider

Private Sub Host_OnProjectLoaded()
    Set RunCommand = Host.Integration.AddSourceCommand("runHere")
    Set Lenses = Host.Integration.AddSourceCodeLensProvider("runLens", "twinbasic")
End Sub

Private Sub Lenses_GetResults(ByVal Uri As String, ByVal ResultResolver As AsyncResultResolver)
    ResultResolver.Resolve "{""lenses"": [{""range"": {""startLineNumber"": 1, ""startColumn"": 1, " & _
        """endLineNumber"": 1, ""endColumn"": 1}, ""command"": {""id"": """ & RunCommand.CommandID & _
        """, ""title"": ""Run here"", ""arguments"": [""" & Uri & """]}}]}"
End Sub

Private Sub RunCommand_Execute(ByVal JsonArgs As String)
    Host.DebugConsole.PrintText "Run here: " & JsonArgs
End Sub
```

The provider puts a **Run here** line above the first line of every code file. Clicking it runs the command, which prints the file's path.

* TOC
{:toc}

## How the three work together

A [**SourceCommand**](/tB/Packages/tbIDE/SourceCommand.md) is an action of the add-in's that the code editor can run. A hover provider and a CodeLens provider name it by its [**CommandID**](/tB/Packages/tbIDE/SourceCommand.md#commandid): a hover shows it as a link, and a lens runs it when clicked. The command's [**Execute**](/tB/Packages/tbIDE/SourceCommand.md#execute) event then fires in the add-in, with the arguments the link or the lens gave it.

A [**SourceHoverProvider**](/tB/Packages/tbIDE/SourceHoverProvider.md) answers its [**Hover**](/tB/Packages/tbIDE/SourceHoverProvider.md#hover) event with text for the box that shows when the mouse rests on code. A [**SourceCodeLensProvider**](/tB/Packages/tbIDE/SourceCodeLensProvider.md) answers its [**GetResults**](/tB/Packages/tbIDE/SourceCodeLensProvider.md#getresults) event with the lenses of a file. Each answers through the [**AsyncResultResolver**](/tB/Packages/tbIDE/AsyncResultResolver.md) its event gives it, at once or later.

Each object stays until the compiler restarts, which loads the add-in again; the new instance adds its own. [**Enabled**](/tB/Packages/tbIDE/SourceHoverProvider.md#enabled) turns one off and on.

## Methods

### AddSourceCodeLensProvider
{: .no_toc }

Adds a CodeLens provider to the code editor, for the files of one language. Once it is added, the provider's [**GetResults**](/tB/Packages/tbIDE/SourceCodeLensProvider.md#getresults) event fires for each file of that language the editor shows.

Syntax: *integration*.**AddSourceCodeLensProvider**( *Name*, *LanguageId* ) **As** [**SourceCodeLensProvider**](/tB/Packages/tbIDE/SourceCodeLensProvider.md)

*Name*
: *required* A name for the provider, which its [**Name**](/tB/Packages/tbIDE/SourceCodeLensProvider.md#name) property returns. **String**.

*LanguageId*
: *required* The language of the files, as the code editor names it: `"twinbasic"` for twinBASIC code, `"json"`, `"javascript"`. **String**.

### AddSourceCommand
{: .no_toc }

Adds a command that a hover or a lens can run. Once it is added, the command's [**Execute**](/tB/Packages/tbIDE/SourceCommand.md#execute) event fires whenever it runs.

Syntax: *integration*.**AddSourceCommand**( *Name* ) **As** [**SourceCommand**](/tB/Packages/tbIDE/SourceCommand.md)

*Name*
: *required* A name for the command, which its [**Name**](/tB/Packages/tbIDE/SourceCommand.md#name) property returns and its [**CommandID**](/tB/Packages/tbIDE/SourceCommand.md#commandid) includes. **String**.

### AddSourceHoverProvider
{: .no_toc }

Adds a hover provider to the code editor. Once it is added, the provider's [**Hover**](/tB/Packages/tbIDE/SourceHoverProvider.md#hover) event fires whenever the mouse rests on twinBASIC code.

Syntax: *integration*.**AddSourceHoverProvider**( *Name* ) **As** [**SourceHoverProvider**](/tB/Packages/tbIDE/SourceHoverProvider.md)

*Name*
: *required* A name for the provider, which its [**Name**](/tB/Packages/tbIDE/SourceHoverProvider.md#name) property returns. **String**.

## See Also

- [Host.Integration](/tB/Packages/tbIDE/Host.md#integration) property
- [SourceCommand](/tB/Packages/tbIDE/SourceCommand.md) class
- [SourceHoverProvider](/tB/Packages/tbIDE/SourceHoverProvider.md) class
- [SourceCodeLensProvider](/tB/Packages/tbIDE/SourceCodeLensProvider.md) class
- [AsyncResultResolver](/tB/Packages/tbIDE/AsyncResultResolver.md) class
