Is there a way in JSDoc/TSDoc to make links to code pieces?

Viewed 522

The problem: when you work on a big project, or on many of them, and one of the tests fails for some reason, you can see which feature fails, but it is hard to recall where the implementation was.

So imagine, links in each test case to its implementation can make life easier. Is there any way (if JSDoc/TSdoc does not have it, maybe there is some IDE extension or library or convention) for this?

There are some desired behavior also:

  • A link to the line is impractical because you know, code changes, lines' contents do as well. So there should be some anchors on both ends, like in HTML.
  • A link to the class or even to the method is also not always can point to the exact implementation.
  • A link should be of course clickable in IDE, otherwise its' usefullness is near to zero
1 Answers

I know the question was posted 234 days ago but the following answer might help some of who got here.

If I understood your question properly, what you're looking for is what most IDEs and editors do (at least what JetBrains IDEs, Sublime Text and VSCode can do), in other words: having the possibility to navigate to the implementation of a function/method/class/... (which can normally be achieved by right-clicking on it and then selecting the relevant option).
So on VSCode, you'll need to click on "Go to Definition" (or press F12) after you right-clicked the relevant function/method call. On JetBrains IDEs, if I recall correctly, the context menu option is called "Go to Implementation".

Note: This usually only works if you have documentation written for the relevant code.

As for having this on tests, It may be possible depending on the testing tool you use. In regards to jest (and I think mocha as well), you can see (a part of) the JSDoc doclet where a failure occurred; bar in mind that won't show you the doclet of the underlying functions/methods.

Related