Skip to content

feat: generate rules files when configuring the MCP#46

Merged
alerizzo merged 9 commits intomainfrom
generate-rules-files
Apr 11, 2025
Merged

feat: generate rules files when configuring the MCP#46
alerizzo merged 9 commits intomainfrom
generate-rules-files

Conversation

@nedaKaighobadi
Copy link
Contributor

No description provided.

@codacy-production
Copy link

codacy-production bot commented Apr 11, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.92% 0.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (9e2de19) 3047 509 16.70%
Head commit (762289e) 3225 (+178) 509 (+0) 15.78% (-0.92%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#46) 179 0 0.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@nedaKaighobadi nedaKaighobadi marked this pull request as ready for review April 11, 2025 07:23
@nedaKaighobadi nedaKaighobadi changed the title generate rules files when configuring the MCP feat: generate rules files when configuring the MCP Apr 11, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

fs.writeFileSync(filePath, JSON.stringify(modifiedConfig, null, 2))

vscode.window.showInformationMessage('Codacy MCP server added successfully')
createRules()
Copy link

Copilot AI Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The asynchronous function createRules() is called without awaiting its result in configureMCP. Consider using 'await createRules()' to ensure proper sequential execution and error handling.

Suggested change
createRules()
await createRules()

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, copilot found a good one!

fs.writeFileSync(rulesPath, `${existingContent}\n${convertRulesToMarkdown(newRules, existingContent)}`)
}

vscode.window.showInformationMessage(`Updated rules in ${rulesPath}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if this type of work should be visible to the user or not. Might be a lot of popup appearing. They will have "MCP Setup successfully" and right after something about rules... Maybe we don't need to make this a popup, just add them as Logs? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it being too many popups as well. But at the same time, I think it's better this way since we are modifying a file (two files actually if we count the gitignore) in the user's workspace and it's more transparent this way

})
)

if (isMCPConfigured()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we also check the rules don't previously exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do the check when creating the rules file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it can be improved, I'm working on properly manipulating the text so that the rules are nicely replaced or modified if they exist with different enforcers

Comment on lines +153 to +174
// Add the created file to .gitignore
const relativeRulesPath = path.relative(workspacePath, rulesPath)
const gitignoreContent = `\n\n#Ignore ${currentIDE} AI rules\n${relativeRulesPath}\n`
let existingGitignore = ''

if (fs.existsSync(gitignorePath)) {
existingGitignore = fs.readFileSync(gitignorePath, 'utf8')

if (!existingGitignore.split('\n').some((line) => line.trim() === relativeRulesPath.trim())) {
fs.appendFileSync(gitignorePath, gitignoreContent)
vscode.window.showInformationMessage(`Added ${relativeRulesPath} to .gitignore`)
}
} else {
fs.writeFileSync(gitignorePath, gitignoreContent)
vscode.window.showInformationMessage('Created .gitignore and added rules path')
}
} catch (error: unknown) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'
vscode.window.showErrorMessage(`Failed to create rules: ${errorMessage}`)
throw error
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do have my doubts about this... i see the benefit, yes... but perhaps this should be a user decision. it's not like it has personal things, the content of the file can be used by other developers using cursor/copilot/whatever

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, but at the same time I think it's weird commiting IDE specific files and folders, I think it might end up polluting the workspace. Maybe I'm biased here and added this based on personal preference, but I don't like when I install something in the IDE (which I find to be very personalised to each developer) and it adds stuff that are commitable and then have to go and hide it manually. But I can remove this if we think it's not necessary 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not a blocker, so we can go either with this or without it, and then check the feedback; it's totally out of preference... so I guess that in both cases, we'll be benefiting some and giving work to others.... which group is bigger, who knows 🤷‍♂️

Comment on lines +40 to +42
if (parts.length < 3) {
throw new Error('Invalid MDC file format: missing frontmatter')
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so confused about this..... I trust it has a reason, I'd add a comment in the code making it explicit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, this for the mdc format that cursor rules follow that need to have a 'header' that sets the rule as 'always applying' or if it needs to be applied manually. I will add a comment explaining this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, now that you mention this, for the rule types, instead of "always applying", did you try with "agent rule"? and I'm saying this thinking about the parameters one... but perhaps the other about checking with the CLI should always be there....mmmm... I'm diverging in this comment, but perhaps in the future will be good considering different .mdc files with different scopes (not now)

},
{
when: 'after generating code',
enforce: ['Analyze the code using cli analysis tool and then correct any issues found'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be "using Codacy cli analysis tool" just in case users have other cli analysis tools?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I have changed it. Now it references the exact name of the tool to use

@alerizzo alerizzo merged commit 3c4445c into main Apr 11, 2025
5 checks passed
@alerizzo alerizzo deleted the generate-rules-files branch April 11, 2025 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants