mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
Extract getTagDocumentation
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user