Repository navigation
Highlight p5 keywords for the sketch's p5.js version - #4339
samchinmaya wants to merge 2 commits into
Conversation
Syntax highlighting used a single p5-keywords.js file that was last generated in June 2024, so v2 sketches were missing newer keywords and still highlighted ones removed in v2. Highlighting now uses the same versioned hinter data as autocomplete, chosen by the sketch's p5 version. - Build the highlight keyword sets from p5-hinter-v1/v2 - Remove p5-keywords.js, its update-syntax-highlighting script, and the unused CodeMirror 5 mode that imported it - Add a weekly workflow that runs update-p5-hinter and opens a PR when the p5.js reference changes Fixes processing#3163
|
🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. |
|
Hi @raclim @lindapaiste, I asked to work on #3163 on Sep 28 and opened this before being assigned. Sorry if that was jumping ahead; I'm happy to close it if you'd rather assign the issue to someone else. This follows @raclim's feedback on #3336 that the keywords should be updated periodically rather than on every commit: the workflow here runs weekly (and can be triggered manually), and opens a PR only when the p5.js reference has changed. If it's easier to review, I can split the weekly workflow into a separate PR and keep this one to the syntax highlighting fix. |
|
hi @samchinmaya thank you for the PR! This looks like a good idea, I'll take a closer look in the next couple of days. I'm not sure about adding a workflow but we should definitely update the list for v2. |
|
Sure I appreciate your time to have a look into this |
Issue:
Fixes #3163
Syntax highlighting used a single
client/utils/p5-keywords.js, which was last regenerated in June 2024. Checked against the current p5.js reference, it was missing 110 v2 keywords (e.g.clamp,bezierOrder,fontWidth,OKLCH) and still highlighted 40 names that were removed in v2 (e.g.preload,curveVertex). Autocomplete already uses separate, versioned data (p5-hinter-v1.js/p5-hinter-v2.js) selected by the sketch's p5.js version, but highlighting didn't.Demo:
A new (p5.js 2.x) sketch:
Before:
preloadis still highlighted although it was removed in v2, while the newclampandbezierOrderare not.After:
clampandbezierOrderare highlighted, andpreloadis not.Changes:
p5-hinter-v1/p5-hinter-v2data that autocomplete uses, and chosen byp5Version(falling back to v1 when the version is unknown).p5-keywords.js, itsupdate-syntax-highlightingscript and the unused CodeMirror 5 mode (p5-javascript.js) that imported it are removed, so there is only one source of keyword data to keep updated.p5-hinter-v2.jsfrom the current p5.js reference..github/workflows/update-p5-hinter.yml) that runsnpm run update-p5-hinterand opens a PR when the reference has changed, so the data no longer goes stale. It only runs onprocessing/p5.js-web-editorand can also be triggered manually.p5JavaScript.test.jsfor v1 keywords in a v1 sketch, v2 keywords in a v2 sketch, and the v1 fallback.Difference from my proposal on the issue: I originally suggested generating a separate
p5-keywordsfile per version. Reusing the existing hinter data instead avoids a second generated file and generator script. Happy to change this if you'd prefer the original approach.Needed from maintainers for the workflow: for the workflow to open PRs, the repository setting Settings → Actions → General → "Allow GitHub Actions to create and approve pull requests" has to be enabled.
I have verified that this pull request:
npm run lint)npm run test)npm run typecheck)developbranch.Fixes #123Note on tests: the new tests in
p5JavaScript.test.jspass, as do 64 of 65 suites locally. The one failure,server/models/__test__/user.test.ts, is unrelated to this PR: in my local Docker setup (arm64),mongodb-memory-servercan't download a MongoDB binary. That suite passes in GitHub CI.