R2018a functionSignatures.json (user function tab complete) not working as documented outside of live-script
Show older comments
In a recent thread, I came across a mention of a new feature in R2018a: tab completion suggestions for user-defined functions. (release notes link to this feature)
I applaud this development. I know I am not the only one complaining that it didn't already exist. So I immediately tried to check it out. I used the guide linked in the release notes, which states: "To experiment with code suggestions, start to call the function from a live script and observe the suggestions."
That suggests that it's also possible to use this outside of live scripts, but they just suggest you use that. I don't appear to be the only one thinking that, as suggested by Sean de Wolski: "While I can't talk about the future, if you look at 18a, there is new infrastructure for adding function signatures for code complete/suggest especially in regards to the live editor."
But I failed to get it to work. In the normal editor I only got the normal header-derived hint, and in the live script I could only get a single input type, instead of the two included in my JSON file. What am I doing wrong? Or is the feature not yet at the level the documentation has us believe? Is this a bug that I should report (there aren't any about this yet)?
(Function header, result in live script, and JSON file below and in zip)
function outfilename=WBM(filename,url_part,varargin)
% syntax:
% outfilename=WBM(filename,url_part)
% outfilename=WBM(___,options)
% outfilename=WBM(___,Name,Value)

.
{
"WBM":
{
"inputs":
[
{"name":"filename", "kind":"required", "type":["char"],
"purpose":"Target file name"},
{"name":"url_part", "kind":"required", "type":["char"],
"purpose":"URL of the file/website"},
{"name":"options", "kind":"ordered", "type":["struct"],
"purpose":"Struct containing the options"}
]
},
"WBM":
{
"inputs":
[
{"name":"filename", "kind":"required", "type":["char"],
"purpose":"Target file name"},
{"name":"url_part", "kind":"required", "type":["char"],
"purpose":"URL of the file/website"},
{"name":"date_part", "kind":"namevalue", "type":["char"],
"purpose":"Partial or complete date of the capture"},
{"name":"tries", "kind":"namevalue", "type":["numeric","numel=3"],
"purpose":"Number of times a [load,save,timeout] is allowed"},
{"name":"verbose", "kind":"namevalue", "type":["numeric","scalar","integer"],
"purpose":"The amount of text displayed"},
{"name":"m_date_r", "kind":"namevalue", "type":["char", "choices={'ignore','warning','error'}"],
"purpose":"Missing date response"},
{"name":"response", "kind":"namevalue", "type":["char"],
"purpose":"Cell with responses"},
{"name":"ignore", "kind":"namevalue", "type":["char"],
"purpose":"HTML error codes to be ignored"}
]
}
}
6 Comments
Ken Atwell
on 9 Aug 2018
Two things to check:
- Be sure that the functionSignatures.json is in the same folder as where your WMB function is located.
- If you have just created this file, you may need to restart MATLAB before it becomes visible. After the restart, you should be able to subsequently update the file without a restart.
Ken Atwell
on 13 Aug 2018
"options" is a catch-all name used to indicate the existence of trailing name/value pairs. I can see how this is confusing in your particular case since you happened to use "options" as a name in your signature too. With the JSON definition you give, I would expect the Live Editor to display to something like the following:

After you enter a few arguments, "options" will still be used to indicate that more name/value pairs are possible:

You've noticed only the Live Editor displays function hints from your JSON definition. Speaking specifically of R2018a, The Command Window and plain-text editor do not get their hints from JSON definitions. While I cannot speak to future plans, I would reasonably expect that, over time, JSON information will be used more broadly. I'll see what can be done to document this more clearly.
However, even in R2018a, your JSON definition will used for the purposes of tab completion, for example:

Does that clarify things a bit?
Rik
on 13 Aug 2018
Ken Atwell
on 14 Aug 2018
Yes, you can see multiple signatures. In your specific case, you would if you rename your "options" argument to something else, say "optionsStruct". You currently see only one line because you'd otherwise get two identical-looking signatures... hardly helpful.
Rik
on 14 Aug 2018
Accepted Answer
More Answers (0)
Categories
Find more on Time-Frequency Analysis 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!