This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-03
Channels
- # adventofcode (23)
- # announcements (2)
- # babashka (54)
- # babashka-sci-dev (2)
- # beginners (14)
- # biff (5)
- # calva (25)
- # cherry (9)
- # clj-kondo (4)
- # clojure-europe (2)
- # clojure-japan (2)
- # clojurescript (1)
- # data-science (6)
- # datascript (3)
- # datomic (1)
- # dev-tooling (25)
- # etaoin (5)
- # events (5)
- # hyperfiddle (1)
- # nbb (2)
- # off-topic (27)
- # shadow-cljs (1)
- # xtdb (7)
I'm writing an app that heavily relies on some constants that can easily be assigned colors.
E.g. I have a "high risk" warning specification assigned to a high-risk
name within a let
block.
Is there any way (or could there be a way) to highlight just that high-risk
in just that let
block in a specific color, both the text and its background? Such highlighting should also be a part of the project definition so it could easily be shared with other developers.
In particular it's useful with DSLs. In this particular case, I'm in the process of writing a table matching macro that would be used something like this:
(table-match value1 | value2
;; @formatter:off
| hom-mut | hz | hom-wt | nil
hom-mut | high-risk | high-risk | low-risk-spread | unknown-risk
hz | high-risk | high-risk | low-risk | unknown-risk
hom-wt | low-risk-spread | low-risk | low-risk | low-risk
nil | unknown-risk | unknown-risk | low-risk | unknown-risk
;; @formatter:on
)
In such a table, it would be incredibly useful to immediately see the overall structure by just color, especially if a table gets larger.
If there's no easy way of achieving it, I suppose I should probably take a closer look at Joyride, right?Do you think you could achieve it with regular expressions? If so this extension probably is the answer: https://github.com/fabiospampinato/vscode-highlight
Otherwise Joyride is the best bet, I think. We don't ship rewrite-clj with it yet, but you might get away with including it in your source, I don't remember what dependencies it has...
Maybe there is a way we can get edamame in there, @U04V15CAJ? Would that be useful for things like this?
The vscode-highlight
extension applies regexes globally, right? It's a great start already, especially given that I can use some naming convention to group items together. But ideally coloring would be limited to the scope where a particular colored name exists.
For example:
(let [;; @color:red
high-risk (create-high-risk-warning)]
;; This value is colored in red because of the @ comment above.
high-risk)
;; But this isn't colored.
(def high-risk "high risk")
Feels like it also ties to an ability to have function/macro-specific formatting settings. But I don't recall if there's any tool for that. Which makes me think that coloring can be done not only on a comment basis but also on a factory function basis.It'll not really possible to express scope with a regex, I think... In lack of rewrite-clj or edamame, Calva has API for figuring out some common ranges. https://calva.io/api/#ranges making this at least a bit easier to do. So a Joyride script could use regexes for figuring out where you have those annotations. Then Calva's ranges API for figuring out the scopes. Then VS Code API for coloring things.
@U0ETXRFEW Yes, we can get edamame in there, it costs virtually nothing extra since it's already a dependency
@U0ETXRFEW Also we could include rewrite-clj - maybe figure out how to lazily load stuff using modules
Not sure if edamame helps for the above problem, I've only skimmed it. edamame returns s-expressions, doesn't preserve whitespace and comments
There's a discussion about rewrite-clj here: https://github.com/BetterThanTomorrow/joyride/discussions/88