Skip to content

feat(editor): code completion from the SDK; ( writes the required name= parameters - #40

Merged
NiJingzhe merged 1 commit into
devfrom
feat/editor-completion
Oct 13, 2026
Merged

NiJingzhe merged 1 commit into
devfrom
feat/editor-completion

Conversation

@NiJingzhe

Copy link
Copy Markdown
Collaborator

Why

The cell editor had no completion for the SDK: it is plain CodeMirror with the stock Python language support, which only knows Python keywords and names already in the file. scad. is a runtime module, so nothing listed its functions, and a call's parameters had to be looked up elsewhere.

What

  • GET /api/sdk (editor/apiindex.py): the running package's public API as data (name, kind, parameters with required/optional/*args/default, first docstring paragraph), read with inspect so it cannot drift from the code. Namespaces: scad, scad.ql, scad.std.<module>. About 100 KB (20 KB gzipped), fetched once.
  • editor-web/src/lib/sdk-complete.ts (CodeMirror):
    • scad., scad.ql., scad.std.gear., ql. / Q. list functions with their signature; the side panel shows every parameter with its default and the docstring.
    • Accepting a function, or typing ( after a known name, writes the call with every required parameter as name= placeholders: scad.make_box_rsolid(width=, height=, depth=). Tab moves to the next parameter (and accepts a highlighted suggestion first). Positional-only and *args parameters get a hint placeholder.
    • Inside a call, the parameters not given yet complete as name= (required first, above Python's builtins).
    • Accepting a completion on a name that already has parentheses changes only the name.
  • A bug that made snippets unusable: the editor wrapper rebuilt its CodeMirror configuration on every render (a fresh onChange and basicSetup object each time), which drops a snippet in progress. Both are stable now (CellEditor, ModuleView).
  • Popup styled for both themes.

Checked

  • test/test_editor.py (new ApiIndexTest: required parameters, *args, classes without private fields, namespaces, the endpoint): 43 passed.
  • In the real editor, with a browser: scad.make_box_r + Tab -> width=, height=, depth=, then 10 Tab 20 Tab 30 -> width=10, height=20, depth=30; scad.fillet_rsolid( typed by hand -> solid=, edges=, radius=; scad.ql.fac and scad.std.gear.make_sp list the right names; , bo after the required parameters offers bottom_face_center= first; accepting on an existing call changes only the name; dark and light.

Not covered

  • Methods on values (selector.where(...)) and variables are not completed; only names reached through scad, scad.ql/ql/Q and scad.std.<module>.
  • The notebook may import the SDK under another alias; only scad, ql and Q are recognized.

… writes the required name= parameters, Tab moves between them

- GET /api/sdk: the running package's public API (names, parameters, which are required, summaries)
  from inspect, for scad, scad.ql and scad.std.<module>
- editor-web/src/lib/sdk-complete.ts: member completion (scad., scad.ql., ql., Q.), snippet on accepting
  a function or typing ( after a known name, name= completion inside calls (required first, above
  Python's builtins), Tab accepts a suggestion and then moves between parameters
- the editor wrapper rebuilt its configuration on every render (new onChange / basicSetup each time),
  which drops a snippet in progress; both are stable now
- popup styled to the editor's themes

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@NiJingzhe
NiJingzhe merged commit b8bf734 into dev Oct 13, 2026
5 checks passed
NiJingzhe added a commit that referenced this pull request Oct 13, 2026
The completion entry (#40) had landed in the 2.2.1 section; both entries are under
Unreleased now, with the editor-configuration fix.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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