Skip to content
111 changes: 51 additions & 60 deletions drracket/gui-debugger/debug-tool.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,32 @@

;; DrRacket's debugging tool

(require racket/function
racket/list
(require (for-syntax images/icons/arrow
images/icons/control
images/icons/style
images/icons/symbol
images/icons/tool
pict
racket/base
racket/class
racket/draw)
drscheme/tool
framework
images/compile-time
lang/debugger-language-interface
mrlib/close-icon
mrlib/switchable-button
racket/class
racket/unit
racket/contract
racket/match
racket/function
racket/gui
drscheme/tool
"marks.rkt"
mrlib/switchable-button
mrlib/close-icon
racket/list
racket/match
racket/unit
string-constants
"annotator.rkt"
"load-sandbox.rkt"
framework
string-constants
lang/debugger-language-interface
images/compile-time
framework
(for-syntax racket/base
racket/class
racket/draw
images/icons/arrow
images/icons/control
images/icons/style
images/icons/symbol
images/icons/tool
pict))
"marks.rkt")

(provide tool@)

Expand Down Expand Up @@ -77,9 +76,7 @@
(and (syntax? stx) (syntax-source stx)))

(define (robust-vector-ref vec idx)
(if (< idx (vector-length vec))
(vector-ref vec idx)
#f))
(and (< idx (vector-length vec)) (vector-ref vec idx)))

(define (safe-vector-set! vec idx val)
(when (< idx (vector-length vec))
Expand All @@ -98,11 +95,10 @@

(define (index-of chr str)
(let loop ([i 0])
(if (< i (string-length str))
(if (char=? chr (string-ref str i))
i
(loop (add1 i)))
#f)))
(and (< i (string-length str))
(if (char=? chr (string-ref str i))
i
(loop (add1 i))))))

(define (safe-min . args)
(apply min (filter identity args)))
Expand All @@ -113,23 +109,17 @@
;; really-long-identifier => really-lon...
;; (<form>) => (<form>)
;; (<form> <arg1> ... <argn>) => (<form> ...)
(define trim-expr-str
(lambda (str [len 10])
(let* ([strlen (string-length str)]
[starts-with-paren (and (> strlen 0)
(char=? (string-ref str 0) #\())]
[len2 (+ len 4)]
[trunc-pos (safe-min (index-of #\space str)
(index-of #\newline str)
(and (> strlen len2) len)
strlen)])
(if (>= trunc-pos strlen)
str
(string-append
(substring str 0 trunc-pos)
(if starts-with-paren
" ...)"
" ..."))))))
(define (trim-expr-str str [len 10])
(let* ([strlen (string-length str)]
[starts-with-paren (and (> strlen 0) (char=? (string-ref str 0) #\())]
[len2 (+ len 4)]
[trunc-pos (safe-min (index-of #\space str)
(index-of #\newline str)
(and (> strlen len2) len)
strlen)])
(if (>= trunc-pos strlen)
str
(string-append (substring str 0 trunc-pos) (if starts-with-paren " ...)" " ...")))))

(define (average . values)
(/ (apply + values) (length values)))
Expand Down Expand Up @@ -157,19 +147,20 @@
(truncate-value (vector-ref v i) size (sub1 depth)))))]
[else v]))

(define filename->defs
(lambda (source [default #f])
(let/ec k
(cond
[(is-a? source editor<%>) source]
[else
(send (group:get-the-frame-group) for-each-frame
(lambda (frame)
(and (is-a? frame drscheme:unit:frame<%>)
(let* ([defss (map (lambda (t) (send t get-defs)) (send frame get-tabs))]
[defs (findf (lambda (d) (send d port-name-matches? source)) defss)])
(and defs (k defs))))))
default]))))
(define (filename->defs source [default #f])
(let/ec
k
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorawee this is an unfortunate newline, I'd say. Better if let/ec always put the identifier on the same line and then to inside the let/ec isntead of to the start of the identifier. Is that possible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Currently the let/ec call is treated like a function application. It would be easy to instruct that it's a special form, which needs to be formatted differently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by sorawee/fmt#83. @jackfirth is there a way to re-run this PR with the latest fmt?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like #709 took care of it.

(cond
[(is-a? source editor<%>) source]
[else
(send (group:get-the-frame-group)
for-each-frame
(lambda (frame)
(and (is-a? frame drscheme:unit:frame<%>)
(let* ([defss (map (lambda (t) (send t get-defs)) (send frame get-tabs))]
[defs (findf (lambda (d) (send d port-name-matches? source)) defss)])
(and defs (k defs))))))
default])))

(define (debug-definitions-text-mixin super%)
(class super%
Expand Down