Skip to content

Custom snippet variable interpolation #2769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Apr 10, 2025
Merged

Conversation

PEZ
Copy link
Collaborator

@PEZ PEZ commented Apr 7, 2025

What has changed?

See updated docs. But here's an example:

    {
      "name": "qol: Add Snitch dependency",
      "repl": "clj",
      "snippet": "(require '[clojure.repl.deps :refer [add-libs]])\n\n\n(add-libs '{org.clojars.abhinav/snitch {:mvn/version \"0.1.16\"}})"
    },
    {
      "name": "qol: Evaluate as Snitch defn* ",
      "repl": "clj",
      "snippet": "(require '[snitch.core :refer [defn* defmethod* *fn *let]])\n${top-level-form|replace|^\\(defn-?|(defn*}"
    }

So, the with the first one there is nothing new, but the second one has ${top-level-form|replace|^\\(defn-?|(defn*} which invokes the replace modifier so that the defn form will be evaluated using Snitch's defn* macro.

There is also a pr-str modifier, that doesn't take any argument, which is what fixes #2282.

The syntax is slightly bash inspired, but a bit more verbose in that we use Clojure function names to make the ClojureScript semantics clear.

@djblue, can you check and see if you agree that this fixes the stringify suggestion?

@seancorfield, can you take the VSIX for a spin and make sure your current snippets still work?

@skylize, I believe you once pointed at the lack of usefulness for some of the snippet variables because they are not stringified? Please have a look at the docs and please take the VSIX for a spin.

The VSIX is available on CircleCI, linked in the jobs/test output below. It's in Artifacts in the build step.

My Calva PR Checklist

I have:

  • Read How to Contribute.
  • Directed this pull request at the dev branch. (Or have specific reasons to target some other branch.)
  • Made sure I have changed the PR base branch, so that it is not published. (Sorry for the nagging.)
  • Made sure there is an issue registered with a clear problem statement that this PR addresses, (created the issue if it was not present).
    • Updated the [Unreleased] entry in CHANGELOG.md, linking the issue(s) that the PR is addressing.
  • Figured if anything about the fix warrants tests on Mac/Linux/Windows/Remote/Whatever, and either tested it there if so, or mentioned it in the PR.
  • Added to or updated docs in this branch, if appropriate
  • Tests
    • Tested the particular change
    • Figured if the change might have some side effects and tested those as well.
  • Formatted all JavaScript and TypeScript code that was changed. (use the prettier extension or run npm run prettier-format)
  • Confirmed that there are no linter warnings or errors (use the eslint extension, run npm run eslint before creating your PR, or run npm run eslint-watch to eslint as you go).

Ping @PEZ, @bpringe, @corasaurus-hex, @Cyrik

@PEZ PEZ requested review from bpringe and Copilot April 7, 2025 19:19
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 8 changed files in this pull request and generated no comments.

Files not reviewed (5)
  • shadow-cljs.edn: Language not supported
  • src/cljs-lib/src/calva/interpolate.cljs: Language not supported
  • src/cljs-lib/test/calva/interpolate_test.cljs: Language not supported
  • test-data/.vscode/settings.json: Language not supported
  • test-data/projects/pirate-lang/deps.edn: Language not supported

Copy link

netlify bot commented Apr 7, 2025

Deploy Preview for calva-docs ready!

Name Link
🔨 Latest commit 10e4a1d
🔍 Latest deploy log https://app.netlify.com/sites/calva-docs/deploys/67f7d4266d1f7d0008077713
😎 Deploy Preview https://deploy-preview-2769--calva-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@PEZ PEZ merged commit 6049ce5 into dev Apr 10, 2025
5 checks passed
@PEZ PEZ deleted the custom-snippet-variable-interpolation branch April 10, 2025 15:08
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