greghendershott / racket-mode

Emacs major and minor modes for Racket: edit, REPL, check-syntax, debug, profile, packages, and more.
https://www.racket-mode.com/
GNU General Public License v3.0
683 stars 93 forks source link

large json output breaks racket-mode #731

Open samth opened 1 day ago

samth commented 1 day ago

Run the following file (not the main submodule):

;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#lang racket
;#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname 14-bus) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
(require 2htdp/json lang/posn)

(require 2htdp/image)
(require 2htdp/universe)

; read-json/web : String -> JSON
; Retrieves the remote file at the given URL and returns JSON data

; read-json/file : String -> JSON
; Retrieves the local file with the given name and returns JSON data

; web-address : String
; The location of the latest bus data
(define web-address "https://iucbs.etaspot.net/service.php?service=get_vehicles&includeETAData=1&inService=1&orderedETAArray=1&token=TESTING")

; parse : Anything -> JSON
; Ignore the input. Retrieve bus data.
(define (parse whatever)
  #;(read-json/file "/home/ccshan/u/courses/indiana/c211/c211/textfiles/buses1.json")

  (read-json/web web-address))

(define (convert a1 b1 a2 b2 a)
  (/ (+ (* b1 (- a2 a)) (* b2 (- a a1))) (- a2 a1)))
(define background (bitmap/file "iub.png"))
(define width (image-width background))
(define height (image-height background))
(define sprite (circle 2 "solid" "red"))
(define (draw-lop lop)
  (foldr (lambda (p i) (place-image sprite (posn-x p) (posn-y p) i)) background lop))
(define-struct world [xmin xmax ymin ymax])
(define iub-view
  (make-world -86.536 -86.496 39.16 39.19))
(define (cartesian->screen w lop)
  (map (lambda (p) (make-posn (convert (world-xmin w) 0 (world-xmax w) width (posn-x p))
                              (convert (world-ymax w) 0 (world-ymin w) height (posn-y p))))
       lop))
(define (draw lop)
  (draw-lop (cartesian->screen iub-view lop)))
(define sample-bus-posns
  (list
   (make-posn -86.5268283 39.1798933)
   (make-posn -86.5220229 39.1631958)
   (make-posn -86.5013583 39.1760933)
   (make-posn -86.52699 39.1802317)
   (make-posn -86.5162083 39.1680917)
   (make-posn -86.5266717 39.1643233)
   (make-posn -86.518595 39.1686967)
   (make-posn -86.5161778 39.1684192)
   (make-posn -86.527125 39.1809483)
   (make-posn -86.5269733 39.1800917)
   (make-posn -86.5169983 39.1839933)
   (make-posn -86.5212888 39.1716147)
   (make-posn -86.5261614 39.1790335)
   (make-posn -86.5236612 39.1763609)
   (make-posn -86.5200923 39.1642786)
   (make-posn -86.5167244 39.1716118)
   (make-posn -86.5270583 39.1805333)))

; lookup : String [ListOf Member] -> JSON
(define (lookup n lom)
  (cond [(string=? n (member-name (first lom)))
         (member-value (first lom))]
        [else (lookup n (rest lom))]))

; project : JSON -> [ListOf Posn]
(define (project buses)
  (map (lambda (o) (make-posn (lookup "lng" (object-members o))
                              (lookup "lat" (object-members o))))
       (lookup "get_vehicles" (object-members buses))))

(draw sample-bus-posns)
(module+ main
(big-bang empty
  [to-draw draw]
  [on-tick (lambda (w) (project (parse "whatever"))) 5]))

Then run (parse 1).

Then note that there's an error in the REPL, and doing anything results in similar errors. From *Messages*:

{racket-back-end-/-stderr} delete: position is out of bounds
  position: 59219
  upper limit: 51027
  context...:
   /home/samth/sw/racket-mode/racket/text-lines.rkt:48:0: 

{racket-back-end-/-stderr} delete
   /home/samth/sw/racket-mode/racket/hash-lang.rkt:217:5
 [2 times]
Mark set [4 times]
funcall-interactively: Text is read-only [3 times]
Error running timer ‘racket--repl-on-output’: (args-out-of-range 71276 67440)
Error running timer: (args-out-of-range 70520 71278)
{racket-back-end-/-stderr} insert: position is out of bounds
  position: 67452
  upper limit: 67440
  context...:
   /home/samth/sw/racket-mode/racket/text-lines.rkt:32:0: insert
   /home/samth/sw/racket-mode/racket/hash-lang.rkt:217:5

