adjust DrRacket to be able to populate the local pkg catalog
database in more convenient ways - add a "update cache" button to online check syntax error message when a missing module exn is raised, but there are no suggestions - add an "update cache" link to the missing module exn printout
This commit is contained in:
parent
ec0053be7f
commit
31e02a5da2
|
@ -28,6 +28,7 @@ profile todo:
|
|||
mrlib/include-bitmap
|
||||
images/compile-time
|
||||
pkg/lib
|
||||
pkg/gui
|
||||
(for-syntax images/icons/misc images/icons/style images/icons/control images/logos)
|
||||
(for-syntax racket/base)
|
||||
(submod "frame.rkt" install-pkg))
|
||||
|
@ -167,7 +168,7 @@ profile todo:
|
|||
(set-flags (cons 'handles-events (get-flags)))))
|
||||
|
||||
(define clickable-image-snip% (clickable-snip-mixin image-snip%))
|
||||
(define clickable-string-snip%
|
||||
(define clickable-string-snip%
|
||||
(class (clickable-snip-mixin snip%)
|
||||
(define/override (get-extent dc x y wb hb db sb lb rb)
|
||||
(define-values (w h d a) (send dc get-text-extent str))
|
||||
|
@ -198,8 +199,22 @@ profile todo:
|
|||
(let ([n (new clickable-string-snip% [str str])])
|
||||
(send n set-callback (get-callback))
|
||||
n))
|
||||
(super-new)))
|
||||
(define/override (write f)
|
||||
(define bts (string->bytes/utf-8 str))
|
||||
(send f put (bytes-length bts) bts))
|
||||
(super-new)
|
||||
(inherit set-snipclass)
|
||||
(set-snipclass clickable-string-snipclass)))
|
||||
(define (set-box/f b v) (when (box? b) (set-box! b v)))
|
||||
(define clickable-string-snipclass
|
||||
(new (class snip-class%
|
||||
(define/override (read f)
|
||||
(define str (bytes->string/utf-8 (or (send f get-unterminated-bytes) #"")))
|
||||
(new clickable-string-snip% [str str]))
|
||||
(super-new))))
|
||||
(send clickable-string-snipclass set-classname "drclickable-string-snipclass")
|
||||
(send clickable-string-snipclass set-version 0)
|
||||
(send (get-the-snip-class-list) add clickable-string-snipclass)
|
||||
|
||||
;; make-note% : string -> (union class #f)
|
||||
(define (make-note% filename bitmap)
|
||||
|
@ -461,28 +476,41 @@ profile todo:
|
|||
(when (exn:missing-module? exn)
|
||||
(define mod ((exn:missing-module-accessor exn) exn))
|
||||
(define pkgs (pkg-catalog-suggestions-for-module mod))
|
||||
(unless (null? pkgs)
|
||||
(display "\n" (current-error-port))
|
||||
(display " packages that provide the missing module:" (current-error-port))
|
||||
(for ([pkg (in-list pkgs)])
|
||||
(eprintf "\n ~a" pkg)
|
||||
(when (port-writes-special? (current-error-port))
|
||||
(define note (new clickable-string-snip% [str "[install]"]))
|
||||
(send note set-callback
|
||||
(λ (snp)
|
||||
;; =Kernel= =Handler=
|
||||
(define admin (send snp get-admin))
|
||||
(define canvas (and admin (send (send admin get-editor) get-canvas)))
|
||||
(define tlw (and canvas (send canvas get-top-level-window)))
|
||||
(install-pkg
|
||||
tlw
|
||||
(lambda (thunk)
|
||||
(parameterize ([error-display-handler drracket:init:original-error-display-handler])
|
||||
(thunk)))
|
||||
#:package-to-offer pkg)))
|
||||
(eprintf " ")
|
||||
(write-special note (current-error-port)))))))
|
||||
|
||||
(define update-pkgs-node (new clickable-string-snip% [str "[update catalog]"]))
|
||||
(define (get-tlw snp)
|
||||
(define admin (send snp get-admin))
|
||||
(define canvas (and admin (send (send admin get-editor) get-canvas)))
|
||||
(and canvas (send canvas get-top-level-window)))
|
||||
(send update-pkgs-node set-callback
|
||||
(λ (snp)
|
||||
(pkg-catalog-update-local/simple-status-dialog
|
||||
#:parent (get-tlw snp))))
|
||||
(cond
|
||||
[(null? pkgs)
|
||||
(when (port-writes-special? (current-error-port))
|
||||
(display "\n no packages suggestions are available " (current-error-port))
|
||||
(write-special update-pkgs-node (current-error-port)))]
|
||||
[else
|
||||
(display "\n packages that provide the missing module:" (current-error-port))
|
||||
(when (port-writes-special? (current-error-port))
|
||||
(display " " (current-error-port))
|
||||
(write-special update-pkgs-node (current-error-port)))
|
||||
(for ([pkg (in-list pkgs)])
|
||||
(eprintf "\n ~a" pkg)
|
||||
(when (port-writes-special? (current-error-port))
|
||||
(define note (new clickable-string-snip% [str "[install]"]))
|
||||
(send note set-callback
|
||||
(λ (snp)
|
||||
;; =Kernel= =Handler=
|
||||
(define tlw (get-tlw snp))
|
||||
(install-pkg
|
||||
tlw
|
||||
(lambda (thunk)
|
||||
(parameterize ([error-display-handler drracket:init:original-error-display-handler])
|
||||
(thunk)))
|
||||
#:package-to-offer pkg)))
|
||||
(eprintf " ")
|
||||
(write-special note (current-error-port))))])))
|
||||
|
||||
;; =User=
|
||||
(define (exn->trace exn)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
(module install-pkg racket/base
|
||||
(require racket/class
|
||||
pkg/gui/main)
|
||||
pkg/gui)
|
||||
(provide install-pkg
|
||||
pkg-manager)
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
"local-member-names.rkt"
|
||||
"rectangle-intersect.rkt"
|
||||
pkg/lib
|
||||
pkg/gui
|
||||
framework/private/logging-timer
|
||||
(submod "frame.rkt" install-pkg))
|
||||
|
||||
|
@ -1246,6 +1247,12 @@
|
|||
(define missing-mods (exn-info-missing-mods error/status-message-str+srcloc))
|
||||
(with-handlers ([exn:fail? (λ (x) '())])
|
||||
(pkg-catalog-suggestions-for-module missing-mods)))))
|
||||
(define has-missing-mods?
|
||||
(for/or ([error/status-message-str+srcloc (in-list error/status-message-strs+srclocs)]
|
||||
#:when (exn-info-missing-mods error/status-message-str+srcloc))
|
||||
(define missing-mods (exn-info-missing-mods error/status-message-str+srcloc))
|
||||
(not (null? missing-mods))))
|
||||
|
||||
(define (combine-msg vec)
|
||||
(define msg (exn-info-str vec))
|
||||
(define stack (exn-info-src-vecs vec))
|
||||
|
@ -1277,7 +1284,7 @@
|
|||
(for/sum ([error/status-message-str+srcloc
|
||||
(in-list error/status-message-strs+srclocs)])
|
||||
(max 1 (length (exn-info-src-vecs error/status-message-str+srcloc))))])
|
||||
install-suggestions)))
|
||||
(and has-missing-mods? install-suggestions))))
|
||||
(define/public (hide-module-language-error-panel)
|
||||
(set! error/status-message-hidden? #t)
|
||||
(update-frame-expand-error))
|
||||
|
@ -1646,21 +1653,34 @@
|
|||
(send expand-error-message set-msgs
|
||||
expand-error-msgs expand-error-msg-is-err? expand-error-msgs+stack)
|
||||
(send expand-error-install-suggestions-panel change-children (λ (l) '()))
|
||||
(for ([suggestion-pkg (in-list expand-error-install-suggestions)])
|
||||
(new button%
|
||||
[parent expand-error-install-suggestions-panel]
|
||||
[callback
|
||||
(λ (_1 _2)
|
||||
(install-pkg
|
||||
(send expand-error-install-suggestions-panel get-top-level-window)
|
||||
(lambda (thunk)
|
||||
(parameterize ([error-display-handler
|
||||
drracket:init:original-error-display-handler])
|
||||
(thunk)))
|
||||
#:package-to-offer suggestion-pkg))]
|
||||
[font small-control-font]
|
||||
[label (format (string-constant install-package-button)
|
||||
suggestion-pkg)]))
|
||||
(when expand-error-install-suggestions
|
||||
(cond
|
||||
[(null? expand-error-install-suggestions)
|
||||
(new button%
|
||||
[parent expand-error-install-suggestions-panel]
|
||||
[callback
|
||||
(λ (_1 _2)
|
||||
(pkg-catalog-update-local/simple-status-dialog
|
||||
#:parent
|
||||
(send expand-error-install-suggestions-panel get-top-level-window)))]
|
||||
[font small-control-font]
|
||||
[label (string-constant update-catalog)])]
|
||||
[else
|
||||
(for ([suggestion-pkg (in-list expand-error-install-suggestions)])
|
||||
(new button%
|
||||
[parent expand-error-install-suggestions-panel]
|
||||
[callback
|
||||
(λ (_1 _2)
|
||||
(install-pkg
|
||||
(send expand-error-install-suggestions-panel get-top-level-window)
|
||||
(lambda (thunk)
|
||||
(parameterize ([error-display-handler
|
||||
drracket:init:original-error-display-handler])
|
||||
(thunk)))
|
||||
#:package-to-offer suggestion-pkg))]
|
||||
[font small-control-font]
|
||||
[label (format (string-constant install-package-button)
|
||||
suggestion-pkg)]))]))
|
||||
(send expand-error-button-parent-panel change-children
|
||||
(λ (l)
|
||||
(list (cond
|
||||
|
|
Loading…
Reference in New Issue
Block a user