racket-mode icon indicating copy to clipboard operation
racket-mode copied to clipboard

Extraneous "no bound occurrences" and `racket-xp-unused-face`

Open greghendershott opened this issue 2 years ago • 2 comments

Capturing from Racket Slack (before it scrolls off into unpaid history there):


badkins Nov 19th at 5:00 PM I'm seeing an oddity with Racket-XP mode. There are some lines that appear, and when I hover over them, the tooltip "no bound occurrence" is displayed, but the lines don't appear to be associated with any code. For example below. Does anyone else have these lines? image 36 replies

greg 3 days ago If you move point to one of those areas and do C-u C-x = (which is Emacs what-cursor-position with the detail flag true) it will open a Help buffer showing information. I'd be curious what that shows, especially the end of the buffer starting with There are text properties here:.

greg 3 days ago Or actually maybe the entire buffer, since I'm curious what exactly is that hyphen-like character.

greg 3 days ago Oh the strikeout character would be from racket-xp-unused-face. So the question is just why is it highlighting those intervals as an unused binding.

greg 3 days ago Sometimes I see an artifact if I'm making many quick edits in a row, not just typing, but cutting/pasting, and the artifact is until the idle timer refresh catches up with the changes. If you C-c # g a.k.a. M-x racket-xp-annotate do the artifacts go away? (edited)

