From afb61944db7a2e0dede0103d96aaaf66b182b8bc Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Wed, 30 Jan 2013 08:39:26 -0600 Subject: [PATCH] bring back the syncheck:add-rename-menu method in a way that preserves backwards compatibility for the drracket/check-syntax library --- collects/drracket/check-syntax.rkt | 1 + collects/drracket/private/syncheck/intf.rkt | 15 +++++- .../private/syncheck/local-member-names.rkt | 1 + collects/scribblings/tools/tools.scrbl | 51 ++++++++++++++----- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/collects/drracket/check-syntax.rkt b/collects/drracket/check-syntax.rkt index a864230980..b517d54d7e 100644 --- a/collects/drracket/check-syntax.rkt +++ b/collects/drracket/check-syntax.rkt @@ -29,6 +29,7 @@ syncheck:add-require-open-menu syncheck:add-docs-menu syncheck:add-id-set + syncheck:add-rename-menu syncheck:add-arrow syncheck:add-tail-arrow syncheck:add-mouse-over-status diff --git a/collects/drracket/private/syncheck/intf.rkt b/collects/drracket/private/syncheck/intf.rkt index 110c9094cb..a23f0409b5 100644 --- a/collects/drracket/private/syncheck/intf.rkt +++ b/collects/drracket/private/syncheck/intf.rkt @@ -13,7 +13,9 @@ syncheck:add-tail-arrow syncheck:add-mouse-over-status syncheck:add-jump-to-definition - syncheck:color-range)) + syncheck:color-range + + syncheck:add-rename-menu)) (define syncheck-text<%> (interface (syncheck-annotations<%>) @@ -36,7 +38,16 @@ (define/public (syncheck:find-source-object stx) #f) (define/public (syncheck:add-background-color source start end color) (void)) (define/public (syncheck:add-require-open-menu source start end key) (void)) - (define/public (syncheck:add-id-set id all-ids new-name-intereferes?) (void)) + (define/public (syncheck:add-id-set all-ids new-name-intereferes?) + (define fst (car all-ids)) + (define src (list-ref fst 0)) + (define sym + (cond + [(syntax? src) (syntax-e src)] + [(object? src) (send src get-text (list-ref fst 1) (list-ref fst 2))] + [else 'just-a-random-guess-as-to-a-good-id])) + (syncheck:add-rename-menu sym all-ids new-name-intereferes?)) + (define/public (syncheck:add-rename-menu sym all-ids new-name-intereferes?) (void)) (define/public (syncheck:add-docs-menu text start-pos end-pos key the-label path definition-tag tag) (void)) (define/public (syncheck:add-arrow start-text start-pos-left start-pos-right end-text end-pos-left end-pos-right diff --git a/collects/drracket/private/syncheck/local-member-names.rkt b/collects/drracket/private/syncheck/local-member-names.rkt index a7120e8fb1..fd01a58d94 100644 --- a/collects/drracket/private/syncheck/local-member-names.rkt +++ b/collects/drracket/private/syncheck/local-member-names.rkt @@ -15,6 +15,7 @@ syncheck:add-require-open-menu syncheck:add-id-set syncheck:add-arrow + syncheck:add-rename-menu syncheck:add-tail-arrow syncheck:add-mouse-over-status syncheck:add-jump-to-definition diff --git a/collects/scribblings/tools/tools.scrbl b/collects/scribblings/tools/tools.scrbl index 84e285560c..52a4e898a9 100644 --- a/collects/scribblings/tools/tools.scrbl +++ b/collects/scribblings/tools/tools.scrbl @@ -621,11 +621,12 @@ Check Syntax is a part of the DrRacket collection, but is implemented via the to @defproc[(make-traversal [namespace namespace?] [path (or/c #f path-string?)]) - (values (->* (syntax?) ((-> (and/c syntax? - (λ (x) - (define lst (syntax->list x)) - (and lst (andmap identifier? lst)))) - void?)) + (values (->* (syntax?) + ((-> (and/c syntax? + (λ (x) + (define lst (syntax->list x)) + (and lst (andmap identifier? lst)))) + void?)) void?) (-> void?))]{ This function creates some local state about a traversal of syntax objects @@ -782,21 +783,42 @@ Check Syntax is a part of the DrRacket collection, but is implemented via the to in @racket[mode]. The mode either indicates regular check syntax or is used indicate blame for potential contract violations (and still experimental). } + @defmethod[(syncheck:add-rename-menu [id symbol?] + [all-ids (listof (list/c (not/c #f) + exact-nonnegative-integer? + exact-nonnegative-integer?))] + [new-name-interferes? (-> symbol boolean?)]) + void?]{ + This method is listed only for backwards compatibility. It is not called directly + by check syntax, but it is called by the default implementation of + @method[syncheck-annotations<%> syncheck:add-rename-menu] in + @racket[annotations-mixin]. + } } +@(define syncheck-example-eval (make-base-eval)) + @defmixin[annotations-mixin () (syncheck-annotations<%>)]{ Supplies all of the methods in @racket[syncheck-annotations<%>] with default behavior. Be sure to use this mixin to future-proof your code and then override the methods you're interested in. - The @racket[syncheck:find-source-object] method ignores its arguments - and returns @racket[#f]; - all of the other methods ignore their arguments and return @racket[(void)]. - - @examples[#:eval (let ([evaluator (make-base-eval)]) - (evaluator '(require drracket/check-syntax)) - evaluator) - (require racket/class) + By default: + @itemlist[@item{The @method[syncheck-annotations<%> syncheck:find-source-object] + method ignores its arguments and returns @racket[#f];} + @item{the @method[syncheck-annotations<%> syncheck:add-id-set] + manufactures a symbol and then passes that and its arguments to + @method[syncheck-annotations<%> syncheck:add-rename-menu] + (this is for backwards compatibility -- the @method[syncheck-annotations<%> syncheck:add-rename-menu] + is not called directly by Check Syntax anymore; the @method[syncheck-annotations<%> syncheck:add-id-set] + calls it instead); and} + @item{all of the other methods ignore their arguments and return @racket[(void)].}] + + Here is an example showing how use this library to extract all + of the arrows that Check Syntax would draw from various + expressions: + @interaction[#:eval syncheck-example-eval + (require drracket/check-syntax racket/class) (define arrows-collector% (class (annotations-mixin object%) (super-new) @@ -838,6 +860,8 @@ Check Syntax is a part of the DrRacket collection, but is implemented via the to (arrows `(λ (,(make-id 'x 1 #t)) x))] } +@(close-eval syncheck-example-eval) + @(define-syntax-rule (syncheck-method-id x ...) (begin @defidform[x]{Bound to an identifier created with @racket[define-local-member-name] @@ -852,6 +876,7 @@ Check Syntax is a part of the DrRacket collection, but is implemented via the to syncheck:add-tail-arrow syncheck:add-mouse-over-status syncheck:add-jump-to-definition + syncheck:add-id-set syncheck:color-range] @subsection{Check Syntax Button}