@@ -19,6 +19,8 @@ import {
1919import { CodelensProvider } from './ui/CodeLensProvider' ;
2020import { callConcretePlayback } from './ui/concrete-playback/concretePlayback' ;
2121import { runKaniPlayback } from './ui/concrete-playback/kaniPlayback' ;
22+ import CoverageConfig from './ui/coverage/config' ;
23+ import { CoverageRenderer , runCodeCoverageAction } from './ui/coverage/coverageInfo' ;
2224import { callViewerReport } from './ui/reportView/callReport' ;
2325import { showInformationMessage } from './ui/showMessage' ;
2426import { SourceCodeParser } from './ui/sourceCodeParser' ;
@@ -64,6 +66,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
6466
6567 // create a uri for the root folder
6668 context . subscriptions . push ( controller ) ;
69+ // Store coverage objects in a global cache when highlighting. When de-highlighting, the same objects need to be disposed
70+ const coverageConfig = new CoverageConfig ( context ) ;
71+ const globalConfig = GlobalConfig . getInstance ( ) ;
6772 const crateURI : Uri = getRootDirURI ( ) ;
6873 const treeRoot : vscode . TestItem = controller . createTestItem (
6974 'Kani proofs' ,
@@ -225,20 +230,49 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
225230 vscode . workspace . getConfiguration ( 'codelens-kani' ) . update ( 'enableCodeLens' , true , true ) ;
226231 } ) ;
227232
228- // Allows VSCode to disable VSCode globally
233+ // Allows VSCode to disable code lens globally
229234 vscode . commands . registerCommand ( 'codelens-kani.disableCodeLens' , ( ) => {
230235 vscode . workspace . getConfiguration ( 'codelens-kani' ) . update ( 'enableCodeLens' , false , true ) ;
231236 } ) ;
232237
238+ // Allows VSCode to enable highlighting globally
239+ vscode . commands . registerCommand ( 'codelens-kani.enableCoverage' , ( ) => {
240+ vscode . workspace . getConfiguration ( 'codelens-kani' ) . update ( 'highlightCoverage' , true , true ) ;
241+ } ) ;
242+
243+ // Allows VSCode to disable highlighting globally
244+ vscode . commands . registerCommand ( 'codelens-kani.disableCoverage' , ( ) => {
245+ vscode . workspace . getConfiguration ( 'codelens-kani' ) . update ( 'highlightCoverage' , false , true ) ;
246+ } ) ;
247+
233248 // Register the command for the code lens Kani test runner function
234249 vscode . commands . registerCommand ( 'codelens-kani.codelensAction' , ( args : any ) => {
235250 runKaniPlayback ( args ) ;
236251 } ) ;
237252
253+ // Separate rendering logic and re-use everywhere to highlight and de-highlight
254+ const renderer = new CoverageRenderer ( coverageConfig ) ;
255+
256+ // Register a command to de-highlight the coverage in the active editor
257+ const dehighlightCoverageCommand = vscode . commands . registerCommand (
258+ 'codelens-kani.dehighlightCoverage' ,
259+ ( ) => {
260+ globalConfig . setCoverage ( new Map ( ) ) ;
261+ renderer . renderInterface ( vscode . window . visibleTextEditors , new Map ( ) ) ;
262+ } ,
263+ ) ;
264+
238265 // Update the test tree with proofs whenever a test case is opened
239266 context . subscriptions . push (
240267 vscode . workspace . onDidOpenTextDocument ( updateNodeForDocument ) ,
241268 vscode . workspace . onDidSaveTextDocument ( async ( e ) => await updateNodeForDocument ( e ) ) ,
269+ vscode . window . onDidChangeActiveTextEditor ( ( editor ) => {
270+ // VS Code resets highlighting whenever a document is changed or switched.
271+ // In order to work around this issue, the highlighting needs to be rendered each time.
272+ // To keep the rendering time short, we store the coverage metadata as a global cache.
273+ const cache = globalConfig . getCoverage ( ) ;
274+ renderer . renderInterfaceForFile ( editor ! , cache ) ;
275+ } ) ,
242276 ) ;
243277
244278 context . subscriptions . push ( runKani ) ;
@@ -251,4 +285,13 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
251285 connectToDebugger ( programName ) ,
252286 ) ,
253287 ) ;
288+ // Register the command for running the coverage action on a harness
289+ context . subscriptions . push (
290+ vscode . commands . registerCommand ( 'codelens-kani.highlightCoverage' , ( args : any ) => {
291+ runCodeCoverageAction ( renderer , args ) ;
292+ } ) ,
293+ ) ;
294+
295+ // Register the command for de-highlighting kani's coverage action on a harness
296+ context . subscriptions . push ( dehighlightCoverageCommand ) ;
254297}
0 commit comments