Skip to content

Commit ef53788

Browse files
authored
clean: prefer to use Logger (#62)
1 parent 23c0033 commit ef53788

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/commands/configureMCP.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Config } from '../common/config'
66
import { get, set } from 'lodash'
77
import { Repository } from '../api/client'
88
import { installCodacyCLI } from './installAnalysisCLI'
9+
import Logger from '../common/logger'
910

1011
interface Rule {
1112
when: string
@@ -81,7 +82,7 @@ const parseMdcContent = (content: string): RuleConfig => {
8182
try {
8283
return JSON.parse(sanitizeJSON(jsonContent))
8384
} catch (error) {
84-
throw new Error('Invalid JSON content in MDC file')
85+
throw new Error(`Invalid JSON content in MDC file (${(error as Error).message})`)
8586
}
8687
}
8788

@@ -129,11 +130,11 @@ const addRulesToGitignore = (rulesPath: string) => {
129130

130131
if (!existingGitignore.split('\n').some((line) => line.trim() === relativeRulesPath.trim())) {
131132
fs.appendFileSync(gitignorePath, gitignoreContent)
132-
vscode.window.showInformationMessage(`Added ${relativeRulesPath} to .gitignore`)
133+
Logger.appendLine(`Added ${relativeRulesPath} to .gitignore`)
133134
}
134135
} else {
135136
fs.writeFileSync(gitignorePath, gitignoreContent)
136-
vscode.window.showInformationMessage('Created .gitignore and added rules path')
137+
Logger.appendLine('Created .gitignore and added rules path')
137138
}
138139
}
139140
export async function createRules(repository: Repository) {
@@ -156,7 +157,7 @@ export async function createRules(repository: Repository) {
156157
isMdc ? JSON.stringify(newRules, null, 2) : convertRulesToMarkdown(newRules)
157158
}`
158159
)
159-
vscode.window.showInformationMessage(`Created new rules file at ${rulesPath}`)
160+
Logger.appendLine(`Created new rules file at ${rulesPath}`)
160161
addRulesToGitignore(rulesPath)
161162
} else {
162163
try {
@@ -178,15 +179,15 @@ export async function createRules(repository: Repository) {
178179
fs.writeFileSync(rulesPath, convertRulesToMarkdown(newRules, existingContent))
179180
}
180181

181-
vscode.window.showInformationMessage(`Updated rules in ${rulesPath}`)
182+
Logger.appendLine(`Updated rules in ${rulesPath}`)
182183
} catch (parseError) {
183-
vscode.window.showWarningMessage(`Error parsing existing rules file. Creating new one.`)
184+
Logger.error(`Error parsing existing rules file. Creating new one. Details: ${parseError}`)
184185
fs.writeFileSync(rulesPath, JSON.stringify(newRules, null, 2))
185186
}
186187
}
187188
} catch (error: unknown) {
188189
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'
189-
vscode.window.showErrorMessage(`Failed to create rules: ${errorMessage}`)
190+
Logger.error(`Failed to create rules: ${errorMessage}`)
190191
throw error
191192
}
192193
}
@@ -236,7 +237,7 @@ export function isMCPConfigured(): boolean {
236237
const config = JSON.parse(fs.readFileSync(filePath, 'utf8'))
237238

238239
return get(config, ideConfig.configAccessor) !== undefined
239-
} catch (error) {
240+
} catch {
240241
// If there's any error reading or parsing the file, assume it's not configured
241242
return false
242243
}
@@ -279,7 +280,7 @@ export async function configureMCP(repository: Repository) {
279280
const cleanedContent = sanitizeJSON(rawContent)
280281
config = JSON.parse(cleanedContent)
281282
} catch (parseError) {
282-
console.log('Error parsing config:', parseError)
283+
Logger.error(`Error parsing config: ${(parseError as Error).message}`)
283284
// If the existing file is invalid JSON, we'll create a new one
284285
config = {}
285286
}

0 commit comments

Comments
 (0)