racket / drracket

DrRacket, IDE for Racket
http://www.racket-lang.org/
Other
445 stars 93 forks source link

Eliminate #t return value for drracket:grouping-position? #535

Closed greghendershott closed 2 years ago

greghendershott commented 2 years ago

The new drracket:grouping-position is documented to allow returning #t to mean "use s-expression grouping".

But that slightly predates the availability of syntax-color/racket-navigation. Given that, a lang that wants sexpr nav could instead:

Otherwise users of this (tools) will need to do things like this:

         (let loop ([pos pos]
                    [count count])
           (match (with-semaphore tokens-sema
                    (with-semaphore parens-sema
                      (match (grouping-position this pos limit dir)
                        ;; Handle case where it returns #t, meaning
                        ;; "use default s-expr grouping". That spec
                        ;; slightly predates the addition of
                        ;; syntax-color/racket-navigation --- the
                        ;; availability of which probably means that
                        ;; this #t value should no longer be returned?
                        ;; In other words, if a lang wants s-expr nav,
                        ;; its lang info should either not supply any
                        ;; drracket:grouping-position at all, or,
                        ;; return racket-grouping-position as that?
                        [#t
                         (when (equal? grouping-position racket-grouping-position)
                           (error 'grouping "racket-grouping-position returned #t"))
                         (racket-grouping-position this pos limit dir)]
                        [v v])))
             [#f #f]
             [(? number? new-pos)
              (cond [(< 1 count) (loop new-pos (sub1 count))]
                    [(= new-pos pos) #f]
                    [else new-pos])]))

Which seems slightly tricky/weird.

TL;DR: I propose eliminating the #t return value from the contract and documentation, and, adding a mention or link to racket-grouping-position.