简体   繁体   English

JSDoc / TSDoc中是否有一种方法可以链接到代码片段?

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

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? 有没有办法(如果JSDoc / TSdoc没有它,可能有一些IDE扩展或库或约定)?

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. 因此,两端应该有一些锚点,就像在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 链接当然应该在IDE中可以点击,否则它的实用性接近于零

I know the question was posted 234 days ago but the following answer might help some of who got here. 我知道这个问题是在234天前发布的,但以下答案可能有助于一些人来到这里。

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). 如果我理解你的问题,你正在寻找的是大多数IDE和编辑所做的事情(至少JetBrains IDE,Sublime Text和VSCode可以做什么),换句话说:有可能导航到函数的实现/ method / class / ...(通常可以通过右键单击它然后选择相关选项来实现)。
So on VSCode , you'll need to click on "Go to Definition" (or press F12) after you right-clicked the relevant function/method call . 因此,在VSCode上右键单击相关的函数/方法调用后 ,您需要单击“转到定义”(或按F12) On JetBrains IDEs , if I recall correctly, the context menu option is called "Go to Implementation" . JetBrains IDE上 ,如果我没记错的话,上下文菜单选项称为“转到实现”

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; 关于jest(我也认为是mocha),你可以看到发生故障的JSDoc doclet(的一部分); bar in mind that won't show you the doclet of the underlying functions/methods. 请记住,这不会向您展示底层函数/方法的doclet。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM