Live data from Hacker News

Ask HN: How Do You Navigate Code?

news.ycombinator.com

1–10 of 39 posts

Ask HN: How Do You Navigate Code?

#1
I've been working in a new codebase recently, and I've been struggling to navigate code. I don't think this code is organized particularly poorly, but I still find myself jumping around and having quite a few files/tabs open trying to follow the thread. In this case some of this code is object oriented and so there's lots of jumping between class and base classes (often multiple base classes deep...) to see where anything happens. I've used VIM marks in the past, I'm trying a bookmarking extension for VS Code, and sometimes I open multiple files in splits to keep things "in context", but I still feel like these are all less than ideal and it's very easy if I step away from my computer for a few minutes for it all to leak out of my brain and then I spend the next 30 minutes trying to get it all back before I can work on the problem.

Looking for any tips you all might have for making this easier.

Re: Ask HN: How Do You Navigate Code?

#3
I use VSCode and mostly navigate via:

F12: Go to definition

Shift+F12: Go to usages

Ctrl+-: Go back

Ctrl+Shift+-: Go forward

Once you get used to it, it's as easy as browsing the web.

Since I started using VSCode I did not have to work with codebases that were complex enough to make these features valuable but some VSCode language extensions support tree views of call hierarchies and type hierarchies. Here's the documentation for the Java extension.

https://code.visualstudio.com/docs/java/java-editing#_call-h...

https://code.visualstudio.com/docs/java/java-editing#_type-h...

You can set keybindings for them too.

Re: Ask HN: How Do You Navigate Code?

#4

I use VSCode and mostly navigate via: F12: Go to definition Shift+F12: Go to usages Ctrl+-: Go back Ctrl+Shift+-: Go forward Once you get used to it, it's as easy as browsing the web. Since I started using VSCode I did not have to work with codebases that were complex enough to make these features valuable but some VSCode language extensions support tree views of call hierarchies and type hierarchies. Here's the docu…

I use these as well, but maybe something I didn't articulate well is that it's often useful to remember where I've been. One thing that I haven't played with in VS Code but that bites me a lot (and sorry, I don't know the proper name for this setting/feature) is that often when you're navigating you're doing so in the same vs code tab. If I remember to double-click the tab it'll hang around, but that's a pretty janky workflow, and I don't ALWAYS want to do that. Ctrl+- works if I hop into a method/function and want to look at it briefly and hop out, but I find if I go more than a couple levels deep it would be nice to mark certain areas as I go so I can easily get back to them.

Sometimes I do this by just adding a comment, and now that file will at least show up in version control as changed and I can get back to it if I need to, but that's also a little bit janky and I have to be careful I don't leave that cruft around on accident when I commit.

I'm trying out a bookmark extension in VS code and we'll see how it goes, I'm already a little bit annoyed by it in that it doesn't seem to let me organize the bookmarks in any way, so it might be somewhat useful for temporary spelunking, but I won't for example be able to save these bookmarks to refer to them later, which seems like it could be useful.

Sourcegraph has this concept of "Notebooks" which allows you to add files and intermix markdown, which feels like a pretty cool idea, and if I'm just reading code in Sourcegraph it's great, but when I'm in my code editor and making changes I don't want to bounce over to another tool. Maybe it's as simple as keeping some sort of Markdown file open that I write into and then add links to file line numbers as I go, I haven't tried that but I suppose it wouldn't be the worst, and allows me to organize the links in any fashion I see fit.

Re: Ask HN: How Do You Navigate Code?

#5

I use VSCode and mostly navigate via: F12: Go to definition Shift+F12: Go to usages Ctrl+-: Go back Ctrl+Shift+-: Go forward Once you get used to it, it's as easy as browsing the web. Since I started using VSCode I did not have to work with codebases that were complex enough to make these features valuable but some VSCode language extensions support tree views of call hierarchies and type hierarchies. Here's the docu…

OOP is annoying because if people are using interfaces, "Go to Definition" takes you to the interface instead of what I'm looking tor which is the implementation.

Re: Ask HN: How Do You Navigate Code?

#7

I use VSCode and mostly navigate via: F12: Go to definition Shift+F12: Go to usages Ctrl+-: Go back Ctrl+Shift+-: Go forward Once you get used to it, it's as easy as browsing the web. Since I started using VSCode I did not have to work with codebases that were complex enough to make these features valuable but some VSCode language extensions support tree views of call hierarchies and type hierarchies. Here's the docu…

I use these as well, but maybe something I didn't articulate well is that it's often useful to remember where I've been. One thing that I haven't played with in VS Code but that bites me a lot (and sorry, I don't know the proper name for this setting/feature) is that often when you're navigating you're doing so in the same vs code tab. If I remember to double-click the tab it'll hang around, but that's a pretty janky…

Sourcegraph Notebooks PM here. We have a notepad feature you can enable that basically does what you're describing and allows you to create a notebook from the saved content in one click. There's a button to enable the notepad on the notebooks page (https://sourcegraph.com/notebooks or /notebooks" rel="nofollow">https:///notebooks).

It follows you around as you navigate search results and files and you can add searches, files, and file ranges to it, as well as notes for each item. Quick demo video: https://storage.googleapis.com/sourcegraph-assets/docs/image...

Re: Ask HN: How Do You Navigate Code?

#8
NeoVim + language servers + global search with rg + a bunch of keyboard shortcuts:

- gd = go to definition

- gr = open a hovering window filled with references to symbol

This is enough to get through every codebase I've yet encountered (Go, Typescript, Python, Java, C++). I also like to use and in vim which allows you to jump between the most recently viewed locations.

For keeping context, I just write everything down! Either in a scratch file or on a digital notetaking app on my iPad.

Re: Ask HN: How Do You Navigate Code?

#10
I had a similar requirements some time ago - I thought one nice way would be to write a Markdown file to be read inside VSCode with links to the files' lines/positions, but couldn't find an extension that worked like this. Settled for "Bookmarks" at the time. The "Code Tour" extension can also be used for this.
Post reply on HN