BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News AI Assistant Comes to ReSharper

AI Assistant Comes to ReSharper

This item in japanese

JetBrains released an AI-powered version of ReSharper, its developer productivity extension for Microsoft Visual Studio. The new version, ReSharper 2023.2, is the first that will 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 questions about programming.

To access the AI-powered features users must log into 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 provider of the large language model (LLM). The assistant does not have access to the source code unless developers include code fragments in their prompts. JetBrains also plans to support local and on-premises models so no data will be sent to the cloud-based LLM providers but the feature set will be rather limited.

The assistant takes into account the language and technologies of the projects and generates properly formatted code snippets. Users can copy and paste the generated code themselves or have the chatbot insert the code in the editor. The assistant also includes several prompts to get started.

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

If developers use 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 code. For example, when asked, "How can I read the 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 code to consume the 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 that the query returns. For each row, it will loop through each field and print the field's name and value.

The assistant also spotted that in the initial code fragment, connection, command and reader are not released, so it refactored the code to make sure they are properly cleaned up:
 


​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 correctly disposed of after use.

ReSharper also supports revisioning the prompts: if the original query needs revising or further information, developers can edit it instead of retyping the whole request. This will create a new chat with the assistant while preserving the original chat too. Furthermore, developers can organize the chats by creating, duplicating, renaming or deleting them.

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

Usually, I don't install beta version but when I saw AI Assistant in ReSharper, I could not resist. My first try was a success! My beloved tool ReSharper gets dramatically better.

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

Ugh, not you too... Come on! Invest in making the dev write *better* code instead of suggesting boiler plate goo that they won't check if it's wrong or not, resulting in crappy code that might succeed the tests but chances are these are generated by the goo generator too...

JetBrains AI assistant shares many commonalities with other AI-powered tools such as GitHub Copilot and Amazon CodeWhisperer but also adds unique features including chat history and accessing the assistant with ALT+Enter, the shortcut for everything.

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

The release also introduced new quick-fixes and inspections for working with discard variables and inlay hints for LINQ queries. When debugging LINQ queries, developers will now see the intermediate output at each step of the query as inlay hints.

About the Author

Rate this Article

Adoption
Style

BT