Feature Request: Refactoring tool

22 ビュー (過去 30 日間)
Nils G
Nils G 2016 年 11 月 21 日
コメント済み: attackers account 2022 年 8 月 11 日
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.
  1 件のコメント
attackers account
attackers account 2022 年 8 月 11 日
"onclick=prompt(8)><image/src/onerror=prompt(1)>"@x.y

サインインしてコメントする。

回答 (7 件)

Grivault
Grivault 2018 年 10 月 17 日
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.

Adam
Adam 2019 年 4 月 2 日
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 件のコメント
Adam
Adam 2019 年 4 月 8 日
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!
per isakson
per isakson 2019 年 4 月 8 日

サインインしてコメントする。


Frank
Frank 2018 年 10 月 8 日
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

Keith Nguyen
Keith Nguyen 2018 年 11 月 9 日
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.

Tom Pickering
Tom Pickering 2020 年 9 月 23 日
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.
Please also check out the Documentation for more info on Find and Replace in Files.
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 件のコメント
Jared MacDonald
Jared MacDonald 2020 年 11 月 10 日
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
Walter Roberson 2021 年 9 月 23 日
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
Don Zheng 2016 年 12 月 7 日
Hi Nils,
Please find the tutorial below for code refactoring in MATLAB Editor:
-Don
  2 件のコメント
Luke M
Luke M 2018 年 8 月 7 日
編集済み: Luke M 2018 年 8 月 7 日
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?
Utku Kaya
Utku Kaya 2021 年 10 月 26 日
編集済み: Utku Kaya 2021 年 10 月 26 日
Agreed. Refactoring still does not work for Classes.

サインインしてコメントする。


Michael W
Michael W 2021 年 9 月 23 日
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 件のコメント
Nikolaus Koopmann
Nikolaus Koopmann 2022 年 1 月 5 日
doesn't work in classes. hence, utterly useless to me :(

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by