How to configure Editor when working on class methods so that I can jump to implementation?
8 views (last 30 days)
Show older comments
I'm working on a small project with only a handful of classes, but there's still enough methods to not keep a complete list in my head for everything. I cannot find a way to efficiently work.
To clarify, assume the following situation:
- I'm working on a file some_methodA.m, which implements method some_methodA() of class A. The path to this file is projectdir/@classA/some_methodA.m
- I want to invoke some_methodB() from class B, which is in projectdir/@classB/some_methodB.m
- I start typing, inside some_methodA.m: b_object.some_methodB(), but then I realize I forgot which arguments some_methodB takes.
- I right-click on some_methodB() and choose "Open some_methodB()" to check (since there's no auto-completion in the editor...!?), but I get an error message saying that some_methodB.m does not exists and if I want to create it.
Note that all the paths I mention are on the MATLAB path.
The root cause of the problem is that the MATLAB editor doesn't know that b_object is an instance of classB, so it doesn't know where to find some_methodB. In my opinion, it should at least suggest that there is a matching function somewhere on my path and suggest opening that one. Yet, it doesn't.
My current way of "working" now is to keep the class definition files open in the editor and, if I'm looking for something, I right-click on the tab for the corresponding, choose "Change current folder to ...", and then open the file that implements the method I'm interested in. Which is totally ridiculous and inefficient.
I cannot imagine working like this on a bigger project, yet I know there are bigger projects being done in MATLAB. So, what am I missing? How can I configure the Editor or path variable or whatever so I can work more efficient?
0 Comments
Answers (2)
Sean de Wolski
on 6 Aug 2018
Edited: Sean de Wolski
on 6 Aug 2018
I usually work in debug mode, either from calling something at the command line or by running a unit test.
You're working on classA.someMethod, but a break point on line 1.
Run the test that calls classA.someMethod or run it directly at command line. Stop in debug mode. You now can see the state of the object as it is when someMethod is called and have access to all private/protected properties or methods. By being in an executed state, MATLAB now knows that objectB is classB.
I'll typically: enter debug mode, write a few lines of code, evaluate it with highlight-run selection to make sure it does what I want, quite debug mode, advance break point, rerun test.
8 Comments
Rik
on 8 Aug 2018
It's not just silly to have to write JSON, it also doesn't seem to work outside of the live editor (and doesn't seem to load the multiple syntaxes correctly).
I'll be posting a question about this when my frustration has become a bit less.
Lucademicus
on 20 Jan 2021
I'm not sure if I correctly interpret your question, but I think I noticed the following behavior.
When I type
instanceOfClassA.someMethod('someinput')
and I want to see the code of someMethod, I usually right click and choose
"open instanceOfClassA.someMethod"
In that case it would say that the method does not exist. Really annoying, as this works with normal functions.
But when I type
someMethod(instanceOfClassA,'someinput')
and if I right click on someMethod and "open someMethod", it does bring me to the correct code.
0 Comments
See Also
Categories
Find more on Software Development Tools in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!