Package

metadata
nil
package-archives
(("elpa" . "https://elpa.gnu.org/packages/")
 ("melpa" . "https://melpa.org/packages/"))
racket--el-source-dir
"/home/samth/sw/racket-mode/"
racket--rkt-source-dir
"/home/samth/sw/racket-mode/racket/"

System values

emacs-version
"29.3"
major-mode
racket-hash-lang-mode
system-type
gnu/linux
x-gtk-use-system-tooltips
t
display-graphic-p
t

Buffer values

after-change-functions
(jit-lock-after-change t racket--xp-after-change-hook racket--hash-lang-after-change-hook)
before-change-functions
(t syntax-ppss-flush-cache)
completion-at-point-functions
(racket-xp-complete-at-point)
eldoc-documentation-function
eldoc-documentation-default
eldoc-documentation-strategy
eldoc-documentation-default
eldoc-documentation-functions
(racket-xp-eldoc-point racket-xp-eldoc-sexp-app t)
font-lock-defaults
(nil t)
pre-command-hook
(eldoc-pre-command-refresh-echo-area t)
post-command-hook
(eldoc-schedule-timer t)
post-self-insert-hook
(racket-hash-lang-post-self-insert t)
xref-backend-functions
(racket-xp-xref-backend-function t)

Racket Mode values

racket--cmd-open-p
t
racket-after-run-hook
nil
racket-back-end-configurations
((:directory "/" :racket-program nil :remote-source-dir nil :restart-watch-directories nil :windows nil))
racket-before-run-hook
(racket-ansi-color-context-reset)
racket-browse-url-function
browse-url-default-browser
racket-command-timeout
10
racket-doc-index-directory
"~/.emacs.d/racket-mode/"
racket-doc-index-predicate-function
always
racket-documentation-search-location
"https://docs.racket-lang.org/search/index.html?q=%s"
racket-error-context
medium
racket-expand-hiding
standard
racket-hash-lang-mode-hook
(racket-xp-mode)
racket-hash-lang-module-language-hook
nil
racket-hash-lang-token-face-alist
((constant . font-lock-constant-face)
 (error . error)
 (other . font-lock-doc-face)
 (keyword . font-lock-keyword-face)
 (hash-colon-keyword . racket-keyword-argument-face)
 (at . font-lock-doc-face))
