Skip to content

Commit b69b5ed

Browse files
Merge pull request #188 from codacy/fix-mcp-404
fix: params not being used for instructions generation CF-2162
2 parents fe4db32 + 2e318bf commit b69b5ed

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/commands/configureMCP.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ export async function configureMCP(params?: RepositoryParams, isUpdate = false)
261261
if (generateRules === 'automatic') {
262262
await createOrUpdateRules(params)
263263
}
264-
await notifyMCPInstallation()
264+
if (!isUpdate) {
265+
await notifyMCPInstallation()
266+
}
265267
return
266268
} else {
267269
await installMCPForVSCode(codacyServer)

src/extension.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,16 @@ const registerGitProvider = async (context: vscode.ExtensionContext, codacyCloud
155155

156156
if (git) {
157157
// register events
158-
git.onDidOpenRepository((repo: GitRepository) => {
159-
codacyCloud.open(repo)
158+
git.onDidOpenRepository(async (repo: GitRepository) => {
159+
try {
160+
await codacyCloud.open(repo)
161+
// update MCP after repository is opened and params are available
162+
updateMCPConfig(codacyCloud.params).catch((error) => {
163+
Logger.warn(`Failed to update MCP config: ${error instanceof Error ? error.message : String(error)}`)
164+
})
165+
} catch (error) {
166+
Logger.error(`Failed to open repository: ${error instanceof Error ? error.message : String(error)}`)
167+
}
160168
})
161169

162170
git.onDidCloseRepository((repo: GitRepository) => {
@@ -172,7 +180,9 @@ const registerGitProvider = async (context: vscode.ExtensionContext, codacyCloud
172180
if (state === 'initialized') {
173181
if (git.repositories.length > 0) {
174182
Logger.debug(`Git API initialized with ${git.repositories.length} repositories`)
175-
codacyCloud.open(git.repositories[0])
183+
await codacyCloud.open(git.repositories[0])
184+
// Update MCP config after repository is opened and params are available
185+
await updateMCPConfig(codacyCloud.params)
176186
} else {
177187
Logger.appendLine('Git API initialized but no repositories found')
178188
codacyCloud.clear()
@@ -350,7 +360,7 @@ export async function activate(context: vscode.ExtensionContext) {
350360
// check for open repository
351361
if (gitProvider.state === 'initialized' && gitProvider.repositories.length > 0) {
352362
Logger.debug(`Found ${gitProvider.repositories.length} repositories, opening first one`)
353-
codacyCloud.open(gitProvider.repositories[0])
363+
await codacyCloud.open(gitProvider.repositories[0])
354364
} else if (gitProvider.state === 'uninitialized') {
355365
Logger.debug('Git API is still initializing, will wait for state change event')
356366
} else {

src/views/SetupView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export class SetupViewProvider implements vscode.WebviewViewProvider {
246246
}
247247

248248
private generateInstructionsFile() {
249-
createOrUpdateRules()
249+
createOrUpdateRules(this._codacyCloud?.params)
250250
.then(() => {
251251
this.updateMCPStatus()
252252
})

0 commit comments

Comments
 (0)