Skip to content

Commit 1ca4159

Browse files
add guardrails settings to enable/disable
1 parent 6699ef3 commit 1ca4159

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,20 @@
309309
"codacy.apiToken": {
310310
"type": "string",
311311
"description": "API Personal Token"
312+
},
313+
"codacy.analysisMode": {
314+
"type": "string",
315+
"title": "Local code analysis",
316+
"description": "This feature allows you to analyze your code locally using the Codacy CLI.",
317+
"enum": ["enabled", "only on saved files", "disabled"],
318+
"default": "enabled"
319+
},
320+
"codacy.guardrailsOnGeneratedCode": {
321+
"type": "string",
322+
"title": "Automatically analyze generated code with Codacy Guardrails",
323+
"description": "This feature ensures that your generated code is analyzed by Codacy Guardrails.",
324+
"enum": ["enabled", "disabled"],
325+
"default": "enabled"
312326
}
313327
}
314328
},

src/commands/configureMCP.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export function isMCPConfigured(): boolean {
219219
}
220220

221221
export async function configureMCP(repository: Repository) {
222+
const guardrailsOnGeneratedCode = vscode.workspace.getConfiguration().get('codacy.guardrailsOnGeneratedCode')
222223
const ideConfig = getCorrectMcpConfig()
223224
try {
224225
const apiToken = Config.apiToken
@@ -267,7 +268,9 @@ export async function configureMCP(repository: Repository) {
267268
fs.writeFileSync(filePath, JSON.stringify(modifiedConfig, null, 2))
268269

269270
vscode.window.showInformationMessage('Codacy MCP server added successfully. Please restart the IDE.')
270-
await createRules(repository)
271+
if (guardrailsOnGeneratedCode === 'enabled') {
272+
await createRules(repository)
273+
}
271274
await installCodacyCLI(repository)
272275
} catch (error: unknown) {
273276
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'

src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ export async function activate(context: vscode.ExtensionContext) {
251251
)
252252

253253
repositoryManager.onDidLoadRepository(async ({ repository }) => {
254-
if (isMCPConfigured()) {
254+
const guardrailsOnGeneratedCode = vscode.workspace.getConfiguration().get('codacy.guardrailsOnGeneratedCode')
255+
if (isMCPConfigured() && guardrailsOnGeneratedCode === 'enabled') {
255256
await createRules(repository)
256257
}
257258
})

src/views/ProblemsDiagnosticCollection.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,15 @@ export class ProblemsDiagnosticCollection implements vscode.Disposable {
104104
})
105105

106106
GitProvider.instance?.onDidChangeTextDocument(async (e) => {
107+
const analysisMode = vscode.workspace.getConfiguration().get('codacy.analysisMode')
108+
107109
// avoid if the document is a .git file
108110
if (e.document.uri.fsPath.endsWith('.git')) return
109111

110112
// update positions of remote issues in the document
111113
this.updateApiIssuesPositions(e.document)
112114

115+
if (analysisMode === 'disabled' || (analysisMode === 'only on saved files' && e.document.isDirty)) return
113116
// run local analysis for available tools
114117
await this.runAnalysisAndUpdateDiagnostics(e.document)
115118
})

0 commit comments

Comments
 (0)