drracket icon indicating copy to clipboard operation
drracket copied to clipboard

Open defining file should jump to definition

Open sorawee opened this issue 5 years ago • 11 comments

There are two cases when jump-to-definition-callback is called: the file with the definition has not been opened, or is already opened. If it's already opened, DrRacket will jump to definition as expected. However, if it has not been opened, it will simply open the defining file without jumping to definition. Making it jumping to definition too would be an improvement.

sorawee avatar May 14 '19 05:05 sorawee

It doesn't do that because it takes (potentially a lot) of time to find the definition. So it jumps to the definition only when it already knows where the definition is.

On Tue, May 14, 2019 at 12:47 AM sorawee [email protected] wrote:

There are two cases when jump-to-definition-callback https://github.com/racket/drracket/blob/master/drracket/drracket/private/syncheck/gui.rkt#L1877 is called: the file with the definition has not been opened, or is already opened. If it's already opened, DrRacket will jump to definition as expected. However, if it has not been opened, it will simply open the defining file without jumping to definition. Making it jumping to definition too would be an improvement.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/racket/drracket/issues/273?email_source=notifications&email_token=AADBNMHNFFW3JLA5MWVH3O3PVJG53A5CNFSM4HMWPDCKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GTSUWGA, or mute the thread https://github.com/notifications/unsubscribe-auth/AADBNMHX2GFBXYHUDAXJWWTPVJG53ANCNFSM4HMWPDCA .

rfindler avatar May 14 '19 10:05 rfindler

Could this be a timed-out jump? If it succeeds in N ticks, it does; otherwise it doesn't?

mfelleisen avatar May 14 '19 12:05 mfelleisen

That sounds confusing to the user to me. I think probably it makes sense to have two things, one where you commit to wait up front and one where you get the present behavior (open the file if the definition's location isn't yet known and go to the definition if it is known (where "known" here mean that online check syntax has completed in the file)).

rfindler avatar May 14 '19 12:05 rfindler

The second option could show a clock or something to indicate that it timed out. But I gave often wanted what Oak asked for but you told me about the "takes a long time" before.

An alternative would be to index the files up front ..

mfelleisen avatar May 14 '19 12:05 mfelleisen

An alternative would be to index the files up front ..

The better alternative

spdegabrielle avatar Sep 12 '22 13:09 spdegabrielle

Yes, I agree that some kind of indexing is the best option here. @chrdimo and I started working on a layer to provide that but I got distracted on picking it up and finishing it off.

rfindler avatar Sep 12 '22 13:09 rfindler

As a user of both racket-mode and DrRacket, the heuristic approach that racket-mode uses works really well and I would appreciate having DrRacket do that in a similar way.

samth avatar Sep 12 '22 13:09 samth

Is there some code that racket-mode and drracket could share here?

rfindler avatar Sep 12 '22 15:09 rfindler

I think @greghendershott could point to the relevant racket-mode code but DrRacket already has the code to heuristically generate the "jump to definition" drop-down for each file so it could use that.

samth avatar Sep 12 '22 15:09 samth

The Racket Mode code is https://github.com/greghendershott/racket-mode/blob/master/racket/find.rkt.

I haven't worked on this code in a couple years, so if you have questions, it would take me awhile to fully reload my brain. View from orbit, my experience is that you can find some definitions from fully expanded syntax... but as a fallback might need to look at pre-expanded. [There is also code in that file to find "signatures" (i.e. something to show users in lieu of an actual bluebox), in which case digging through pre-expanded surface syntax is even more useful.]

Racket Mode maintains an in-memory cache of syntax (both pre-expanded and expanded). The keys include files on disk, as well as code strings that exist only in non-saved code buffers. The cache can be warmed by check syntax having already run, or by a compiled load handler (so required files might already be in the cache), or by some other command wanting syntax for the file or buffer.

So often it's pretty fast. Even so, this is done "asynchronously" in Racket Mode, i.e. the user can keep using Emacs while the search is happening, including expansion if that needs to happen because there's a cache miss.


I'm 100% open to sharing. How, exactly? Often this can be tricky to do in the form of a shared package because Racket Mode supports older versions of Racket than you would want to support.

At the very least I'm happy to share in terms of you using the code as a head start (whether you regard it as a model or anti-model, either way. :smile:). And if it seems like an actual shared package is possible and non-awkward, that would be great, too.

greghendershott avatar Sep 12 '22 18:09 greghendershott

This issue has been mentioned on Racket Discussions. There might be relevant details there:

https://racket.discourse.group/t/opportunities-for-indexing/1321/1