@@ -22,6 +22,40 @@ import { APIState, Repository as GitRepository } from './git/git'
2222import { configureGuardrails , configureMCP , updateMCPConfig , updateMCPState } from './commands/configureMCP'
2323import { addRepository , joinOrganization } from './onboarding'
2424
25+ /**
26+ * Handle file creation events by running Codacy CLI config discover
27+ */
28+ const handleFileCreation = async ( filePath : string , codacyCloud : CodacyCloud ) => {
29+ const ignorePaths = [
30+ '.git/' ,
31+ 'node_modules/' ,
32+ '.codacy/' ,
33+ '.vscode/' ,
34+ '.windsurf/' ,
35+ '.cursor/' ,
36+ '.github/' ,
37+ 'readme/' ,
38+ ]
39+ try {
40+ if ( ignorePaths . some ( ( path ) => filePath . includes ( path ) ) ) {
41+ return
42+ }
43+
44+ // Skip if it's not a regular file
45+ const stat = await vscode . workspace . fs . stat ( vscode . Uri . file ( filePath ) )
46+ if ( stat . type !== vscode . FileType . File ) {
47+ return
48+ }
49+
50+ Logger . debug ( `File created: ${ filePath } , running config discover...` )
51+
52+ // Run config discover for the new file
53+ await codacyCloud . cli ?. configDiscover ( filePath )
54+ } catch ( error ) {
55+ Logger . warn ( `Failed to run config discover for ${ filePath } : ${ error } ` )
56+ }
57+ }
58+
2559/**
2660 * Helper function to register all extension commands
2761 * @param context
@@ -268,6 +302,15 @@ export async function activate(context: vscode.ExtensionContext) {
268302 item . onClick ( )
269303 } )
270304
305+ // Listen for file creation and run config discover
306+ context . subscriptions . push (
307+ vscode . workspace . onDidCreateFiles ( async ( event ) => {
308+ for ( const file of event . files ) {
309+ await handleFileCreation ( file . fsPath , codacyCloud )
310+ }
311+ } )
312+ )
313+
271314 const analysisMode = vscode . workspace . getConfiguration ( ) . get ( 'codacy.cli.analysisMode' )
272315 const cliVersion = vscode . workspace . getConfiguration ( ) . get ( 'codacy.cli.cliVersion' )
273316 // When the user doesn't have a specific version, update the CLI to the latest version
0 commit comments