Kodrick

Linking Files in VS Code - Holding your Codebase Together One Comment At a Time

Cody Moore
July 19, 2022

Have you ever been trying to write documentation for some code you just made, then thought it would be great if you could just make a link to these comments across your codebase?

The DRY principle (Don't Repeat Yourself) suggests that you should only write code once, but what about comments? Is the explanation for why you did something not going to take up as much, or more, time to write out, especially if you need to duplicate that explanation in multiple places? Can you count on a colleague (or even yourself) stumbling into the single implementation that actually has an explanatory comment in the future?

Wouldn't it be a lot easier to just write a comment once, then reference back to it whenever you needed?

Enter Comment Anchors.

Comment Anchors - the best comments extension for VS Code

Linking between pages is pretty simple with Comment Anchors. Just add an Anchor tag with an id wherever you want to create a link.

`// ANCHOR[id=myReference]`

Then, wherever you want to make it linkable, add a Link tag with the path to the file and the id.

`// LINK path\to\my\file#myReference`

VS Code will now allow you to navigate to the reference with as little effort as a CTRL + CLICK. This makes it significantly easier to find comments and relate ideas between files in your codebase.

Comment Anchors can use both relative and absolute paths, so these links work even for your colleagues who've just cloned your work and have no clue how anything works yet. Hopefully, they'll figure it out easily with all your amazing comments.

Written By
Cody Moore
Kodrick LLC © 2022