SourceCodeLensProvider class

Adds CodeLens lines to the code editor: a line of links above a line of code, each of which runs a SourceCommand. Made by Integration.AddSourceCodeLensProvider.

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.

Properties

Enabled

Whether the provider is asked. Boolean, read/write. True when it is added. Setting it to False removes the provider’s lenses, and 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.

LanguageId

The language whose files the provider is asked about, as given to AddSourceCodeLensProvider. String, read-only.

Name

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

Methods

Refresh

Asks for the lenses again: GetResults fires for the file the code editor shows. Call it when what the lenses show has changed.

Syntax: provider.Refresh

Events

GetResults

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.

Syntax: provider_GetResults( Uri As String, ResultResolver As AsyncResultResolver )

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.
ResultResolver
Takes the answer. Call its 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:

{
  "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’s CommandID, title the text of the link, and arguments, which may be left out, the array that the command’s Execute gets as its JsonArgs.

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

See Also