Naming Made Easy: AI-Powered Rename Suggestions

Dalia Abo Sheasha

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.


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

  • David Lowndes 0

    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 2

      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!

  • Andreas Saurwein 0

    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 2

      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 0

        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 2.0 (17.9.0) and Copilot Chat 0.1.1986.61475

        • Dalia Abo SheashaMicrosoft employee 2

          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.

        • Dalia Abo SheashaMicrosoft employee 1

          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!

  • Dean Peters 1

    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 🙂

  • Baker, Josh 2

    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 1

      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, you need to pay a subscription fee as well.

      The use of these models can be very helpful because they allow us to do more than we could before but they come at a cost. We’re hoping the productivity gains are worth it for developers.

  • Oliver Brendel 1

    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 0

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

  • Michael Taylor 1

    >> 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 names in cases where people are creating god types, functions that do more than one logical thing or for variables that either aren’t actually needed or are storing stuff that isn’t understood.

    As for consistency, that’s what styling rules are for. We don’t need AI for that, it is already available and it is free. I’m sure some people may find this feature useful but it just seems like it is trying to fix a problem that comes from poorly written code. At that point might as well have the AI write it for you.

    • Dalia Abo SheashaMicrosoft employee 1

      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 to get their creative juices flowing. We saw developers that ended up evaluating the names and choosing their own that combine a few of our suggestions.
      The other case is a legacy codebase that has bad names making the code base hard to maintain and service. This is unfortunately very common as code changes over several years and folks forget to update their identifier names because “it still works”. There are also lots of codebases with no styling rules that developers have to inherit and work with. We’re hoping this would help developers in those cases.

      For students, I think it’s important they learn the skills you’re teaching them. This tool and others assume a certain level of proficiency especially that they’re meant to be more of a “copilot” where the developer is still the pilot and is capable of evaluating the multiple suggestions we offer to choose the highest quality one that works for their code.

  • Suzuki Tomohiro 0

    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?

Feedback usabilla icon