Why cursor can't come up with this feature

The cursor is notorious for removing and replacing the code from other blocks unrelated to what we are working on. I have been trying to make a simple change and I am not able to, every time the AI is removing like 500, 300, 200 lines of code, even though I’m writing clearly not to remove the code. It is still removing, not to edit, like very clearly in many different areas of my chat. Is it so difficult for a cursor to come up with the system where it scanned the code and only works with the part that we are working on? I think Klein has something like this right now.

It actually is quite a hard problem.

Here are two ways I’ve worked around this problem:

  1. Get the AI to produce the function or file you’re working on in full:
    • When Cursor only needs to update a function, it has an easier time correctly applying changes without overriding other files
    • o1-mini does a much better job at reproducing a function in full compared to Claude
    • If the AI isn’t producing the full output, try a new chat window, as Claude tends to be more concise (frustratingly so) as conversations progress
  2. Instead of using the apply button:
    • Copy the code block
    • Manually highlight the area of code/function to update
    • Do an inline edit using command/control K
    • Write something like “update the code to the attached code, only adding the new code and leaving all other code the same” (adjust the prompt based on whether you’re creating or replacing code)

In many cases where apply changes hasn’t worked, copying the code block and using command/control K for an inline edit has worked for me.

I hope that helps.

2 Likes

This is very informative information, and I appreciate it. Let me share some tips that worked for me. I’ve noticed the chat interface works better and removes less content compared to the composer, which tends to remove large chunks of code. I’ve also developed a prompt that I add to all my other prompts - it might sound funny, but it’s effective.

“look, this is very, very, very serious instruction for you. You are not allowed to remove a single line of code that is not related. You understand? Do not remove the code. This is the 20th time I’m trying to fix this. You are removing 300 lines of code. Are you serious?”

and somehow it feel threatened and it listens :smiley:

2 Likes

Does your project have .cursorrules?

Yes, I do have Cursor rules and I have Notepad, all of them. But I don’t have a summary about my project that it can go through. But yes, I do have the rules.

Lol, love that :joy:

Here’s a similar line from my Rules For AI that seems to help:

You will be penalised for being lazy. If you are asked to provide a fully coded solution, you must give the code IN FULL without skipping any lines.

Works well in combination with my previous comment in (1) above, prompting the AI to give the entire function (which as mentioned, as a much higher hit rate when applying from chat).

1 Like

We should be able to have direct apply model access

You can use this project of mine to create .cursorrules

My solution, is tell Componser to create you a file “readme-project.md” or something.

Tell it to scan your codebase and summarize the project in detail.

I have done that for the past few projects and it works great! Then as I come up with new features for the project, I tell Composer to “let’s brainstorm” on the ideas and features. After some back and forth, you can proceed to a “Question & Answer” session. Then again, ask Composer to create you a new file “readme-milestones.md”.

I now have at least 6 Composer generated readme files covering various aspects of the project. One of the most important ones is “readme-next-days-agenda.md”, where we keep track of all the tasks and sub-tasks with bullet lists.

If for some reason Cursor/Composer can’t do it well enough for you, use ChatGPT or Claude (web UI) and have at it. Get as detailed and deep as you want. The more, the better! Then drop that into your readme and copy over a generic cursorrules file, and tell Cursor to modify the file for you, works great!

I like to paste in documentation URLs into the cursorrules file to remind the AI to always check the docs, also scan the package.json so it doesn’t try to install something we already have.

Telling Cursor to modify these files really helps!