-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor support for @see and {@link} in JSDoc comments tags #35524
Comments
The JetBrains IDEs have had support for this forever (the WebStorm, too, has the problem of unresolved documentation links when there is no import for the Symbol. JSDoc actually in a way proposes a solution to this issue with a Syntax to "import" a type from another "module":
Adapted from https://jsdoc.app/about-namepaths.html |
More issues to consider in the proposal:
Some nice-to-haves that we'll need before any implementation happens:
Edit: Playing the role of obstinate implementer, I'd say that we could get 80% or more of the benefit of /** @param x - a thing; @see foo.bar for details */ Would produce {
kind: JSDocParameterTag,
name: "x",
comment: "a thing; @see foo.bar for details",
references: ["foo.bar"] // or an actual symbol, after binding is done
} |
@DanielRosenwasser the previous issue #16498 had 60 upvotes. Let's spend some time thinking again about whether we want this. |
@sandersn Checkout It'd be great if we could move away from our homegrown solution that only works inside |
Would it be possible that relative paths were also considered (JSDocs' namepaths)? I was thinking that it could be useful for referencing docs or other assets: // (might not be the exact syntax)
/**
* Without the `@link`
* @see ../README.md#Troubleshooting
*/
// or
/**
* See {@link ./my_asset.svg}...
*/ |
@sandersn I think if the string starts with a protocol and not starts with either And also, if the string starts with By the way, should the namepath syntax follow JSDoc, using |
Our code comments sometimes mention symbols in other files. I want to be able to copy such a path However, it doesn't work currently and needs to be done in two steps. taken from microsoft/vscode#96651 |
Ahh interesting, I was actually playing with implementing some of these types of things in a PR but I ended up keeping it simple to make sure there was wide support for it. I also wasn't sure what was possible since I haven't played with the tsServer in the past. I have to see this is definitely huge IMO. The rich realtime documentation as you code is probably the most underrated and powerful features to come with modern programming / IDE's - and making these hovers/popups more rich and useful will be a huge plus! My PR aims to be more general purpose by allowing absolute project & workspace linking, but it does reach into the tsServer to grab the Note: The current implementation is broken for relative paths. This is due to the fact they are utilizing the open file to resolve the relative link. This is problematic since we often are imported values from other files. The PR here fixes that issue for the hovers. At the very least it may provide insight into the vscode implementation requirements! |
imo it should not do anything and any links should be required in the file linking them. It simply makes things less magical and makes sense. Auto resolution simply has too many potential caveats and problems that can also be specific to the users environment at some times.
While the jsdoc mentions resolution via something like {@link Foo<T>['baz']}
// or just
{@link Foo['baz']} |
I just read through all of the previous issues and everything and I have to say I'm rather confused. But I would like to contribute here, based on how big of a task that actually is, but I would definitely like to look into it. Does anybody have a recommendation for where to start and can maybe outline the current status of this whole issue, what has already been done and what still needs to be done? I agree with @bradennapier, live documentation via popups in VSCode would be a huge plus for developer experience and I personally would love to use it myself. Also, what role does TSDoc currently play here? I think it shouldn't only support plain JSDoc fully but also TSDoc. If there is any kind of work group currently looking into this issue specifically I would love to join. |
@leontepe I think microsoft/tsdoc is just a reference implementation. |
As far as I understand it, TSDoc is a documentation standard that's similar to / based on JSDoc but without unnecessary type documentations that are already included in the TypeScript language itself. That's why I was saying it should take that into account as well, IMO. |
Yeah, I agree. There are some tags that were supported in TSDoc but not in TypeScript language server, like Also, I prefer the way TSDoc handle the Plus, TSDoc handles |
@JasonHK Yeah. And since basically every piece of code Microsoft writes is moving towards TypeScript and away from plain JavaScript, I think they should also have good native support for TSDoc in VSCode. |
I second @yGuy - if I'm a new developer and I want to write JS/TS documentation, I'm going to search for how to do that and I'm going to get results about (long-standing, widely accepted) JSDoc documentation. So, my opinion would be that we stick as close to the JSDoc spec as possible, for backwards compatibility and continuity reasons. |
@yGuy I don't mind not having this option, and you do make some good points. |
Duplicate of #5802. Glad to see it's been fixed — it's only been five years. |
Would it be a weird idea to optionally log warnings, and optionally even breaking the build, if a E.g. the linked-to thing got renamed / moved / removed, but the linking text wasn't updated. @sandersn wrote:
Personally I'd want that yes — optionally breaking the build (a compiler flag?). So annoying if trying to understand old code, and it says "blah blah, see: ..." and then that other related code is ... nowhere. (At the same time, if urgently releasing a security patch, then it'd be stressful to have to spend time cleaning up documentation links? So, optionally?) |
Is there currently an option in TSC that behaves similar to Visual Studio's "Treat warnings as errors" option? If so, we could just log them as warnings and use that pre-existing flag to change them to errors if the project called for it? |
add @see and {@link} support for typedoc see microsoft/TypeScript#35524
add @see and {@link} support for typedoc see microsoft/TypeScript#35524
This should be an eslint rule (or a whatever-your-lint-tool-is-rule). I'm not about to install vscode in a github workflow just to lint comments 🤣 |
Wanted to chime in on this because I thought it already worked this way, but turns out it doesn't: If I want to do a The |
Could support for differentiating |
Search Terms
jsdoc @link
jsdoc @see
jsdoc @see @link
Suggestion
Reminder of what
{@link}
doesWhenever a
{@link}
tag is encountered in JSDoc, it’d be nice to have it formatted as an actual anchor. It works with URL and symbols relative to the documented one: a function, a property of the current class, or a function in another class?The
@see
tag can also reference a symbol without any{@link}
, provided there is only a path to a symbol and no free-form text next to it. https://jsdoc.app/tags-see.htmlUse Cases
I often speak of other functions/classes in my doc comments, and as
{@link}
is described on JSDoc’s website, it’d be nice to have it parsed by the langage server and have it shown as a clickable link in any compatible doc widget.Examples
Non-imported symbols
A question that subsists is “what to do when {@link} refers to a symbol that exists in the project but isn’t imported in the current file?”
{@link mysterySymbol}
is converted into a basic non-interactivemysterySymbol
? Con is that to get a working link, you’d have to import symbols that are only used for doc.import("the-module").mysterySymbol
syntax like what was done for types declarations?file:line:column
, find all references of the given symbol in the project and somehow make the editor open a “peek” widget?node_module
?Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: