sphinx-contrib / matlabdomain

A Sphinx extension for documenting Matlab code
http://sphinxcontrib-matlabdomain.readthedocs.io/
Other
70 stars 45 forks source link

Property getters not rendered #126

Closed cvergari closed 2 years ago

cvergari commented 2 years ago

I am struggling with the documentation of get.property, which do not render correctly. Here is a minimal example from matlabdomain docs:

index.rst:

.. mat:automodule:: code

.. mat:autoclass:: MyHandleClass
    :show-inheritance:
    :members:       

And MyHandleClass.m:

classdef MyHandleClass < handle & my.super.Class   
    properties
        x % a property
    end
    methods 
        function x = get.x(obj)
        % how is this displayed?
            x = obj.x
        end
    end
end

Renders like this:

image

So get.x is not rendered. I gather from the builder's documentation that "how is this displayed?" should show.

I found two ways to make this comment show: one was to remove "get." from the method, and remove "x" from the property list. Of course this would break the Matlab code, but it's just for testing. The second way is to leave "x" among the properties, and substitute "get.x(obj)" with "xy(obj)".

classdef MyHandleClass < handle & my.super.Class

    properties
        x % a property
    end
    methods 
        function x = xy(obj)
        % how is this displayed?
            x = obj.x
        end
    end
end

Which yields:

image

So I have a feeling that the property definition and the methods shadow each other.

Anyway: am I doing something wrong? I would like for both the property definition and the description of the getter method to appear in the documentation.

joeced commented 2 years ago

You are not doing anything wrong. This is by design. MATLAB documentation also works this way.

You can only write a docstring for the property itself.

cvergari commented 2 years ago

Fair enough, thanks for the prompt answer! However...why does get_x() ... how is this displayed? appear in the example of matlabbuilder's documentation? Indeed, how is this displayed?

joeced commented 2 years ago

get_x is not a property getter, that would have been get.x().

cvergari commented 2 years ago

Ok so just to be clear the input function in this documentation and the compiled output do not correspond, right? In that case the example function could be updated to be consistent with the output, because this is exactly what I was trying to achieve, and it sounds like it is not possible:

    properties
       x % a property
    end
    function x = get.x(obj)
    % how is this displayed?
        x = obj.x
    end

immagine

Thanks for the clarification!

joeced commented 2 years ago

Thanks for making me aware of this. The first is actually a bad example, I should clean that up. The second URL is from the original author - and not under my control.

cvergari commented 2 years ago

Thanks to you for maintaining this excellent package! So at the moment, there is no way to document a class property because according to Matlab's design, one should add comment lines above the property definition. This renders in Matlab's help viewer:

classdef MyHandleClass  < handle
    properties
        x

        % y - This is a long documentation for y
        % It should appear both in Matlab's help and in the HTML docs
        % But only the first line appears
        y % another info in y
    end
    methods 
        function x = get.x(obj)
        % how is this displayed
            x = obj.x
        end
    end
end

Matlab's help, when clicking on the property's name: immagine

However, neither the long comment for ynor the comment for xappear in matlabbuilder's output. immagine

joeced commented 2 years ago

Thanks. That feature was also requested in #125 :) . I think this could be next issue to do!