BetterThanTomorrow / calva

Clojure & ClojureScript Interactive Programming for VS Code
https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva
Other
1.67k stars 217 forks source link

Incorrect syntax highlighting for closing bracket character literal #2037

Open skylize opened 1 year ago

skylize commented 1 year ago

Several examples of character literals colored as invalid syntax.

The primary symptom is a square closing bracket char literal \] colors as invalid.

;; The ] is marked as invalid.
\]

But in some contexts, the ] in \] is interpreted as closing an earlier bracket, with the bracket that actually closes the form being marked invalid instead.

;; First ] is marked as punctuation instead of char.
;  Second ] is marked invalid.
[\]]

One case found so far where the character literal is not \], but the expression needs to have a ] in it to trigger the bug.

;; First `)` is marked as punctuation, instead of char.
;; All of [ , ] , and final ) are marked invalid.
([\)])

;; We can ignore the arity lint error here, as this is still
;  syntactically valid and generalizes the cases of
(foo-fn [\)])
;  and
([\)] 0)
PEZ commented 1 year ago

Thanks for reporting! Does this affect other bracket types, besides ]?

skylize commented 1 year ago

~No other bracket types found so far, except that the character literal itself in the last example is a closing paren, with the square bracket only playing a supporting role.~

All bracket types are fully in play.

\)  ; 💣
\}  ; 💣
\]  ; 💣
PEZ commented 1 year ago

That makes more sense, actually. Haven't tested myself yet, but I now expect \[ and friends to also cause troubles for the highlighting.

The structural editing seems to handle these escaped characters, right? Maybe we can make the highlight module lean more on the tokenization used for there. I thought we already did, but apparently not.