Eugleo / magic-racket

The best coding experience for Racket in VS Code
https://marketplace.visualstudio.com/items?itemName=evzen-wybitul.magic-racket
GNU General Public License v3.0
202 stars 28 forks source link

highlighting is incorrect with literal `#\"` #48

Closed dannypsnl closed 2 years ago

dannypsnl commented 3 years ago

Environment

Additional Context

圖片
jryans commented 2 years ago

A related example from Scribble which seems to hit the same issue:

(define (write-string/xml-quote str p [start 0] [end (string-length str)])
  (let loop ([start start])
    (when (< start end)
      (define m (regexp-match-positions #rx"[&<>\"]" str start end p))
      (when m
        (write-string (case (string-ref str (caar m))
                        [(#\&) "&amp;"]
                        [(#\<) "&lt;"]
                        [(#\>) "&gt;"]
                        [(#\") "&quot;"])
                      p)
        (loop (cdar m))))))
image
dannypsnl commented 2 years ago

@Eugleo would you mind giving some hints?

Eugleo commented 2 years ago

Sure. In general, it might be useful to look at the Developer: Inspect Editor Tokens and Scopes command. If you're not sure what a token and a scope is, I recommend giving this article in VSC docs a look.

I found out that the character literals actually work ok when used at top-level, and the causes are different in each case that you presented.

First problem

The problem in @jryans code is the #rx string in which the first \" isn't properly escaped. To fix this, we can add the following pattern to the regexp-string pattern:

"patterns": [
  {
    "include": "#escape-char-base"
  }
]

The same piece of code is in byte strings and normal strings. I'm not sure why I haven't added support for escape characters into regex strings in the first place — maybe I just forgot to do so. Anyway, once I add this, the highlighting in this case is fixed:

CleanShot 2021-12-26 at 10 06 48@2x

Second problem

As for the original problem, I have no idea what's causing it. On my machine, it works fine:

CleanShot 2021-12-26 at 10 11 12@2x

I'm also on MacOS, Racket 8.3, Magic Racket 5.7.1. Please make sure to update your magic racket to the latest version, and also make sure you only have magic racket a no other racket extension installed. If the problem persists, please send me the whole file and also tell me what does the token and scope command show for that problematic piece of code.

Eugleo commented 2 years ago

In the meantime, I will close this issue because I'm unable to reproduce it.

dannypsnl commented 2 years ago

My problem get fixed with Magic-Racket 5.8, thanks