AI Assistant comes to ReSharper

JetBrains has released an AI-powered version of ReSharper, its developer productivity extension for Microsoft Visual Studio. The new version, ReSharper 2023.2, is the first to come with AI-powered development assistance.

The early access program version includes a preview version of the AI ​​assistant, a chat intended for programming questions. .NET developers using Visual Studio and ReSharper can use the AI ​​assistant to troubleshoot or refactor existing code, generate code snippets or documentation, and ask general programming questions.

To access AI-powered features, users need to log in to JetBrains AI Services to enable the AI ​​Assistant. When developers use AI features, some contextual information, such as file types, language, and framework used, is shared with the Large Language Model (LLM) vendor. The assistant does not have access to the source code unless developers include code snippets in their prompts. JetBrains also plans to support local and on-premises models, so no data will be sent to cloud-based LLM providers, but the feature set will be quite limited.

The assistant takes into account the language and technologies of the projects and generates correctly formatted code snippets. Users can copy and paste the generated code themselves or have the chatbot enter the code into the editor. The assistant also includes several instructions for getting started.

Below is an example of what the assistant generates when asked “How do I find an element in a sorted array?” one of the prompts included in the assistant:

If the developers use the source code in the prompts, the source code will be sent to the LLM provider and the AI ​​model will be able to generate, explain or document the code. For example, when asked “How can I read values ​​from this query?” with the following code:


var connection = new SqliteConnection("DataSource=:memory:");
var command = connection.CreateCommand();
command.CommandText = "Select * from Item where value > ?";
command.Parameters.Add(4);
var reader = command.ExecuteReader();

The AI ​​assistant generates the code to consume the file reader and explains how it works:



To read the values from the query, you can use the SqliteDataReader 
object that ExecuteReader() returns. 
Here's an example of how you can do this:

while (reader.Read())
{
   for (int i = 0; i < reader.FieldCount; i++)
   {
    Console.WriteLine($"{reader.GetName(i)}: {reader.GetValue(i)}");
   }
}

This code will loop through each row returned by the query. For each row, it will iterate through each field and print the field name and value.

The assistant also noticed that in the initial snippet, connection, command AND reader aren’t released, so he refactored the code to make sure they’re cleaned up properly:



Please note that you should open the connection before executing 
the command and close it after you're done. 
Here's the complete code:

using (var connection = new SqliteConnection("DataSource=:memory:"))
{
  connection.Open();
  using (var command = connection.CreateCommand())
  {
    command.CommandText = "Select * from Item where value > ?";
    command.Parameters.AddWithValue("value", 4);
    using (var reader = command.ExecuteReader())
    {
      while (reader.Read())
      {
        for (int i = 0; i < reader.FieldCount; i++)
        {
          Console.WriteLine($"{reader.GetName(i)}: {reader.GetValue(i)}");
        }
      }
    }
  }
}

This code uses using statements to ensure that the SqliteConnection, SqliteCommand, and SqliteDataReader objects are properly disposed of after use.

ReSharper also supports prompt revision: if the original query needs revision or additional information, developers can edit it instead of retyping the entire request. This will create a new assistant chat while also preserving the original chat. Also, developers can organize chats by creating, duplicating, renaming or deleting them.

The .NET community received the announcement with mixed feelings. Sébastien Lachance, former MVP of Microsoft, said:

I usually don’t install the beta version but when I saw AI Assistant in ReSharper, I couldn’t resist. My first attempt was a success! My beloved ReSharper tool improves dramatically.

Frans Bouma, creator and lead developer of a popular .NET ORM, LLBLGen Pro, was disappointed:

Ugh, not you too… Come on! Invest in having the developer write *better* code instead of suggesting that they won’t check whether it’s wrong or not, resulting in poor code that may pass tests, but those are also likely to be generated by the goo generator. . .

JetBrains AI Assistant shares many commonalities with other AI-powered tools like GitHub Copilot and Amazon CodeWhisperer, but also adds unique features including chat history and ALT+Enter assistant access, shortcut to everything.

AI features are currently limited by the number of users and the countries where the OpenAI service is available. The AI ​​service is free as part of the EAP program and pricing information will be announced at a later date. In addition to ReSharper, the AI-powered assistant will be available in Rider and ReSharper for C++.

The release also introduced new hotfixes and inspections for working with reject variables and inlay hints for LINQ queries. When debugging LINQ queries, developers will now see the intermediate output in each query step as inlay hints.


#Assistant #ReSharper
Image Source : www.infoq.com

Leave a Comment