racket-history-filter-regexp
"\\`\\s *\\'"
racket-imagemagick-props
nil
racket-images-do-not-use-svg
nil
racket-images-inline
t
racket-images-keep-last
100
racket-images-system-viewer
"display"
racket-indent-curly-as-sequence
t
racket-indent-sequence-depth
0
racket-input-prefix
"\\"
racket-input-translations
(("All" "∀")
 ("Union" "U")
 ("Intersection" "∩")
 ("test-->>E" "test-->>∃")
 ("vdash" "⊢")
 ("gg" "≫")
 ("succ" "≻")
 ("times" "×")
 ("Uparrow" "⇑")
 ("Downarrow" "⇓")
 ("Leftarrow" "⇐")
 ("Rightarrow" "⇒")
 ("leftarrow" "←")
 ("rightarrow" "→")
 ("nwarrow" "↖")
 ("nearrow" "↗")
 ("uparrow" "↑")
 ("downarrow" "↓")
 ("searrow" "↘")
 ("swarrow" "↙")
 ("leftrightarrow" "↔")
 ("updownarrow" "⇕")
 ("aleph" "א")
 ("emptyset" "∅")
 ("nabla" "∇")
 ("surd" "√")
 ("negation" "¬")
 ("infinity" "∞")
 ("prod" "∏")
 ("coprod" "∐")
 ("integrate" "∫")
 ("oint" "∮")
 ("vee" "∨")
 ("wedge" "∧")
 ("follows" "∘")
 ("setin" "∈")
 ("ni" "∋")
 ("notin" "∉")
 ("sqsubset" "⊏")
 ("sqsupset" "⊐")
 ("sqsubseteq" "⊑")
 ("sqsupseteq" "⊒")
 ("subset" "⊂")
 ("superset" "⊃")
 ("subseteq" "⊆")
 ("supseteq" "⊇")
 ("approx" "≈")
 ("cong" "≌")
 ("neq" "≠")
 ("sqcap" "⊓")
 ("sqcup" "⊔")
 ("models" "⊧")
 ("alpha" "α")
 ("Alpha" "Α")
 ("beta" "β")
 ("Beta" "Β")
 ("gamma" "γ")
 ("Gamma" "Γ")
 ("delta" "δ")
 ("Delta" "Δ")
 ("epsilon" "ε")
 ("Epsilon" "Ε")
 ("zeta" "ζ")
 ("Zeta" "Ζ")
 ("eta" "η")
 ("Eta" "Η")
 ("theta" "θ")
 ("Theta" "Θ")
 ("iota" "ι")
 ("Iota" "Ι")
 ("kappa" "κ")
 ("Kappa" "Κ")
 ("lambda" "λ")
 ("Lambda" "Λ")
 ("lamda" "λ")
 ("Lamda" "Λ")
 ("mu" "μ")
 ("Mu" "Μ")
 ("nu" "ν")
 ("Nu" "Ν")
 ("xi" "ξ")
 ("Xi" "Ξ")
 ("omicron" "ο")
 ("Omicron" "Ο")
 ("pi" "π")
 ("Pi" "Π")
 ("rho" "ρ")
 ("Rho" "Ρ")
 ("sigma" "σ")
 ("Sigma" "Σ")
 ("tau" "τ")
 ("Tau" "Τ")
 ("upsilon" "υ")
 ("Upsilon" "Υ")
 ("phi" "φ")
 ("Phi" "Φ")
 ("chi" "χ")
 ("Chi" "Χ")
 ("psi" "ψ")
 ("Psi" "Ψ")
 ("omega" "ω")
 ("Omega" "Ω")
 ("digamma" "ϝ")
 ("Digamma" "Ϝ")
 ("san" "ϻ")
 ("San" "Ϻ")
 ("qoppa" "ϙ")
 ("Qoppa" "Ϙ")
 ("sampi" "ϡ")
 ("Sampi" "Ϡ")
 ("stigma" "ϛ")
 ("Stigma" "Ϛ")
 ("heta" "ͱ")
 ("Heta" "Ͱ")
 ("sho" "ϸ")
 ("Sho" "Ϸ")
 ("|A|" "𝔸")
 ("|B|" "𝔹")
 ("|C|" "ℂ")
 ("|D|" "𝔻")
 ("|E|" "𝔼")
 ("|F|" "𝔽")
 ("|G|" "𝔾")
 ("|H|" "ℍ")
 ("|I|" "𝕀")
 ("|J|" "𝕁")
 ("|K|" "𝕂")
 ("|L|" "𝕃")
 ("|M|" "𝕄")
 ("|N|" "ℕ")
 ("|O|" "𝕆")
 ("|P|" "ℙ")
 ("|Q|" "ℚ")
 ("|R|" "ℝ")
 ("|S|" "𝕊")
 ("|T|" "𝕋")
 ("|U|" "𝕌")
 ("|V|" "𝕍")
 ("|W|" "𝕎")
 ("|X|" "𝕏")
 ("|Y|" "𝕐")
 ("|Z|" "ℤ")
 ("|gamma|" "ℽ")
 ("|Gamma|" "ℾ")
 ("|pi|" "ℼ")
 ("|Pi|" "ℿ")
 ("forall" "∀")
 ("exists" "∃")
 ("_0" "₀")
 ("_1" "₁")
 ("_2" "₂")
 ("_3" "₃")
 ("_4" "₄")
 ("_5" "₅")
 ("_6" "₆")
 ("_7" "₇")
 ("_8" "₈")
 ("_9" "₉")
 ("^0" "⁰")
 ("^1" "¹")
 ("^2" "²")
 ("^3" "³")
 ("^4" "⁴")
 ("^5" "⁵")
 ("^6" "⁶")
 ("^7" "⁷")
 ("^8" "⁸")
 ("^9" "⁹"))
racket-logger-config
((racket-hash-lang-mode . debug)
 (racket-mode . debug)
 (cm-accomplice . warning)
 (GC . info)
 (module-prefetch . warning)
 (optimizer . info)
 (racket/contract . error)
 (racket-mode-debugger . info)
 (sequence-specialization . info)
 (* . fatal))
racket-memory-limit
2048
racket-mode-hook
(racket-xp-mode)
racket-module-forms
"\\s(\\(?:module[*+]?\\|library\\)"
racket-pretty-lambda
nil
racket-pretty-print
t
racket-program
"~/bin/racket"
racket-repl-buffer-name-function
nil
racket-repl-command-file
"/home/samth/.emacs.d/racket-mode/repl.rkt"
racket-repl-history-directory
"~/.emacs.d/racket-mode/"
racket-repl-mode-hook
nil
racket-sexp-comment-fade
0.5
racket-shell-or-terminal-function
racket-shell
racket-show-functions
(racket-show-pseudo-tooltip)
racket-smart-open-bracket-enable
nil
racket-submodules-to-run
((test)
 (main))
