Eugleo / magic-racket

The best coding experience for Racket in VS Code
https://marketplace.visualstudio.com/items?itemName=evzen-wybitul.magic-racket
GNU General Public License v3.0
199 stars 29 forks source link

Frequent hover errors in a file that opened before the plugin loaded #108

Open Reilithion opened 1 year ago

Reilithion commented 1 year ago

Sometimes I notice that any time I move my mouse within a Racket source file in VSCodium an error pops up in the Output pane. It gets quite annoying after a while. I've noticed this behavior in files that were open before the plugin loaded - for example, files that were open when I last closed the program and therefore opened automatically when I relaunched it.

Based on the error message I suspect this is a simple oversight in the handling of cases when an entry in a hash table is absent, but I'm happy to reproduce the error with more debug info on if needed.

Environment

Error message

[Error - 4:44:21 PM] Request textDocument/hover failed. Message: internal error in method "textDocument/hover" Code: -32603 Caught exn in request "textDocument/hover" hash-ref: no value found for key key: 'file:///c:/Users/Lucas/ETCETERA/myfile.rkt' context...: C:\Users\Lucas\AppData\Roaming\Racket\8.9\pkgs\racket-langserver\text-document.rkt:117:0: hover C:\Program Files\Racket\collects\racket\contract\private\arrow-val-first.rkt:486:18 C:\Users\Lucas\AppData\Roaming\Racket\8.9\pkgs\racket-langserver\methods.rkt:26:0: process-message C:\Program Files\Racket\collects\racket\contract\private\arrow-val-first.rkt:486:18 C:\Users\Lucas\AppData\Roaming\Racket\8.9\pkgs\racket-langserver\main.rkt:60:2: consume

jryans commented 1 year ago

Thanks for the report!

Have you noticed if it happens consistently for particular files? Or does it appear to be any file that you've left open...? I ask because I've occasionally seen similar errors, but it was always limited to specific files in my experience.

If it does seem specific to certain files, then it would be very helpful if you could share one of the affected files somehow, either via a link, gist, or email.

Reilithion commented 1 year ago

I may have been mistaken about the cause. I created a new file (call it test.rkt), copied and pasted the entire contents of the problem file into it and saved. As expected, there were no issues with hover in this new file. I then closed VSCodium and reopened it. To my surprise test.rkt continued to have well-behaving hover, but the original file continued to be problematic. I also was unable to get it to behave by closing and reopening the file.

I've since created a new file which is much more minimal. When I first saved it everything was working fine. But when I committed it in git, it began exhibiting errors on hover! Here are the entire contents of that file:

#lang racket/base

#|
Copyright 2023 Lucas Adam Michael Paul

This file is part of SomeProject.
SomeProjectis free software: you can redistribute it and/or modify it under the terms of the GNU
Lesser General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
SomeProjectis distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with SomeProject. If
not, see <https://www.gnu.org/licenses/>. 
|#

(require
  racket/unit
  "games.rkt")

(module+ test
  (require rackunit))

#|
  This is a trivial agent.
  It waits for a single move, ignores it, and then plays the string "foo", then terminates.
|#
(define-unit trivial-agent@
  (import game^)
  (export agent^)

  (define (strategy)
    (await)
    (play "foo"))
)
Reilithion commented 1 year ago

As extra context, I have admittedly updated VSCodium since last time. Also, the game^ and agent^ signatures are defined in games.rkt. game^ exports await and play while agent^ exports strategy.

jryans commented 1 year ago

I wasn't able to replicate the issue with your attached file, perhaps because I don't have the other associated files it tries to import... If it's possible to share a bit more of your project so that I can be sure I'm testing the same case as you're seeing, that would be ideal.

Even without that though, I have noticed similar hash-ref: no value found for key errors when exploring other unit-based files, such as those in https://github.com/philnguyen/soft-contract. My current hypothesis then is that something about units causes the language server to get confused when processing such files. I'll try to isolate what goes wrong in more detail.