Integration class
Extends the IDE’s code editor: commands, text shown when the mouse rests on code, and CodeLens lines above it. Reached through Host.Integration.
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.
How the three work together
A SourceCommand 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: a hover shows it as a link, and a lens runs it when clicked. The command’s Execute event then fires in the add-in, with the arguments the link or the lens gave it.
A SourceHoverProvider answers its Hover event with text for the box that shows when the mouse rests on code. A SourceCodeLensProvider answers its GetResults event with the lenses of a file. Each answers through the AsyncResultResolver 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 turns one off and on.
Methods
AddSourceCodeLensProvider
Adds a CodeLens provider to the code editor, for the files of one language. Once it is added, the provider’s GetResults event fires for each file of that language the editor shows.
Syntax: integration.AddSourceCodeLensProvider( Name, LanguageId ) As SourceCodeLensProvider
- Name
- required A name for the provider, which its 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
Adds a command that a hover or a lens can run. Once it is added, the command’s Execute event fires whenever it runs.
Syntax: integration.AddSourceCommand( Name ) As SourceCommand
- Name
- required A name for the command, which its Name property returns and its CommandID includes. String.
AddSourceHoverProvider
Adds a hover provider to the code editor. Once it is added, the provider’s Hover event fires whenever the mouse rests on twinBASIC code.
Syntax: integration.AddSourceHoverProvider( Name ) As SourceHoverProvider
- Name
- required A name for the provider, which its Name property returns. String.
See Also
- Host.Integration property
- SourceCommand class
- SourceHoverProvider class
- SourceCodeLensProvider class
- AsyncResultResolver class