I am moving from Neovim to VS Code for my development workflow. In Neovim, I had a lua function to extract information from the function declaration and help me creating docstrings. Hence, I released a small extension to VS Code to do the same:
Basically, you select the text with the function declaration, like:
function my_function(x::Int, y::Int, z::Int = 3; verbose::Bool = false)
and call a command to insert the following snippet:
Where everything between <> are placeholders that you can navigate using TAB. It fits for my development strategy by writing the most annoying part of the documentation following the template I like. Currently, the extension supports only macros and functions but I am planning to support structures as well.
Looks very cool!
DocStringExtensions.jl does a bit of that parsing but I am not a fan of some design choices / limitations there (like not showing default values for keyword arguments if memory serves) so this extension might be useful
This will be awesome! Because 95% of time, I really do not need this kind of configurability. Can the system take all the information, including the variable’s name, or only the variable’s type?
I see! The snippet/tab is not the most useful thing in my workflow, it is the argument / keyword listing with their default values. It is very annoying to add this information following the template in Blue style / Julia official docs.
As you say, if a doctoring begins with a code block, leave it alone.
If a function/method has no docstring, don’t add a docstring. Otherwise the documentation for functions with multiple methods will be extremely long, listing every single method.
If the function is defined as literally function func_name end (no function body), insert its docstring (call it “general docstring”) into other auto-generated docstrings as follows: "$signature\n$general_docstring\n$specific_docstring". The general docstring is supposed to describe the overall purpose of the function ModuleName.function_name.
The function signature should be copied verbatim from the method it belongs to, including keyword arguments, types (possibly auto-minified) and default arguments.
Example “specific docstring”:
# ===== In Distributions.jl =====
"""
Fit a probability distribution via maximum likelihood.
"""
function fit_mle end
# ===== Elsewhere =====
"""
Fits the Student's t distribution using the EM algorithm.
"""
function Distributions.fit_mle(d::TDist, xs::AbstractVector{<:Real})
# code here
end
Example output:
help?> fit_mle(TDist(1.5), [1,2,3])
fit_mle(d::TDist, xs::AbstractVector{<:Real})
Fit a probability distribution via maximum likelihood.
Fits the Student's t distribution using the EM algorithm.
But perhaps such docstrings will be too cluttered. After all, one could just ask for ?fit_mle and get docstrings for all methods, including the one without the body.