Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking to code files from another code file on GitHub

Tags:

github

What I want to achieve is to reference a code file from another code file and GitHub would recognize it as it recognizes markdown links in a markdown file.

I have a code base which is a tutorial about how to use a specific framework. People go through the code files by following the explanations in the comments and jump to the next file if the comment references it. For example:

// NEXT STATION: Go to Controllers/AdminController.cs

It would be really practical to let the user go through the GitHub repository on GitHub by clicking these code file references. Not sure if this is possible though.

I've tried but didn't work:

// NEXT STATION: Go to [Controllers/AdminController.cs](AdminController.cs)
// NEXT STATION: Go to https://github.com/username/repo-name/blob/master/src/Controllers/AdminController.cs

So is there a way to make GitHub recognize these references and make them links?

like image 759
Márk Bartha Avatar asked Nov 06 '22 21:11

Márk Bartha


1 Answers

This is not supported through Markdown alone.

You could take advantage of a new GitHub feature being rolled out in Q4 2021/Q1 2022: Precise and search-based navigation

Certain languages supported by GitHub have access to precise code navigation, which uses an algorithm (based on the open source stack-graphs library) that resolves definitions and references based on the set of classes, functions, and imported definitions that are visible at any given point in your code.

Reference -- https://docs.github.com/assets/cb-38247/images/help/repository/search-based-code-navigation-link.png

By adding a dummy function call src.SeeTest() in main.cs, with a dummy function SeeTest in Test.cs, you could effectively create a link that a user can click to switch from main.cs to Test.cs.

However, that feature is implemented for now only with the Python language, as listed in "Navigating code on GitHub". C# should follow shortly.

like image 82
VonC Avatar answered Nov 14 '22 22:11

VonC