Repository navigation
Suggest constructor arguments of generated classes - #929
Draft
ehennestad wants to merge 1 commit into
Draft
ehennestad wants to merge 1 commit into
ehennestad wants to merge 1 commit into
Conversation
ehennestad
added this pull request to stack #928
October 4, 2026 11:40
ehennestad
force-pushed
the
generated-function-signatures
branch
2 times, most recently
from
October 5, 2026 06:40
415d443 to
d90f29d
Compare
MATLAB now suggests the name-value arguments of a generated class
constructor while the user types it, for example the properties of
types.core.TimeSeries after "types.core.TimeSeries(".
file.writeNamespace writes a fragment with one function signature
entry per class into each generated namespace folder. The entry lists
the properties of the class and its superclasses that the constructor
can set. It leaves out read-only properties and properties that hold a
set of typed members, whose members are passed under their own names.
MATLAB reads functionSignatures.json only from the resources folder
next to +types, which in the matnwb root also holds the signatures of
the matnwb functions. The hand-written entries move to
resources/function_templates/functionSignatures.json, and
resources/functionSignatures.json is rebuilt from them and the
fragments whenever classes are generated, copied from the cache or
cleared. The committed file matches the committed classes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ehennestad
force-pushed
the
generated-function-signatures
branch
from
October 6, 2026 18:09
d90f29d to
892d984
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Problem — A user who creates an NWB object by typing a constructor such as
types.core.ElectricalSeries(gets no suggestions for its arguments, and has to look up the property names in the documentation or the class file. MATLAB suggests name-value arguments only for functions listed in afunctionSignatures.jsonfile in theresourcesfolder next to+types. MatNWB's file lists its own functions, such asnwbReadandgenerateCore, but none of the 96 generated classes. The generated constructors takevarargin, so MATLAB has nothing else to suggest from.Solution — Generating classes now also writes a signature entry for each constructor, listing the properties it can set with the description from the schema. MATLAB suggests these names while the user types the constructor call. The entries are rebuilt whenever classes are generated, copied from the cache (#926) or cleared, so they always match the classes on the path.
What changed
generateCore,generateExtension,nwbInstallExtensionornwbRead, MATLAB suggests the name-value arguments of every generated constructor, with the schema description of each.nwbdatainterfaceset ofProcessingModule), because those members are passed under their own names.resources/functionSignatures.jsonlists the committed classes (core 2.11.0, hdmf-common 1.10.0, hdmf-experimental 0.6.0), so suggestions work in a fresh clone without generating anything.nwbClearGeneratedremoves the entries of the classes it deletes.resources/functionSignatures.json, as it changes the files in+types.resources/function_templates/functionSignatures.json. Edits to them go there;resources/functionSignatures.jsonis rebuilt from that file.Implementation notes
file.fillFunctionSignaturecreates one entry per class from the same merged property list thatfile.fillConstructoruses for the help text. The set properties it leaves out are the ones for which the constructor usestypes.untyped.Set()as the default.file.writeNamespacewrites the entries of a namespace to+types/+<namespace>/functionSignatures.fragment.json. The fragment is part of the namespace folder, so the cache from Reuse generated classes from a cache in nwbRead and generateCore #926 stores and restores it with the classes.matnwb.internal.typecache.writeFunctionSignatures(saveDir)rebuildssaveDir/resources/functionSignatures.jsonfrom the fragments, and adds the hand-written entries whensaveDiris the MatNWB root. It combines the files as text, because the hand-written file repeats the keygenerateCoreto declare two signatures, whichjsondecodedoes not keep.resourcesfolder next to the outermost namespace folder, so with a customsavedirthe file is written to<savedir>/resources.Examples
Constructor entries in the signatures file
The snippet counts the constructor entries in the signatures file of the MatNWB root folder and checks for
types.core.TimeSeries.Before — The file lists only MatNWB functions, so MATLAB has no suggestions for generated constructors.
After — Every generated class has an entry: 83 in core, 12 in hdmf-common and 1 in hdmf-experimental.
An entry lists each argument with the schema description that MATLAB shows next to the suggestion. The start of the entry for
ElectricalSeries:How to test
In a fresh MATLAB session with MatNWB on the path, type
types.core.ElectricalSeries(in the editor or the Command Window and press Tab: MATLAB lists the property names. Then run the tests, which check the entries for a small test schema, the file after a cache copy, and the file afternwbClearGenerated:Checklist
fix #XXwhereXXis the issue number?🤖 Generated with Claude Code