Repository navigation
fix(parametric): write array slider edits back into the array literal - #265
Arthur031221 wants to merge 2 commits into
Conversation
Parameters such as size[1] come from parsing 'size = [10, 20, 30];' but updateParameter looked for a literal 'size[1] = ...' line, so moving one of those sliders changed nothing in the code. Replace the matching element of the array instead.
|
@Arthur031221 is attempting to deploy a commit to the Adam Team on Vercel. A member of the Team first needs to authorize it. |
|
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
parseParameters exposes an array element from the last unindented, single line, numeric declaration of a name above the first module or function that has that element. Write array element edits back to that declaration instead of the first match, and leave string arrays, indented assignments, multi-line arrays and declarations below the first module or function alone. The replacement no longer relies on type casts.
|
Thanks for the review. Both findings were right, and I pushed a follow-up commit. Duplicate declarations: an array edit now goes to the last declaration of the name that Type casts: the replacement no longer goes through a callback, so Checks on the new head: |
What
Moving a slider for one element of an array parameter (for example
size[1]fromsize = [10, 20, 30];) did nothing: the preview and the saved code stayed the same.parseParameterssplits a numeric array into one slider per element, namedsize[0],size[1], and so on.updateParameterthen searched the code for a line starting withsize[1] =, which never exists, so the replace was a no-op.Fix
For a parameter named
name[i],updateParameternow findsname = [...];and rewrites elementiwith the new value. The trailing comment is kept. The editor passes the whole parameter list throughupdateParameter, so the other elements are rewritten from their parsed values (20.0becomes20).Test
src/lib/utils.test.tsparsessize = [10, 20, 30]; // [1:100], editssize[1]to 55 and checks the result issize = [10, 55, 30]; // [1:100]. It also covers two edits in sequence, the whole parameter list applied the waychangeParametersdoes it, a scalar parameter as a control, and arrays that are declared more than once, including declarations of different length, and declarations the parser does not expose (string arrays, indented assignments, multi-line arrays, declarations below the firstmodule).With the change to
updateParameterremoved (keeping theimport typeedit below), the array tests fail and the scalar one passes. With it, all eight pass, and the fullnode --testrun passes.import { Parameter }andimport { ModelConfig }inutils.tsbecameimport type, so the file loads undernode --testtype stripping.Summary by cubic
Fixes array slider edits not writing back to the code, so moving a slider for an element like
size[1]now updatessize = [10, 20, 30];instead of doing nothing.updateParameterrewrites the element in the last unindented, single-line numeric declaration of that name above the firstmodule/function, leaving string arrays, multi-line arrays, indented assignments, and declarations below that point untouched.ParameterandModelConfigimports inutils.tstoimport typeso tests load undernode --test.Written for commit 601176a. Summary will update on new commits.