question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change file name when change class name

See original GitHub issue

Every time that I want to refactor a name of a class in my code I need to change the class name and also change the file name. I think this is a waste of time to change the name of the same thing twice, this is an another step to make refactor harder. For example, I have a class that have the name of NodeKey and I want to change the class name to FileKey I need to change the class name and the file name from node_key.dart to file_key.dart.

I thing that this process need to be automated and it will same time for many users and make refactoring easier. On Change Symble that change class name the extension will check if the file name have the same name as the changed class name (taking into consideration the name conventions of UpperCamelCase for class names and lowercase_with_underscores for file names) and if they have the same name change also the file name to the new name (with the name conventions).

Alternative solutions are: use existing extensions that does it, if you know any, or this is already possible in this extension and I don’t know about it or make a new extension that does it.

I will be happy to implement this if it is possible 😃 If possible you know any file/files you think that I need to change to make this feature?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
DanTupcommented, Sep 6, 2021

This works is complete but requires two things to use it:

  1. The next release of Dart-Code (likely early next month)
  2. An updated Dart SDK that includes https://github.com/dart-lang/sdk/commit/3aa464af26a4467d3977150108c1a9c7b0b1a53a (I believe this will be v2.15, but it may be some way off release)

It’s off by default but can be turned on with the dart.renameFilesWithClasses setting (which can be "never", "prompt" or "always").

If you want to try it before them, you can manually add the setting to your VS Code settings (ignore that VS Code says it doesn’t exist):

"dart.renameFilesWithClasses": "prompt"

And use a bleeding edge SDK build (not recommended for general dev, stick to stable!):

https://dart.dev/tools/sdk/archive#main-channel-url-scheme

0reactions
jacobggmancommented, Sep 8, 2021

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

rename class with file name in one step in Visual Studio
The quick solution is to copy the file (I use ctrl+drag) into a nearby folder, rename, then move it back. Another option (which...
Read more >
Change File Name To Class Name : Path « File Input Output «
import java.text.NumberFormat; · import java.util.regex. · class Utilities { /** * Change the passed file name to its corresponding class name. E.G. ·...
Read more >
File Renaming & Class Name Refactor - Visual Studio Feedback
I mainly work in core projects. I use [F2], on a file to rename it. I then change the name, hit [enter] to...
Read more >
Refactor: renaming file name results in renaming my class name
I want to rename the file MyCar.cpp to my_car.cpp and I did it using Refactor -> Rename ( or using Shift+F6). It works...
Read more >
Best Way To Change Class Name (including filename, etc)
It seems whenever I need to change a class name, ... For example, I changed ARealLifeCharacter to ADefaultCharacter, file names went from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found