Skip to content

fix(parametric): write array slider edits back into the array literal - #265

Open
Arthur031221 wants to merge 2 commits into
Adam-CAD:masterfrom
Arthur031221:fix-array-slider-writeback
Open

Arthur031221 wants to merge 2 commits into
Adam-CAD:masterfrom
Arthur031221:fix-array-slider-writeback

Conversation

@Arthur031221

@Arthur031221 Arthur031221 commented Oct 1, 2026 •

Copy link
Copy Markdown

What

Moving a slider for one element of an array parameter (for example size[1] from size = [10, 20, 30];) did nothing: the preview and the saved code stayed the same.

parseParameters splits a numeric array into one slider per element, named size[0], size[1], and so on. updateParameter then searched the code for a line starting with size[1] =, which never exists, so the replace was a no-op.

Fix

For a parameter named name[i], updateParameter now finds name = [...]; and rewrites element i with the new value. The trailing comment is kept. The editor passes the whole parameter list through updateParameter, so the other elements are rewritten from their parsed values (20.0 becomes 20).

Test

src/lib/utils.test.ts parses size = [10, 20, 30]; // [1:100], edits size[1] to 55 and checks the result is size = [10, 55, 30]; // [1:100]. It also covers two edits in sequence, the whole parameter list applied the way changeParameters does 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 first module).

With the change to updateParameter removed (keeping the import type edit below), the array tests fail and the scalar one passes. With it, all eight pass, and the full node --test run passes.

import { Parameter } and import { ModelConfig } in utils.ts became import type, so the file loads under node --test type 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 updates size = [10, 20, 30]; instead of doing nothing.

  • updateParameter rewrites the element in the last unindented, single-line numeric declaration of that name above the first module/function, leaving string arrays, multi-line arrays, indented assignments, and declarations below that point untouched.
  • Trailing comments and other element values are preserved; scalar parameters still work.
  • Adds tests covering sequential edits, the full parameter list, duplicate declarations, and declarations the parser ignores.
  • Switches Parameter and ModelConfig imports in utils.ts to import type so tests load under node --test.

Written for commit 601176a. Summary will update on new commits.

Review in cubic

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.
@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

@Arthur031221 is attempting to deploy a commit to the Adam Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds array element editing to the parameter update system.

No new blocking issue was established, so this PR appears safe to merge.

Summary

The PR makes flattened numeric-array sliders write back to array literals. Since the previous review, it adds parser-aligned declaration selection, removes the new type casts, and expands coverage for duplicate and unsupported declarations.

Reviews (2) · Last reviewed commit: "fix(parametric): edit the array declarat..."

Comment thread src/lib/utils.ts Outdated
Comment thread src/lib/utils.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/lib/utils.ts Outdated
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.
@Arthur031221

Copy link
Copy Markdown
Author

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 parseParameters exposes the element from: unindented, on one line, made only of plain numeric literals, above the first module or function, and long enough to have that element. With size = [1, 2, 3]; followed by size = [4, 5];, editing size[2] changes the first line and size[0] the second. A later string array, an indented assignment, a multi-line array or a declaration below the first module is left alone. Each case has a test.

Type casts: the replacement no longer goes through a callback, so body as string is gone, and the test no longer needs as Parameter because { ...param, value } already has that type. The non-null assertion on the regex match is gone too.

Checks on the new head: src/lib/utils.test.ts passes 8 of 8, and node --test over the five *.test.ts files in the repo passes 34 of 34. I also updated the test paragraph of the PR description, which counted four tests.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant