secture & code

How Cursor can help us in software development

Introduction

The generative AI revolution and its impact on the software world is already a palpable reality. More and more AI-based tools are making developers' lives easier, automating repetitive tasks and optimizing workflows. Although we are not yet in a total transformation of software development, significant steps are being taken, progressively changing the way we consult resources such as Stack Overflow.

In this context, Cursor emerges as one of the most promising solutions. If we visit your home page, we will see that they are presented as a AI editor designed to improve the code development experience. One of its peculiarities is that its interface adapts to the user's preferences: during installation, we can choose between an experience similar to VSCode o IntelliJ, This eases the transition for those already accustomed to these environments.

Basic Cursor functionalities

Cursor offers several features focused on improving developer productivity. Although the platform continues to evolve and more features are likely to be added in the future, these are some of the most prominent and useful from day one:

  • Intelligent autocompleteCursor: Beyond the classic code hints, Cursor allows you to rename variables or methods, automatically detecting all their occurrences in the code and applying changes globally. This eliminates the need for manual searches or tedious refactoring.
  • Assisted code modificationOne of Cursor's most powerful tools is its ability to make changes to specific code fragments. We can ask it to optimize a function, refactor a complex structure or even translate code between different programming languages.
  • Interaction with AI modelsCursor offers two main ways to interact with its AI engine:
    1. From the side panel, where we can ask questions, ask for explanations of code fragments or request the generation of new functions.
    2. Through the floating console, which allows a more dynamic interaction while programming. In both cases, AI not only suggests changes, but also allows us to apply them directly to the code, speeding up the implementation of improvements.
  • Unit test generationWe can ask Cursor to help us to write automated tests for our code, which is especially useful when we need to improve test coverage without investing too much time in writing it manually.
  • Documentation generationif we work on collaborative projects, the generation of documentation is key. Cursor can help document functions, classes or modules following standards such as JSDoc or Docstrings in Python.

Cursor TAB

Cursor TAB is one of the main functionalities provided by Cursor. In this case, as we write code, Cursor will suggest autocompletes and use recent changes to suggest more appropriate changes.

For example, if we are generating methods for array management, if for example we have something like this:

const addItemInArray = (array, item) => {
  array.push(item)
  
  return array
}

If we now start writing something like remov Cursor will understand that we need such a method:

const removeItemFromArray = (array, index) => {
  if (index >=0 && index < array.length) {
    array.splice(index, 1)
  }
  
  return array
}

All this works because Cursor works with the context of what we have written and suggests the changes relative to what we are working on. If we see that the change looks good to us, we will only have to press TAB on our keyboard and everything will be applied.

It is interesting that Cursor allows us to apply the changes line by line. To do this we will have to go to the Cursor configuration and enable it.

Cursor Chat

Perhaps the most interesting feature that Cursor gives us is to be able to talk to the AI model, ask our queries, ask for information or even ask it to explain code or look for bugs or ways to refactor our methods.

We have two options for this, the first is the side panel that appears to the right of the IDE with which we will have a conversation thread with Cursor and will gain context on the questions we ask him. Keep in mind that if we open a new conversation, Cursor can make different suggestions because it may happen that the model finds another way to solve the question. If we stay in the same conversation and we go digging in that conversation, Cursor will use the context of that conversation to continue spinning as we ask it.

image

Another option is to use the code generator below which is opened using a key combination. On Mac we will use CMD + K and on Windows we can use Ctrl + K. This chat works the same as the side chat, it just takes less screen space.

image 1

Using either of the two ways of communicating with the chat, when we ask it to generate code and apply it, we will see how it paints the new lines in green while the old ones remain in red, an aspect very similar to when we see the changes in a Git interface (Github or Gitlab).

Another way to ask Cursor is to ask it to solve something taking into account certain files in our project.

image
 Discover how Cursor, with its AI technology, transforms software development by facilitating tasks such as intelligent auto-completion and code refactoring, optimizing productivity and efficiency.

Cursor context

In order for Cursor's responses to be more appropriate and follow the model of what is already implemented in our project, Cursor performs an indexing of all the files in the project in order to have much more context when responding to us. This can be useful, for example, in a very simple task in which we ask if a variable is being used in several parts of the project in case we want to make a change.

Cursor generates embeddings that help you to make queries much faster and also to know where to refer us to when you find something useful for us.

Conclusions

Cursor is a very powerful tool that can help us in our day to day. Personally, I think it is much more useful for more tedious tasks that usually take a lot of time, such as creating XML files, or mocks for tests or even when we have some dependency errors in the project and we do not know how to solve them.

I think that for more common tasks to develop a new feature it can be good for a skeleton, but we can not rely one hundred percent on the AI because it will make mistakes and we have to review well what it offers us and avoid errors in production.

Do you want to read more posts by David Luque? Here you have all the ones he has written in this blog.

Backend

Picture of David Luque Quintana

David Luque Quintana

The best way to learn to program is to program. I currently work with Ruby and React.
Picture of David Luque Quintana

David Luque Quintana

The best way to learn to program is to program. I currently work with Ruby and React.

We are HIRING!

What Can We Do