December 18th, 2023

Naming Made Easy: AI-Powered Rename Suggestions

Image SmartRenameNameSuggestions Cropped Ever struggled to name a variable, method, or class—finding that perfect balance between expressiveness and conciseness? You’re not alone. We’ve tackled this universal challenge in the latest Visual Studio Preview via our GitHub Copilot Chat extension (subscription required). Introducing: AI-powered rename suggestions. This feature doesn’t just suggest names; it learns how your identifier is used and your code style to propose identifiers that seamlessly fit into your codebase. It’s like having a dedicated naming expert by your side, enhancing your code while keeping you in the coding flow.

The Power of AI in Naming

Our new feature utilizes AI to analyze your identifier’s current usage and the code’s naming style. By understanding how identifiers are used within your code, it generates a range of expressive name suggestions. Our goal is to help you improve the readability and maintainability of your code, ensuring its longevity and ease of comprehension for years to come.

How It Works

In Visual Studio, simply select any identifier, right-click, and choose Rename (Ctrl+R, Ctrl+R). Click on the rename suggestions button or use the Ctrl+Space shortcut. You will be presented with a list of naming suggestions tailored to the context of your code. Pick the name you like best and press Enter.

Rename Suggestions

Try it out!

This feature uses GitHub Copilot to analyze the code and generate the renaming suggestions. You’ll need an active GitHub Copilot subscription. Ensure you are using Visual Studio 2022 17.9 Preview 3 and update the GitHub Copilot Chat Extension (if it’s already installed). Enable this feature by going to Options > GitHub > Copilot chat > and check the “Enable rename suggestions” option.

Your Feedback Matters

We’d love to hear your thoughts on how this feature impacts your coding workflow. Your feedback is instrumental as we continue to improve the feature and quality of the renaming suggestions provided. Please share your thoughts with us!

We appreciate the time you’ve spent reporting issues/suggestions and hope you continue to give us feedback when using Visual Studio on what you like and what we can improve. Your feedback is critical to help us make Visual Studio the best tool it can be! You can share feedback with us via Developer Community: report any bugs or issues via report a problem and share your suggestions for new features or improvements to existing ones.

Stay connected with the Visual Studio team by following us on YouTube, Twitter, LinkedIn, Twitch and on Microsoft Learn.

15 comments

Discussion is closed. Login to edit/delete existing comments.

  • Suzuki Tomohiro

    I uninstalled Visual Studio 2022 preview once.
    I reinstalled 17.9 Preview 2 and cannot roll back. where is the installer for 17.9 Preview 1?

  • Michael Taylor

    >> Ever struggled to name a variable, method, or class

    Yes I have. But as I teach students new to programming, "if you cannot come up with a descriptive, concise name then you're doing something wrong". Maybe your thing is doing too much (hence not concise) and needs to broken down. Or perhaps you don't fully understand what that thing is and therefore need to reevaluate whether you need it at all. I see bad identifier...

    Read more
    • Dalia Abo SheashaMicrosoft employee Author

      Thanks for sharing your perspective Michael!

      When the idea of this feature was brought up, we were discussing a couple of pain points for our users. The first one was a developer in the process of writing code but doesn’t know what the code will do quite yet so gives their identifiers placeholder names then goes back to refactor after they’re done. Instead of starting from scratch with no ideas, they get a few suggestions...

      Read more
  • Oliver Brendel

    Thank you for explaining this well and giving out the necessary information.

    Looking forward to this in release, as it will render quite a few refactoring plugins redundant 😉

    • Dalia Abo SheashaMicrosoft employee Author

      Thank you for the kind comment Oliver! I hope you find it useful when you get a chance to try it.

  • Baker, Josh

    Why lock this behind GitHub Copilot? IntelliJ offers similar refactoring functionality in their freely available Community Edition. Just seems like a cash grab.

    • Dalia Abo SheashaMicrosoft employee Author

      This feature uses the GitHub Copilot’s model which is powered by OpenAI Codex, a language model specifically trained on code which allows us to offer high quality naming suggestions based on the code flow. Without it, we’d be limited to offering basic name, for example, inferring a name based on the variable type only but not the code logic.

      The basic suggestions offered by IntelliJ are free. However, to get the refactoring functionality using AI Assistant,...

      Read more
  • Dean Peters

    Perhaps down the road, heuristic, team-level fine-tuning via names/identifiers selected? This, perhaps in response to a team or a group of teams on a product, seeking consistency … naming conventions always being a contentious point … specially when standards are set but not met 🙂

  • Andreas Saurwein

    As of this moment, there is no update to the VS 2022 Enterprise preview available, neither for the Copilot Chat extension.

    • Dalia Abo SheashaMicrosoft employee Author

      The feature is available in Visual Studio 17.9 Preview 1. If you’re on the latest Visual Studio preview version and Copilot chat extension, you should see an “Enable rename suggestions” under Options > GitHub > Copilot chat. If you don’t see the option, please let me know.

      • Andreas Saurwein

        Right now I feel dumb. I launched over and over again the release version of VS2022 Enterprise instead of the the preview. doh...
        Anyway, I see the option in the Copilot Chat settings, enabled now.
        But the C# rename Inline UI doesn't even show up (although rename works, and all occurrences of the variable are colored differently), and in the dashboard UI no AI suggestions appear. Rename preview tracking is also working.
        VS2022 Enterprise, preview...

        Read more
      • Dalia Abo SheashaMicrosoft employee Author

        Hey Andreas, Visual Studio 17.9 Preview 3 was released today with a fix to the problem you reported. If you’d like, you can try using the feature and let us know if you run into any problems. Looking forward to hearing your feedback!

      • Dalia Abo SheashaMicrosoft employee Author

        After doing some investigating, it looks like there is an issue in Preview 2 with the rename suggestions and the C# inline UI. We’re working on getting the fix available as soon as we can. Meanwhile, you can use Visual Studio 17.9 Preview 1 if you’d still like to try the feature out or wait until we have a fix available. Thank you for bringing attention to this issue. I sincerely apologize for the inconvenience.

  • David Lowndes

    Is this going to work with the rename in C/C++ projects, or is it only going to be .NET only?

    • Dalia Abo SheashaMicrosoft employee Author · Edited

      Great question! We’re currently working on the support for C/C++ files. We’re hoping to have that available for C/C++ files soon!