Skip to content

Commit

Permalink
Adds the JSDoc 'see' tag
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Dec 19, 2019
1 parent 6130309 commit 21c79dc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
26 changes: 26 additions & 0 deletions tsdoc/src/details/StandardTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,31 @@ export class StandardTags {
standardization: Standardization.Extended
});

/**
* (Extended)
*
* Used to document another symbol or resource that may be related to the current item being documented.
*
* @remarks
*
* For example:
*
* ```ts
* /**
* * Make a rectangle from two points.
* *
* * @see {@link Point}
* */
* function makeRect(a: Point, b: Point): Rect;
* ```
*/
public static readonly see: TSDocTagDefinition = StandardTags._defineTag({
tagName: '@see',
synonyms: ['@seeAlso'],
syntaxKind: TSDocTagSyntaxKind.BlockTag,
standardization: Standardization.Extended
});

/**
* (Extended)
*
Expand Down Expand Up @@ -413,6 +438,7 @@ export class StandardTags {
StandardTags.remarks,
StandardTags.returns,
StandardTags.sealed,
StandardTags.see,
StandardTags.throws,
StandardTags.typeParam,
StandardTags.virtual
Expand Down
1 change: 1 addition & 0 deletions tsdoc/src/emitters/TSDocEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class TSDocEmitter {
docComment.typeParams,
docComment.returnsBlock,
...docComment.customBlocks,
...docComment.seeBlocks,
docComment.inheritDocTag
]);
if (docComment.modifierTagSet.nodes.length > 0) {
Expand Down
25 changes: 23 additions & 2 deletions tsdoc/src/nodes/DocComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { DocBlock } from './DocBlock';
import { DocInheritDocTag } from './DocInheritDocTag';
import { StringBuilder } from '../emitters/StringBuilder';
import { DocParamCollection } from './DocParamCollection';
import { IModifierTagSetParameters } from '../details/ModifierTagSet';
import { StandardTags } from '../details/StandardTags';

/**
* Constructor parameters for {@link DocComment}.
Expand Down Expand Up @@ -87,6 +89,7 @@ export class DocComment extends DocNode {
*/
public readonly modifierTagSet: StandardModifierTagSet;

private _seeBlocks: DocBlock[];
private _customBlocks: DocBlock[];

/**
Expand All @@ -109,6 +112,7 @@ export class DocComment extends DocNode {
};
this.modifierTagSet = new StandardModifierTagSet(modifierTagSetParameters);

this._seeBlocks = [];
this._customBlocks = [];
}

Expand All @@ -117,13 +121,30 @@ export class DocComment extends DocNode {
return DocNodeKind.Comment;
}

/**
* The collection of all `@see` DocBlockTag nodes belonging to this doc comment.
*/
public get seeBlocks(): ReadonlyArray<DocBlock> {
return this._seeBlocks;
}

/**
* The collection of all DocBlock nodes belonging to this doc comment.
*/
public get customBlocks(): ReadonlyArray<DocBlock> {
return this._customBlocks;
}

/**
* Append an item to the seeBlocks collection.
*/
public appendSeeBlock(block: DocBlock): void {
if (!StandardTags.see.isDefinitionOfTag(block.blockTag)) {
throw new Error("Provided block is not a @see block.");
}
this._seeBlocks.push(block);
}

/**
* Append an item to the customBlocks collection.
*/
Expand All @@ -142,6 +163,7 @@ export class DocComment extends DocNode {
this.typeParams.count > 0 ? this.typeParams : undefined,
this.returnsBlock,
...this.customBlocks,
...this.seeBlocks,
this.inheritDocTag,
...this.modifierTagSet.nodes
];
Expand Down Expand Up @@ -169,5 +191,4 @@ export class DocComment extends DocNode {
}

// Circular reference
import { TSDocEmitter } from '../emitters/TSDocEmitter';import { IModifierTagSetParameters } from '../details/ModifierTagSet';

import { TSDocEmitter } from '../emitters/TSDocEmitter';
2 changes: 2 additions & 0 deletions tsdoc/src/parser/NodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ export class NodeParser {
docComment.deprecatedBlock = block;
} else if (StandardTags.returns.isDefinitionOfTag(block.blockTag)) {
docComment.returnsBlock = block;
} else if (StandardTags.see.isDefinitionOfTag(block.blockTag)) {
docComment.appendSeeBlock(block);
} else {
docComment.appendCustomBlock(block);
}
Expand Down

0 comments on commit 21c79dc

Please sign in to comment.