Conversation

sandersn

Fixes #35524 (80% solution)

This PR makes the parser parse @link tag and the language service offer symbols for entity names found at the beginning of those tags. Links are stored redundantly with comment text, so they're only used to provide (1) a span to an editor to format in some way (2) a symbol for the declaration of the link's target.

Future PRs

  1. Parse # as type-space element access: Class#method. As well as, possibly, the normal TS syntax Class["method"], which doesn't currently parse either.

Open questions

  1. I parse @see {@link ...} as a @see with no reference and a link in its comment text. I think that's OK.
  2. I intentionally do not parse { @link X}, with a space separating { and @. I saw this only twice in my corpus, but @amcasey points out that it's easy to support with an additional skipWhitespace call. I originally skipped it because I had slightly less lookahead when the next token after { was @, but that made the code unreadable, so I dropped it.

Resolved questions

  1. I introduced JSDocText and JSDocLink nodes into the AST, which better reflects the semantic relation of comments to their tags. It is more expensive, though, it means that jsdoc comment text is treated as a first-class member of the parse tree now.

Probably need to fork the services/server types and provide a conversion
with Session.toFileSpan. Not sure where to put the conversion.
In theory this is already better supported, but not sure practise bears
that out.
1. Simplify protocol after talking to @mjbvz.
2. Add more tests.
3. Initial notes about where to add parsing.
The text of the link is still stored in the comment text, but that's now
kept in an object instead of just a string. Each link has the parse for
the entity reference, if there is one.

Needs lots more tests -- this just makes all the existing jsdoc tests
pass.
@typescript-bot

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @amcasey, @mjbvz, @minestarks for you. Feel free to loop in other consumers/maintainers if necessary

@typescript-bottypescript-bot added the For Uncommitted BugPR for untriaged, rejected, closed or missing buglabel Dec 8, 2020
@sandersn

@mjbvz and @amcasey, you should maybe also look at this (at least the protocol part)

@andrewbranch

@typescript-bot pack this

Only thing I’m curious about is if there are some places where JSDoc can go, but otherwise entity names could not go, and therefore might expose a hole in getSymbolAtLocation.

@typescript-bot

Heya @andrewbranch, I've started to run the tarball bundle task on this PR at fce33f1. You can monitor the build here.

@sandersn

@andrewbranch I indeed tried writing more tests and discovered a hole. I'll put up a commit that makes getSymbolAtLocation work with identifiers in links.

@minestarks

@jessetrinity any chance you could validate this doesn't break anything in VS? I don't think we'll just get @link tag support for free, but at least JSDoc tags and other stuff should continue to work (in plain .js / .html / .cshtml)

@sandersn

The most recent commit avoids breaking VS, and I'm working on tests for all 4 possible combinations of the rich/full matrix.

They are ambiguous; previously the parser preferred the type
interpretation, but will now look ahead and parse links instead when the
prefix is `{@link`.
@sandersn

This is ready for review now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior and interface changes generally LGTM. Some suggestions below.

1. Add a cross-file goto-def test.
2. Switch from per-message args to UserPreference.
@sandersn

I think this PR has had enough review to be ready to use. I'll merge it and address any follow-up in subsequent PRs.

@sandersnsandersn merged commit ec77bff into master Mar 16, 2021
@sandersnsandersn deleted the editor-support-for-links branch March 16, 2021 23:26
@Kingwl

Cool!

sandersn added a commit that referenced this pull request Mar 18, 2021
sandersn added a commit that referenced this pull request Mar 18, 2021
sandersn added a commit that referenced this pull request Mar 19, 2021
@sandersnsandersn mentioned this pull request Mar 19, 2021
sandersn added a commit that referenced this pull request Mar 22, 2021
* Revert "Revert "Editor support for link tag (#41877)" (#43302)"

This reverts commit 451d435.

* Fix parsing @link at end of comment

* Parse comments as string when no @link occurs

* fix lint
@millsp

Sign up for free to join this conversation on . Already have an account? Sign in to comment
Author: Team For Uncommitted BugPR for untriaged, rejected, closed or missing bug
Archived in project

Successfully merging this pull request may close these issues.

Editor support for @see and {@link} in JSDoc comments tags