@@ -38,7 +38,7 @@ import waitPort = require('wait-port');
3838import { GroupBy , Impact , Confidence } from './detections/WakeTreeDataProvider' ;
3939import { SolcTreeDataProvider } from './detections/SolcTreeDataProvider' ;
4040import { WakeTreeDataProvider } from './detections/WakeTreeDataProvider' ;
41- import { Detector , WakeDetection } from './detections/model/WakeDetection' ;
41+ import { Detector , WakeDetection , WakeDiagnostic } from './detections/model/WakeDetection' ;
4242import { convertDiagnostics } from './detections/util' ;
4343import { DetectorItem } from './detections/model/DetectorItem' ;
4444import { ClientMiddleware } from './ClientMiddleware' ;
@@ -65,6 +65,8 @@ let errorHandler: ClientErrorHandler;
6565let printers : PrintersHandler ;
6666let crashlog : string [ ] = [ ] ;
6767let graphvizGenerator : GraphvizPreviewGenerator ;
68+ let showIgnoredDetections = false ;
69+ let extensionContext : vscode . ExtensionContext ;
6870
6971//export let log: Log
7072
@@ -75,20 +77,28 @@ interface DiagnosticNotification {
7577 diagnostics : Diagnostic [ ] ;
7678}
7779
80+ // Store all diagnostics globally so we can refresh visibility
81+ let allDiagnosticsMap : Map < string , WakeDiagnostic [ ] > = new Map ( ) ;
82+
7883function onNotification ( outputChannel : vscode . OutputChannel , detection : DiagnosticNotification ) {
79- let diags = detection . diagnostics
80- . map ( ( it ) => convertDiagnostics ( it ) )
81- . filter ( ( item ) => ! item . data . ignored ) ;
82- diagnosticCollection . set ( vscode . Uri . parse ( detection . uri ) , diags ) ;
84+ let diags = detection . diagnostics . map ( ( it ) => convertDiagnostics ( it ) ) ;
85+
86+ // Store all diagnostics for later filtering
87+ allDiagnosticsMap . set ( detection . uri , diags ) ;
88+
89+ // Store filtered diagnostics for VS Code diagnostics panel
90+ let visibleDiags = diags . filter ( ( item ) => showIgnoredDetections || ! item . data . ignored ) ;
91+ diagnosticCollection . set ( vscode . Uri . parse ( detection . uri ) , visibleDiags ) ;
8392
8493 try {
8594 let uri = vscode . Uri . parse ( detection . uri ) ;
95+ // Pass all detections to providers (including ignored ones)
8696 let wakeDetections = diags
87- . filter ( ( item ) => item . source == 'Wake' )
97+ . filter ( ( item ) => item . source === 'Wake' )
8898 . map ( ( it ) => new WakeDetection ( uri , it ) ) ;
8999 wakeProvider ?. add ( uri , wakeDetections ) ;
90100 let solcDetections = diags
91- . filter ( ( item ) => item . source == 'Wake(solc)' )
101+ . filter ( ( item ) => item . source === 'Wake(solc)' )
92102 . map ( ( it ) => new WakeDetection ( uri , it ) ) ;
93103 solcProvider ?. add ( uri , solcDetections ) ;
94104 } catch ( err ) {
@@ -98,9 +108,18 @@ function onNotification(outputChannel: vscode.OutputChannel, detection: Diagnost
98108 }
99109}
100110
111+ function refreshDiagnosticsVisibility ( ) {
112+ // Re-filter all stored diagnostics based on current showIgnoredDetections state
113+ for ( const [ uri , diags ] of allDiagnosticsMap ) {
114+ let visibleDiags = diags . filter ( ( item ) => showIgnoredDetections || ! item . data . ignored ) ;
115+ diagnosticCollection . set ( vscode . Uri . parse ( uri ) , visibleDiags ) ;
116+ }
117+ }
118+
101119// this method is called when your extension is activated
102120// your extension is activated the very first time the command is executed
103121export async function activate ( context : vscode . ExtensionContext ) {
122+ extensionContext = context ;
104123 const outputChannel = vscode . window . createOutputChannel (
105124 'Solidity: Output' ,
106125 'tools-for-solidity-output'
@@ -236,6 +255,9 @@ export async function activate(context: vscode.ExtensionContext) {
236255 wakeProvider = new WakeTreeDataProvider ( context ) ;
237256 solcProvider = new SolcTreeDataProvider ( context ) ;
238257
258+ // Initialize showIgnoredDetections from workspace state (already loaded by WakeTreeDataProvider)
259+ showIgnoredDetections = context . workspaceState . get ( 'detections.showIgnored' , false ) ;
260+
239261 const clientOptions : LanguageClientOptions = {
240262 documentSelector : [ { scheme : 'file' , language : 'solidity' } ] ,
241263 synchronize : { configurationSection : 'wake' } ,
@@ -325,7 +347,7 @@ export async function activate(context: vscode.ExtensionContext) {
325347 client . start ( ) ;
326348
327349 // Create the Wake status bar item
328- const statusBarProvider = new WakeStatusBarProvider ( client ) ;
350+ const statusBarProvider = new WakeStatusBarProvider ( client , analytics ) ;
329351
330352 analytics . logActivate ( ) ;
331353
@@ -542,6 +564,7 @@ function registerCommands(outputChannel: vscode.OutputChannel, context: vscode.E
542564 'Tools-for-Solidity.detections.force_rerun_detectors' ,
543565 async ( ) => {
544566 wakeProvider ?. clear ( ) ;
567+ allDiagnosticsMap . clear ( ) ;
545568 vscode . commands . executeCommand ( 'wake.lsp.force_rerun_detectors' ) ;
546569 }
547570 )
@@ -552,6 +575,7 @@ function registerCommands(outputChannel: vscode.OutputChannel, context: vscode.E
552575 async ( ) => {
553576 solcProvider ?. clear ( ) ;
554577 wakeProvider ?. clear ( ) ;
578+ allDiagnosticsMap . clear ( ) ;
555579 vscode . commands . executeCommand ( 'wake.lsp.force_recompile' ) ;
556580 }
557581 )
@@ -652,6 +676,39 @@ function registerCommands(outputChannel: vscode.OutputChannel, context: vscode.E
652676 ) ;
653677 } )
654678 ) ;
679+
680+ // Register commands for toggling ignored detections
681+ context . subscriptions . push (
682+ vscode . commands . registerCommand ( 'Tools-for-Solidity.detections.toggle_show_ignored' , ( ) => {
683+ showIgnoredDetections = true ;
684+ vscode . commands . executeCommand ( 'setContext' , 'wake.detections.showIgnored' , true ) ;
685+
686+ // Update tree provider (which also saves to workspaceState)
687+ wakeProvider ?. setShowIgnored ( true ) ;
688+
689+ // Refresh diagnostics panel by re-processing existing detections
690+ refreshDiagnosticsVisibility ( ) ;
691+ } )
692+ ) ;
693+
694+ context . subscriptions . push (
695+ vscode . commands . registerCommand ( 'Tools-for-Solidity.detections.toggle_hide_ignored' , ( ) => {
696+ showIgnoredDetections = false ;
697+ vscode . commands . executeCommand ( 'setContext' , 'wake.detections.showIgnored' , false ) ;
698+
699+ // Update tree provider (which also saves to workspaceState)
700+ wakeProvider ?. setShowIgnored ( false ) ;
701+
702+ // Refresh diagnostics panel by re-processing existing detections
703+ refreshDiagnosticsVisibility ( ) ;
704+ } )
705+ ) ;
706+ }
707+
708+ function registerFormatter ( context : vscode . ExtensionContext ) {
709+ context . subscriptions . push (
710+ vscode . languages . registerDocumentFormattingEditProvider ( 'solidity' , new PrettierFormatter ( ) )
711+ ) ;
655712}
656713
657714function registerFormatter ( context : vscode . ExtensionContext ) {
@@ -668,7 +725,7 @@ function watchFoundryRemappings() {
668725
669726 const workspace = workspaces [ 0 ] ;
670727 const fileWatcher = vscode . workspace . createFileSystemWatcher (
671- new vscode . RelativePattern ( workspace , 'remappings.txt ' )
728+ new vscode . RelativePattern ( workspace , '.gitmodules ' )
672729 ) ;
673730
674731 let configWatcher : vscode . Disposable ;
@@ -704,6 +761,14 @@ function watchFoundryRemappings() {
704761 return ;
705762 }
706763
764+ // Check if this is a Foundry project by looking for .gitmodules or foundry.toml
765+ // const gitmodulesPath = path.join(workspace.uri.fsPath, '.gitmodules');
766+ // const foundryTomlPath = path.join(workspace.uri.fsPath, 'foundry.toml');
767+
768+ // if (!fs.existsSync(gitmodulesPath) && !fs.existsSync(foundryTomlPath)) {
769+ // return;
770+ // }
771+
707772 // start file system watcher
708773 fileWatcher . onDidChange ( async ( ) => {
709774 vscode . commands . executeCommand ( 'Tools-for-Solidity.foundry.import_remappings_silent' ) ;
@@ -712,6 +777,7 @@ function watchFoundryRemappings() {
712777 vscode . commands . executeCommand ( 'Tools-for-Solidity.foundry.import_remappings_silent' ) ;
713778 } ) ;
714779 fileWatcher . onDidDelete ( async ( ) => {
780+ // When .gitmodules is deleted, clear remappings since dependencies are gone
715781 vscode . workspace
716782 . getConfiguration ( 'wake.compiler.solc' )
717783 . update ( 'remappings' , undefined , vscode . ConfigurationTarget . Workspace ) ;
0 commit comments