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 eac58d3 commit 70614b4
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 @@ -105,6 +108,7 @@ export class DocComment extends DocNode {
this.returnsBlock = undefined;
this.modifierTagSet = new StandardModifierTagSet({ configuration: this.configuration });

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

Expand All @@ -113,13 +117,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 @@ -138,6 +159,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 @@ -165,5 +187,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 70614b4

Please sign in to comment.