Skip to content

Parse comment on @property tag and use as documentation comment#21119

Merged
4 commits merged into
masterfrom
quickInfoProperty
Jan 11, 2018
Merged

Parse comment on @property tag and use as documentation comment#21119
4 commits merged into
masterfrom
quickInfoProperty

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Jan 10, 2018

Fixes #21105

@ghost ghost requested review from armanio123 and sandersn January 10, 2018 16:48
@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Jan 10, 2018

@sandersn can you please review this change.

Copy link
Copy Markdown
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Couple of areas:

  1. Test and questions about indent handling.
  2. Question about showing @param doc on usage as well as definition.

//// */
////
/////** @type {I} */
////const obj = { /**/x: 10 };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what about obj.x/**/ ? Did that work before this change? Does it work now?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, these both get the same symbol, and the documentation-getting code just depends on the symbol.

Comment thread src/compiler/utilities.ts
((node as JSDocFunctionType).parameters[0].name as Identifier).escapedText === "new";
}

export function getAllJSDocs(node: Node): (JSDoc | JSDocTag)[] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this was internal, right? I don't see a jsdoc on it, so I assume so.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

API tests should ensure we don't delete internal things.

Comment thread src/services/jsDoc.ts

function getCommentsFromDeclaration(declaration: Declaration): string[] {
switch (declaration.kind) {
case SyntaxKind.JSDocPropertyTag:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is this special-cased here instead of in getAllJSDocs?

Copy link
Copy Markdown
Author

@ghost ghost Jan 10, 2018

Choose a reason for hiding this comment

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

Updated, now there's only one function.

Comment thread src/compiler/parser.ts
return false;
}
const tag = parseParameterOrPropertyTag(atToken, tagName, target);
tag.comment = parseTagComments(tag.end - tag.pos);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just to make sure I'm not missing something: This is the only line required to make the tests pass, right? The rest looks like refactoring.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why isn't isn't indent needed to get the correct offset, like with the other call to parseTagComments? Does tryParseChildTag need to track indent?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I needed to make a few other changes to parser.ts to avoid skipping the @ token at the end of a comment and to use undefined instead of "" for the comment.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It looks like it will be needed to get the best comment text, that will be a bigger change though. Filed #21123

// @Filename: /a.js
/////**
//// * @typedef I
//// * @property {number} x Doc
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you make the documentation longer and multiline, with varying indents, to make sure that it works correctly?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@ghost ghost force-pushed the quickInfoProperty branch from d142fcb to af26984 Compare January 10, 2018 18:50
"documentation": [
{
"text": "Doc{T} A template",
"text": "DocT} A template",
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@ghost ghost force-pushed the quickInfoProperty branch from af26984 to 5181017 Compare January 10, 2018 18:52
Copy link
Copy Markdown
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Just one question but good enough to merge.

Comment thread src/services/jsDoc.ts Outdated
return name ? withNode(name) : comment;
default:
return comment;
return comment || "";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

adding || "" goes the opposite direction of adding | undefined to the return type. Is the latter still correct?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Whoops, shouldn't have left this in.

@ghost ghost merged commit a77c601 into master Jan 11, 2018
@ghost ghost deleted the quickInfoProperty branch January 11, 2018 18:49
errendir added a commit to errendir/TypeScript that referenced this pull request Jan 15, 2018
* origin/master: (114 commits)
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  Enable substitution for object literal shorthand property assignments in the system transform (microsoft#21106)
  Skip outer expressions when checking for super keyword in binder (microsoft#20164)
  Group intersection code in getSimplifiedIndexedAccessType
  Use filter instead of unnecessary laziness
  Remove mapped types to never from intersections
  Handle jsconfig.json in fourslash tests (microsoft#16484)
  Add a `getFullText()` helper method to `IScriptSnapshot` (microsoft#21155)
  Test Diff and Omit
  Keep string index from intersections in base constraint of index type
  LEGO: check in for master to temporary branch.
  Fix bug: get merged symbol of symbol.parent before checking against module symbol (microsoft#21147)
  Do not trigger the failed lookup location invalidation for creation of program emit files Handles microsoft#20934
  Add test where emit of the file results in invalidating resolution and hence invoking recompile
  Parse comment on @Property tag and use as documentation comment (microsoft#21119)
  Update baselines
  push/popTypeResolution for circular base constraints
  LEGO: check in for master to temporary branch.
  Test:incorrect mapped type doesn't infinitely recur
  ...
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants