Skip to content
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

support string interpolation syntax highlighting (and maybe even linting) #443

Closed
alidcast opened this issue Oct 30, 2019 · 8 comments
Closed
Labels
help wanted Extra attention is needed

Comments

@alidcast
Copy link

alidcast commented Oct 30, 2019

for example, in the snippet below, it'd be great if name could have the same syntax highlighting as other variables:

(ns example) (:require [clojure.core.strint :refer [<<]]))

(defn print-my-editor [name] (println (<< "My go to editor is ~{name}")))

(print-my-editor "Calva")

taking this a step further, it'd be great if there was a config that allowed us to extend the string interpolation syntax highlighting for custom formats, based on the symbol that is calling it.

i.e. for graphql

(gql "query Users { users: [User]! }")

or for sql

(sql "select * from users")

currently apollo supports this for gql string literals in apollo-vscode

another example is styled-components which supports this for css string literals in their vscode-styled-components

this would go a long way in integrating Clojure with other languages, since one of the main reason for converting everything into maps and edn formats seems to be lack of editor support

@PEZ PEZ added enhancement help wanted Extra attention is needed labels Oct 30, 2019
@PEZ
Copy link
Collaborator

PEZ commented Oct 30, 2019

I've totally missed <<. That's a good find!

I think this could prove a bit tricky. But there are ways to allow for subsyntaxes in the tmLanguage definitions... So for instance I think it might be possible to include the clojure syntax inside those ~{}. And gql syntax inside that string, maybe. I wonder if there are any tmLanguage experts out there that could help take a look at it.

@alidcast
Copy link
Author

alidcast commented Oct 30, 2019

with JS I used string interpolation a lot, so it was one of the first things I looked for in Clojure 😅 I much prefer to write out gql and sql queries in their native string format, so would be great to have editor support!

why do you think it would not be possible if there's already working solutions with js string interpolation? for example, here's how gql queries look like for me using apollo-vscode:

Screen Shot 2019-10-30 at 5 37 36 PM

what's even cooler is it integrates with eslint and so it is also able to use the graphql schema to pick up errors if you try to use a property that doesn't exist, etc.

@alidcast
Copy link
Author

alidcast commented Oct 30, 2019

it'd be great if Calva could provide a basic interface for interpolation highlighting/lighting that could be extended for custom formats (i.e. i'd be cool if the sql string could have auto-completion!) - but haven't created a vscode extension so not even sure if that's possible

@PEZ
Copy link
Collaborator

PEZ commented Oct 31, 2019

why do you think it would not be possible if there's already working solutions with js string interpolation?

I didn't say not possible. 😄 I just don't think it is easy. But might be not so hard for someone who's experienced with tmLanguage grammar.

To make it user extendible is probably in the very tricky realm, however.

@jwhitlark
Copy link

It's from a library, though, right? Considering it's age, I don't think it's seriously proposed for inclusion in Clojure.
That makes me think that this specific syntax highlighting should be added in a separate extension.

@bpringe
Copy link
Member

bpringe commented Nov 25, 2020

What is <<? I can't find it anywhere.

@alidcast
Copy link
Author

feel free to close this issue - opened it when I was learning Clojure since I used string interpolation a lot coming from JS, but just had to relearn some habits :)

@bpringe looks like it's in clojure core.incubator: https://clojure.github.io/core.incubator/clojure.core.strint-api.html

@bpringe
Copy link
Member

bpringe commented Nov 26, 2020

Thanks for the info! Learned something new 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants