Feature Request: Refactoring tool
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I would like to have a real refactoring tool for MATLAB like the one e.g. in PyCharm. At the moment I'm using Grep if I'm renaming a Class/Method/Function.
Réponses (7)
Grivault
le 17 Oct 2018
I agree, the lack of this refactoring capability is making Matlab IDE quite outdated face to other IDEs... As it seems to me impossible to develop Matlab with another IDE it makes Matlab also non-competitive and less attractive face to other languages (python, java, C# etc...) Missing syntactic coloration is already from another age, but since it's intrinsic to Matlab we can accept it. Refactoring though is the minima nowadays.
0 commentaires
Adam
le 2 Avr 2019
This is still such a huge frustration all the way into R2019a. Even things that should be so simple can take on epic proportions when it comes to simple changes.
In one of my latest classes I didn't think ahead far enough and named some public functions things like
getData(...)
getScaledData(...)
getTrainingData(...)
Now, of course, a few weeks later I am incorporating a 2nd type of data that I didn't expect originally. So now I have to rename these functions to something more specific than just 'Data'. But they are public functions so I now have to search the whole repository with a Find All. This is not so bad for getTrainingData(...), I don't have many occurences of this, but I have numerous classes with a getData(...) function and loads of places that call it. The class/object of the call gives them their scope so the functions don't need more specific names often.
Except now when I come to have to do a rename and I have to sift through all those cases to make sure I only change those related to the class I am editing.
My design may not be great in terms of having these functions where they are, but isn't that the whole point of refactoring? You don't need to do perfect upfront design, you evolve it as appropriate!
This is one of the most basic tasks of refactoring too. I have no idea how easy or difficult is is for Matlab to link these in an interpreted language, but other languages seem to do it and even Matlab itself I have noticed has improved a lot in terms of its resolution if I 'Go to definition' on a function and it manages to take me to the relevant class.
3 commentaires
Adam
le 8 Avr 2019
Yeah, Ctrl + Shift + F is the method I've always used (it has been around as long as I remember). It helps, but still getting a list of 100+ matches when only 4 of them are related to the specific occurence I want to change makes refactoring a slow risky business!
Frank
le 8 Oct 2018
Dear Don,
Nils asked about refactoring and not how to rename a local variable. The lack of support for refactoring within Matlab is quite annoying.
-Frank
0 commentaires
Keith Nguyen
le 9 Nov 2018
This is true. If I want to rename a function (to give it an easy-to-understand name instead of test(ptcle1,ptcle2). I'll break my program. Is there a way to rename the function across all files in the same project/folder/workspace?
Other features such as: - Changing function signature also change it across all files. - Moving lines up and down using shortcut. - Syntax highlighting.
0 commentaires
Tom Pickering
le 23 Sep 2020
Hi Nils,
if you rename the function name in the function declaration, a tooltip opens. The tooltip indicates that MATLAB will rename all instances of the function in the file when you press Shift + Enter.
In addition to this functioncality in both the classic Editor and the Live Editor, the Live Editor also has some additional refactoring features. If you have an existing large live script or function, you can break it into smaller pieces by automatically converting selected areas of code into functions or local functions. Select one or more lines of code and on the Live Editor tab, in the Code section, click Refactor. Then, select from the available options. MATLAB creates a function with the selected code and replaces the original code with a call to the newly created function.
In Projects, when renaming a function, a dependency analysis is performed, notifying you which files and lines are impacted before you make a change.
3 commentaires
Jared MacDonald
le 10 Nov 2020
Hi Vasco, this is what we are focused on (migrating features from Live Editor to be available for your .M files) and is planned for a near upcoming release.
Thanks,
Jared
Walter Roberson
le 23 Sep 2021
As of R2021b, released today, the old editor is retired and the same editor used for Livescript is used for .m files.
... Unfortunately this does mean that the Fix options that used to be available are mostly gone :(
Don Zheng
le 7 Déc 2016
Hi Nils,
Please find the tutorial below for code refactoring in MATLAB Editor:
https://www.mathworks.com/videos/refactor-code-to-rename-variable-with-with-matlab-editor-97138.html
-Don
2 commentaires
Luke M
le 7 Août 2018
Modifié(e) : Luke M
le 7 Août 2018
I know this is a fairly old question, but I haven't found anything more recent. I think what Nils is looking for is a tool to refactor a project when renaming, as they said, a Class, Method or Function. The tutorial presented is great when working in a single file, but what about when working on a project with many files?
Michael W
le 23 Sep 2021
It seems some added functionality is now available in the editor since release R2021b:
(from the R2021b release notes)
"Break large scripts or functions into smaller pieces by converting selected code into functions in files or local functions. With one or more lines of code selected, on the Editor tab, in the Code section, click the Refactor button, and then select from the available options. MATLAB creates a function with the selected code and replaces the original code with a call to the newly created function."
1 commentaire
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!