@@ -19,7 +19,7 @@ import Telemetry from './common/telemetry'
1919import { decorateWithCoverage } from './views/coverage'
2020import { APIState , Repository as GitRepository } from './git/git'
2121import { configureMCP , createRules , isMCPConfigured } from './commands/configureMCP'
22- import { isCLIInstalled , updateCodacyCLI } from './commands/installAnalysisCLI'
22+ import { installCodacyCLI , isCLIInstalled , updateCodacyCLI } from './commands/installAnalysisCLI'
2323
2424/**
2525 * Helper function to register all extension commands
@@ -216,17 +216,48 @@ export async function activate(context: vscode.ExtensionContext) {
216216 } )
217217
218218 // Update CLI on startup
219- const cliInstalled = await isCLIInstalled ( )
220- vscode . commands . executeCommand ( 'setContext' , 'codacy:cliInstalled' , cliInstalled )
219+ const updateCLIState = async ( ) => {
220+ const cliInstalled = await isCLIInstalled ( )
221+ vscode . commands . executeCommand ( 'setContext' , 'codacy:cliInstalled' , cliInstalled )
222+ }
221223
224+ const cliInstalled = await isCLIInstalled ( )
222225 const analysisMode = vscode . workspace . getConfiguration ( ) . get ( 'codacy.cli.analysisMode' )
223226 const cliVersion = vscode . workspace . getConfiguration ( ) . get ( 'codacy.cli.cliVersion' )
224227 // When the user doesn't have a specific version, update the CLI to the latest version
225228 if ( ! cliVersion && cliInstalled && analysisMode !== 'disabled' ) {
226229 await updateCodacyCLI ( repositoryManager . repository )
230+ await updateCLIState ( )
227231 // If it is not installed, don't do anything. On the next usage of the CLI it will be installed with the most recent version
228232 }
229233
234+ context . subscriptions . push (
235+ vscode . commands . registerCommand ( 'codacy.installCLI' , async ( ) => {
236+ await vscode . commands . executeCommand ( 'setContext' , 'codacy:cliInstalling' , true )
237+
238+ await vscode . window . withProgress (
239+ {
240+ location : vscode . ProgressLocation . Window ,
241+ title : 'Installing Codacy CLI' ,
242+ cancellable : false ,
243+ } ,
244+ async ( ) => {
245+ try {
246+ await installCodacyCLI ( repositoryManager . repository )
247+ await updateCLIState ( )
248+ vscode . window . showInformationMessage ( 'Codacy CLI installed successfully!' )
249+ } catch ( error ) {
250+ vscode . window . showErrorMessage (
251+ `Failed to install Codacy CLI: ${ error instanceof Error ? error . message : 'Unknown error' } `
252+ )
253+ } finally {
254+ await vscode . commands . executeCommand ( 'setContext' , 'codacy:cliInstalling' , false )
255+ }
256+ }
257+ )
258+ } )
259+ )
260+
230261 // Register MCP commands
231262 const updateMCPState = ( ) => {
232263 const isConfigured = isMCPConfigured ( )
0 commit comments