racket / drracket

DrRacket, IDE for Racket
http://www.racket-lang.org/
Other
452 stars 94 forks source link

syncheck:add-jump-to-definition provides wrong path #498

Closed dannypsnl closed 3 years ago

dannypsnl commented 3 years ago

To reproduce

  1. create a project project
  2. create project/a.rkt
  3. create project/b.rkt with (require "a.rkt")
  4. implement annotation-mixin and print filename from syncheck:add-jump-to-definition, result would be "/dir-to-project/b.rkt/a.rkt" rather than "/dir-to-project/a.rkt"

Additional But if you use (require project/a), result will be "/dir-to-project/a.rkt"

rfindler commented 3 years ago

Here is some example code that runs that does not have the problem you are describing. Can you perhaps help by telling me what would need to be different to get the bad output? (Note that the code below creates the file "tmp2.rkt" in whatever directory you run it in.)

Also, just in case, there was a bug like this a few versions ago, but it has been fixed. Is it possible you're not using the latest version?

#lang racket

(require drracket/check-syntax)

(define annotations
  (new (class (annotations-mixin object%)
         (super-new)
         (define/override (syncheck:add-jump-to-definition source-obj    
                                                           start     
                                                           end   
                                                           id    
                                                           filename  
                                                           submods)
           (printf "~s\n" filename)
           (super syncheck:add-jump-to-definition source-obj
                  start end id filename submods))
         (define/override (syncheck:find-source-object stx)
           (if (eq? 'the-source (syntax-source stx))
               'yep
               #f)))))

(define-values (add-syntax done)
  (make-traversal (make-base-namespace) #f))

(call-with-output-file "tmp2.rkt" (λ (port) (displayln "#lang racket\n(define x 1)\n(provide x)" port))
  #:exists 'truncate)
(parameterize ([current-annotations annotations]
               [current-namespace (make-base-namespace)])
  (add-syntax (expand
               (parameterize ([read-accept-reader #t])
                 (read-syntax 'the-source (open-input-string "#lang racket/base\n(require \"tmp2.rkt\")\nx")))))
  (done))
dannypsnl commented 3 years ago

I created a repository for this, output:

$ racket main.rkt
#t
#<path:/Applications/Racket v8.2/collects/racket/private/reqprov.rkt>
#<path:/Users/linzizhuan/dannypsnl/reproduce/b.rkt/a.rkt>

Racket version

$ racket
Welcome to Racket v8.2 [cs].
rfindler commented 3 years ago

I think the occurrence of path on this line should be src-dir (or #f, maybe).

dannypsnl commented 3 years ago

Wow, that's work!

rfindler commented 3 years ago

Yay!

On Mon, Jul 19, 2021 at 6:45 PM Lîm Tsú-thuàn≡悃悃 @.***> wrote:

Wow, that's work!

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/racket/drracket/issues/498#issuecomment-882936531, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADBNMAP4AQQN7DT22S5JEDTYS2LFANCNFSM5ATCKPGA .