badkins 3 days ago C-u C-x = resulted in:

             position: 14 of 1037 (1%), column: 0
            character: C-j (displayed as C-j) (codepoint 10, #o12, #xa)
              charset: ascii (ASCII (ISO646 IRV))
code point in charset: 0x0A
               script: latin
               syntax: > 	which means: endcomment
             to input: type "C-x 8 RET a" or "C-x 8 RET LINE FEED (LF)"
          buffer code: #x0A
            file code: #x0A (encoded by coding system utf-8-unix)
              display: by this font (glyph code)
    mac-ct:-*-Monaco-normal-normal-normal-*-12-*-*-*-m-0-iso10646-1 (#x02)

Character code properties: customize what to show
  old-name: LINE FEED (LF)
  general-category: Cc (Other, Control)

There is an overlay here:
 From 13 to 15
  face                 racket-xp-unused-face
  insert-behind-hooks  (racket--modifying-overlay-deletes-it)
  insert-in-front-hooks (racket--modifying-overlay-deletes-it)
  modification-hooks   (racket--modifying-overlay-deletes-it)
  priority             0


There are text properties here:
  fontified            t
  help-echo            "no bound occurrences"

badkins 3 days ago or

             position: 48 of 1037 (5%), column: 0
            character: SPC (displayed as SPC) (codepoint 32, #o40, #x20)
              charset: ascii (ASCII (ISO646 IRV))
code point in charset: 0x20
               script: latin
               syntax:   	which means: whitespace
             category: .:Base, a:ASCII, l:Latin
             to input: type "C-x 8 RET 20" or "C-x 8 RET SPACE"
          buffer code: #x20
            file code: #x20 (encoded by coding system utf-8-unix)
              display: by this font (glyph code)
    mac-ct:-*-Monaco-normal-normal-normal-*-12-*-*-*-m-0-iso10646-1 (#x03)

Character code properties: customize what to show
  name: SPACE
  general-category: Zs (Separator, Space)
  decomposition: (32) (' ')

There is an overlay here:
 From 47 to 52
  face                 racket-xp-unused-face
  insert-behind-hooks  (racket--modifying-overlay-deletes-it)
  insert-in-front-hooks (racket--modifying-overlay-deletes-it)
  modification-hooks   (racket--modifying-overlay-deletes-it)
  priority             0


There are text properties here:
  fontified            t
  help-echo            "no bound occurrences"

[back]

badkins 3 days ago M-x racket-xp-annotate did not clear them.

badkins 3 days ago I just recreated the file in another buffer, and it does not have the artifacts, but the Racket XP mode indicator is red and has an x instead of a checkmark.

badkins 3 days ago My bad - red herring. I had a typo in one of my requires - when I fixed that, the strange artifacts returned.

badkins 3 days ago Toggling racket-xp-mode hides and shows the artifacts reliably.

badkins 3 days ago It looks like it may have something to do with the macro I use to create my views. Not sure this is helpful, but here it is:

(define-syntax (axio-render-layout stx)
  (syntax-case stx ()
    [(_ ctx body-template)
     (with-syntax ([ body (format-id #'ctx "body") ]
                   [ layout-template (datum->syntax #'ctx "../views/layouts/application.html") ])
       #'(axio-render-template ctx
                               (let ([ body (include-template body-template) ])
                                 (include-template layout-template))))]
    [(_ ctx body-template layout-template)
     (with-syntax ([ body (format-id #'ctx "body") ])
       #'(axio-render-template ctx
                               (let ([ body (include-template body-template) ])
                                 (include-template layout-template))))]
    ))

badkins 3 days ago If this info is insufficient, I can try and produce a minimal example that reproduces the problem over the weekend.

greg 1 day ago A minimal example would be awesome if you can.

greg 1 day ago If you open the file in Dr Racket, you won't see a strikeout effect, but if you hover the mouse pointer in the same areas, do you see the "no bound occurrence" message?

greg 1 day ago My guess is that there probably are unused definitions, somewhere. Obviously not where it's being annotated there in your file. Somehow the srcloc is being garbled or misapplied, either at the drracket/check-syntax level or by me.

greg 1 day ago Like, maybe there's truly an unused definition in some file bar.rkt at position [13 15), and that's reported correctly, but somehow the annotation is ending up drawn in the buffer for foo.rkt.

greg 1 day ago I do "filter" the annotations to just those whose syntax-source = that of the file being checked

    (define/override (syncheck:find-source-object stx)
      (and (equal? src (syntax-source stx))
           src))

greg 1 day ago I guess another theory is that include-template is causing things like syntax-position and syntax-span to be from the template file instead of adjusted to the containing/using file? Or something like that?

badkins 1 day ago Thanks @greg that's helpful - I'll explore some of that, and if I come up blank, put together a tiny reproducible example.

badkins 1 day ago Weird - I opened in DrRacket, then clicked "check syntax" and got a DrRacket internal error!

send: target is not an object
  target: #f
  method name: last-position
  context...:
   /Users/badkins/sync/github/racket/racket/collects/racket/private/class-internal.rkt:4681:0: obj-error
   /Users/badkins/sync/github/racket/racket/share/pkgs/drracket/drracket/private/syncheck/gui.rkt:1140:12: add-to-range/key method in make-syncheck-text%380
   /Users/badkins/sync/github/racket/racket/share/pkgs/drracket-tool-lib/drracket/private/syncheck/traversals.rkt:1039:0: annotate-counts
   /Users/badkins/sync/github/racket/racket/share/pkgs/drracket-tool-lib/drracket/private/syncheck/traversals.rkt:48:10: expanded-expression
   /Users/badkins/sync/github/racket/racket/share/pkgs/drracket/drracket/private/syncheck/gui.rkt:2535:27
   /Users/badkins/sync/github/racket/racket/share/pkgs/drracket/drracket/private/syncheck/gui.rkt:2557:8: with-lock/edit-sequence method in unit-frame-mixin
   /Users/badkins/sync/github/racket/racket/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt:435:6
   /Users/badkins/sync/github/racket/racket/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt:486:32
   /Users/badkins/sync/github/racket/racket/share/pkgs/gui-lib/mred/private/wx/common/queue.rkt:634:3

badkins 1 day ago FYI - Hovering in DrRacket didn't produce anything.

badkins 18 hours ago Extracted a directory tree of 10 files to another directory that was sufficient to compile the error.rkt controller. I thought I had reproduced it, and was going to work on making it as small as possible, but now, I'm not seeing the artifacts :( No idea why having the same files in a different location would "fix" it.

badkins 18 hours ago 2 files image image

badkins 18 hours ago I suppose the length of the lines may be a clue, but that doesn't narrow it down much :)

badkins 18 hours ago The 2 images show how the tooltip changes as I move the cursor to the right. The "No bound occurrences" tooltip appears before I get to the white strikeout line.

badkins 18 hours ago It does seem related to that macro that expands to include-template

badkins 18 hours ago The artifacts only appear in my controller files that use that macro.

badkins 18 hours ago Ah, got something. Changing:

(require web-server/http
         web-server/templates)

to:

(require web-server/http
         web-server/templates
         (only-in xml xml-attribute-encode))

Causes the problem.

badkins 18 hours ago Ok, this is weird. Commenting out that 3rd line removes the strange artifacts, but then uncommenting did not restore the strange artifacts. There's some odd state management going on. (edited)

badkins 18 hours ago One more clue. Changing #lang racket to #lang racket/base fixed the artifacts in 2 of 3 files. Maybe related to the fact that the file containing the macro also used #lang racket/base instead of #lang racket ?

badkins 18 hours ago Hmm.. looks like it fixed it in one file, the second file now has a blue line that I mistook for the "unused require" line. So, in that second file, using #lang racket/base fixed one of the "no bound" artifacts, but left one of them.

badkins 18 hours ago So, in summary, changing to #lang racket/base removed the artifact near the #lang in all 3 files, and removed both artifacts in the simpler error.rkt file.

badkins 18 hours ago Ok, never mind, that change just moved the artifact lines in such a way as to nearly hide them. I'm done now, this is going nowhere.

greg 5 minutes ago Ugh that sound frustrating. :frowning: Thank you for pursuing it so doggedly!

greg 2 minutes ago The last pair of screenshots is interesting -- how it starts midway through the racket.

greg < 1 minute ago Unfortunately. I don't have any quick theories of the bug. And I'm up to my eyeballs in some other issues atm. But I want to capture your report/research in a GitHub issue so it doesn't get lost. So I'll do some copy/paste for now....

greghendershott avatar Nov 22 '21 13:11 greghendershott

greg 2 hours ago badkins What version of Racket are you using?

badkins 1 hour ago Welcome to Racket v8.2.0.8 [cs].

greghendershott avatar Nov 22 '21 15:11 greghendershott

I just merged https://github.com/greghendershott/racket-mode/commit/ba63c5b9b05ce54e370e5c6bb631060246ce7ea4 but I think that's "adjacent" to this problem not a fix for it.

The similarity is that I have (rarely) seen things like misplaced strikeout lines for a brief interval, if I am typing quickly, but with pauses long enough for an annotation request to be issued, then I keep typing more. The responses arrive and some of them are outdated. This causes the temporarily weird display. But waiting a second or two without typing, eventually the responses "catch up" and it's all consistent. So that's not really the same as the reported bug.

Anyway, the new commit ignores outdated responses; as a result, the buffer annotations might be old -- e.g. some new identifier you typed might lack an annotation -- but they generally won't be inconsistent with the text in the buffer. Annotations become text properties that mostly just "float along" with the text, even as it might be moved by insertions or deletions.

greghendershott avatar Dec 16 '21 21:12 greghendershott