racket-use-repl-submit-predicate
nil
racket-xp-add-binding-faces
t
racket-xp-after-change-refresh-delay
1
racket-xp-eldoc-level
summary
racket-xp-highlight-unused-regexp
"^[^_]"
racket-xp-mode-lighter
(:eval
 (racket--xp-mode-lighter))

Minor modes

enabled
((auto-composition-mode)
 (auto-compression-mode)
 (auto-encryption-mode)
 (blink-cursor-mode)
 (eldoc-mode)
 (file-name-shadow-mode)
 (font-lock-mode)
 (global-eldoc-mode)
 (global-font-lock-mode)
 (global-paren-face-mode)
 (indent-tabs-mode)
 (line-number-mode)
 (menu-bar-mode)
 (mouse-wheel-mode)
 (override-global-mode)
 (racket-xp-mode)
 (semantic-minor-modes-format)
 (shell-dirtrack-mode)
 (show-paren-mode)
 (tooltip-mode)
 (transient-mark-mode))
Disabled minor modes
disabled
((abbrev-mode)
 (auto-fill-function)
 (auto-fill-mode)
 (auto-save-mode)
 (auto-save-visited-mode)
 (buffer-face-mode)
 (buffer-read-only)
 (button-mode)
 (cl-old-struct-compat-mode)
 (column-number-mode)
 (comint-fontify-input-mode)
 (compilation-minor-mode)
 (compilation-shell-minor-mode)
 (completion-in-region-mode)
 (context-menu-mode)
 (cursor-face-highlight-mode)
 (defining-kbd-macro)
 (diff-auto-refine-mode)
 (diff-minor-mode)
 (electric-indent-mode)
 (electric-layout-mode)
 (electric-pair-mode)
 (electric-quote-mode)
 (global-prettify-symbols-mode)
 (global-semantic-highlight-edits-mode)
 (global-semantic-highlight-func-mode)
 (global-semantic-show-parser-state-mode)
 (global-semantic-show-unmatched-syntax-mode)
 (global-semantic-stickyfunc-mode)
 (global-visual-line-mode)
 (horizontal-scroll-bar-mode)
 (hs-minor-mode)
 (isearch-fold-quotes-mode)
 (isearch-mode)
 (jit-lock-debug-mode)
 (lock-file-mode)
 (lost-selection-mode)
 (next-error-follow-minor-mode)
 (overwrite-mode)
 (paragraph-indent-minor-mode)
 (paren-face-mode)
 (prettify-symbols-mode)
 (racket-hash-lang-repl-mode)
 (racket-input-mode)
 (racket-smart-open-bracket-mode)
 (read-extended-command-mode)
 (semantic-highlight-edits-mode)
 (semantic-highlight-func-mode)
 (semantic-mode)
 (semantic-show-parser-state-mode)
 (semantic-show-unmatched-syntax-mode)
 (semantic-stickyfunc-mode)
 (sh-electric-here-document-mode)
 (shell-highlight-undef-mode)
 (size-indication-mode)
 (tab-bar-history-mode)
 (tab-bar-mode)
 (temp-buffer-resize-mode)
 (text-scale-mode)
 (tool-bar-mode)
 (treesit-explore-mode)
 (treesit-inspect-mode)
 (undelete-frame-mode)
 (url-handler-mode)
 (use-hard-newlines)
 (vc-dir-git-mode)
 (view-mode)
 (visible-mode)
 (visual-line-mode)
 (window-divider-mode)
 (xref-etags-mode))
samth commented 1 day ago

Probably you don't actually need to run the file since the error messages give away the problem.

greghendershott commented 1 day ago

Although I'm unable to reproduce this when the edit buffer is using racket-mode, I can with racket-hash-lang-mode. (This causes the REPL to use racket-hash-lang-mode, as well, for purposes of syntax highlighting and navigating within portions of the REPL.)

Also:

I'm not immediately sure why the backing hash-lang object would be getting bad positions, but I'll investigate...

greghendershott commented 1 day ago

I've spent well over an hour debugging this. It relates to how the "after-change" notifications I get from Emacs, are translated to a "text lines" data structure in the back end. Some of after-change notifications surprise me. Hopefully it will become clearer after I step away from the problem for awhile, then come back...