# SourceCodeLensProvider class
{: .no_toc }

Adds CodeLens lines to the code editor: a line of links above a line of code, each of which runs a [**SourceCommand**](/tB/Packages/tbIDE/SourceCommand.md). Made by [**Integration.AddSourceCodeLensProvider**](/tB/Packages/tbIDE/Integration.md#addsourcecodelensprovider).

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

Private Sub Host_OnProjectLoaded()
    Set Open = Host.Integration.AddSourceCommand("openTop")
    Set Lenses = Host.Integration.AddSourceCodeLensProvider("topLens", "twinbasic")
End Sub

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

Private Sub Open_Execute(ByVal JsonArgs As String)
    Host.ShowNotification "The lens was clicked."
End Sub
```

The lens above each file's first line shows the file's path.

* TOC
{:toc}

## Properties

### Enabled
{: .no_toc }

Whether the provider is asked. **Boolean**, read/write. **True** when it is added. Setting it to **False** removes the provider's lenses, and [**GetResults**](#getresults) does not fire while it is **False**. Setting it to **True** again does not ask for the lenses: they show again at the next **GetResults**, after an edit to the file or a call to [**Refresh**](#refresh).

### LanguageId
{: .no_toc }

The language whose files the provider is asked about, as given to [**AddSourceCodeLensProvider**](/tB/Packages/tbIDE/Integration.md#addsourcecodelensprovider). **String**, read-only.

### Name
{: .no_toc }

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

## Methods

### Refresh
{: .no_toc }

Asks for the lenses again: [**GetResults**](#getresults) fires for the file the code editor shows. Call it when what the lenses show has changed.

Syntax: *provider*.**Refresh**

## Events

### GetResults
{: .no_toc }

Fires when the code editor needs the lenses of a file of the provider's language: as the file is shown, after it is edited, and after [**Refresh**](#refresh).

Syntax: *provider*_**GetResults**( *Uri* **As String**, *ResultResolver* **As** [**AsyncResultResolver**](/tB/Packages/tbIDE/AsyncResultResolver.md) )

*Uri*
: The file's path in the project: `/MyProject/Sources/Module1.twin`. It has no `twinbasic:` in front of it, unlike the *Uri* of [**SourceHoverProvider.Hover**](/tB/Packages/tbIDE/SourceHoverProvider.md#hover).

*ResultResolver*
: Takes the answer. Call its [**Resolve**](/tB/Packages/tbIDE/AsyncResultResolver.md#resolve) with the file's lenses as a **String** of JSON, or with an empty string for none.

The JSON is an object whose `lenses` is an array, with one object for each lens:

```json
{
  "lenses": [
    {
      "range": { "startLineNumber": 12, "startColumn": 1, "endLineNumber": 12, "endColumn": 1 },
      "command": { "id": "tbaddin.openTop.1", "title": "Open the top", "arguments": ["a", 7] }
    }
  ]
}
```

`range`
: Where the lens is: it shows above `startLineNumber`. Lines and columns count from 1.

`command`
: What the lens shows and does. `id` is a [**SourceCommand**](/tB/Packages/tbIDE/SourceCommand.md)'s [**CommandID**](/tB/Packages/tbIDE/SourceCommand.md#commandid), `title` the text of the link, and `arguments`, which may be left out, the array that the command's [**Execute**](/tB/Packages/tbIDE/SourceCommand.md#execute) gets as its *JsonArgs*.

This is the `CodeLensList` of Monaco, the IDE's code editor, which its documentation describes in full.

## See Also

- [Integration.AddSourceCodeLensProvider](/tB/Packages/tbIDE/Integration.md#addsourcecodelensprovider) method
- [SourceCommand](/tB/Packages/tbIDE/SourceCommand.md) class
- [AsyncResultResolver](/tB/Packages/tbIDE/AsyncResultResolver.md) class
