Extract getTagDocumentation

This commit is contained in:
Matt Bierner
2018-01-04 16:29:48 -08:00
parent cca35e214e
commit d47922c595
+12 -10
View File
@@ -6,7 +6,7 @@
import * as Proto from '../protocol';
import { MarkdownString } from 'vscode';
function getTagText(tag: Proto.JSDocTagInfo): string | undefined {
function getTagBodyText(tag: Proto.JSDocTagInfo): string | undefined {
if (!tag.text) {
return undefined;
}
@@ -14,7 +14,7 @@ function getTagText(tag: Proto.JSDocTagInfo): string | undefined {
switch (tag.name) {
case 'example':
case 'default':
// Convert to markdown code block
// Convert to markdown code block if it not already one
if (tag.text.match(/^\s*[~`]{3}/g)) {
return tag.text;
}
@@ -24,6 +24,15 @@ function getTagText(tag: Proto.JSDocTagInfo): string | undefined {
return tag.text;
}
function getTagDocumentation(tag: Proto.JSDocTagInfo): string | undefined {
const label = `*@${tag.name}*`;
const text = getTagBodyText(tag);
if (!text) {
return label;
}
return label + (text.match(/\r\n|\n/g) ? ' \n' + text : `${text}`);
}
export function plain(parts: Proto.SymbolDisplayPart[]): string {
if (!parts) {
return '';
@@ -33,14 +42,7 @@ export function plain(parts: Proto.SymbolDisplayPart[]): string {
export function tagsMarkdownPreview(tags: Proto.JSDocTagInfo[]): string {
return (tags || [])
.map(tag => {
const label = `*@${tag.name}*`;
const text = getTagText(tag);
if (!text) {
return label;
}
return label + (text.match(/\r\n|\n/g) ? ' \n' + text : `${text}`);
})
.map(getTagDocumentation)
.join(' \n\n');
}