11import * as vscode from 'vscode'
2+ import * as os from 'os'
23import { CommandType , wrapCommandWithCatch } from './common/utils'
34import Logger from './common/logger'
45import { initializeApi } from './api'
@@ -18,6 +19,7 @@ import Telemetry from './common/telemetry'
1819import { decorateWithCoverage } from './views/coverage'
1920import { APIState , Repository as GitRepository } from './git/git'
2021import { configureMCP , createRules , isMCPConfigured } from './commands/configureMCP'
22+ import { installCodacyCLI , isCLIInstalled } from './commands/installAnalysisCLI'
2123
2224/**
2325 * Helper function to register all extension commands
@@ -96,6 +98,8 @@ export async function activate(context: vscode.ExtensionContext) {
9698 ( vscode . env . appName . toLowerCase ( ) . includes ( 'code' ) && ! ! vscode . extensions . getExtension ( 'GitHub.copilot' ) )
9799 )
98100
101+ await vscode . commands . executeCommand ( 'setContext' , 'codacy:canInstallCLI' , os . platform ( ) === 'darwin' )
102+
99103 Config . init ( context )
100104
101105 initializeApi ( )
@@ -180,6 +184,46 @@ export async function activate(context: vscode.ExtensionContext) {
180184 item . onClick ( )
181185 } )
182186
187+ // Register CLI installation commands
188+ const updateCLIState = async ( ) => {
189+ const isInstalled = await isCLIInstalled ( )
190+ vscode . commands . executeCommand ( 'setContext' , 'codacy:cliInstalled' , isInstalled )
191+ }
192+
193+ await updateCLIState ( )
194+
195+ context . subscriptions . push (
196+ vscode . commands . registerCommand ( 'codacy.installCLI' , async ( ) => {
197+ await vscode . commands . executeCommand ( 'setContext' , 'codacy:cliInstalling' , true )
198+
199+ await vscode . window . withProgress (
200+ {
201+ location : vscode . ProgressLocation . Window ,
202+ title : 'Installing Codacy CLI' ,
203+ cancellable : false ,
204+ } ,
205+ async ( ) => {
206+ try {
207+ const repository = repositoryManager . repository
208+ if ( repository ) {
209+ await installCodacyCLI ( repository )
210+ await updateCLIState ( )
211+ vscode . window . showInformationMessage ( 'Codacy CLI installed successfully!' )
212+ } else {
213+ throw new Error ( 'No repository found' )
214+ }
215+ } catch ( error ) {
216+ vscode . window . showErrorMessage (
217+ `Failed to install Codacy CLI: ${ error instanceof Error ? error . message : 'Unknown error' } `
218+ )
219+ } finally {
220+ await vscode . commands . executeCommand ( 'setContext' , 'codacy:cliInstalling' , false )
221+ }
222+ }
223+ )
224+ } )
225+ )
226+
183227 // Register MCP commands
184228 const updateMCPState = ( ) => {
185229 const isConfigured = isMCPConfigured ( )
0 commit comments