mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
@@ -82,7 +82,7 @@ class MyCompletionItem extends vscode.CompletionItem {
|
||||
|
||||
const { sourceDisplay, isSnippet } = tsEntry;
|
||||
if (sourceDisplay) {
|
||||
this.label = { label: tsEntry.name, description: Previewer.plainWithLinks(sourceDisplay, client) };
|
||||
this.label = { label: tsEntry.name, description: Previewer.asPlainTextWithLinks(sourceDisplay, client) };
|
||||
}
|
||||
|
||||
if (tsEntry.labelDetails) {
|
||||
@@ -255,7 +255,7 @@ class MyCompletionItem extends vscode.CompletionItem {
|
||||
parts.push(action.description);
|
||||
}
|
||||
|
||||
parts.push(Previewer.plainWithLinks(detail.displayParts, client));
|
||||
parts.push(Previewer.asPlainTextWithLinks(detail.displayParts, client));
|
||||
return parts.join('\n\n');
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ class MyCompletionItem extends vscode.CompletionItem {
|
||||
baseUri: vscode.Uri,
|
||||
): vscode.MarkdownString | undefined {
|
||||
const documentation = new vscode.MarkdownString();
|
||||
Previewer.addMarkdownDocumentation(documentation, detail.documentation, detail.tags, client);
|
||||
Previewer.appendDocumentationAsMarkdown(documentation, detail.documentation, detail.tags, client);
|
||||
documentation.baseUri = baseUri;
|
||||
return documentation.value.length ? documentation : undefined;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import type * as Proto from '../tsServer/protocol/protocol';
|
||||
import { ClientCapability, ITypeScriptServiceClient, ServerType } from '../typescriptService';
|
||||
import { conditionalRegistration, requireSomeCapability } from './util/dependentRegistration';
|
||||
import { DocumentSelector } from '../configuration/documentSelector';
|
||||
import { markdownDocumentation } from './util/textRendering';
|
||||
import { documentationToMarkdown } from './util/textRendering';
|
||||
import * as typeConverters from '../typeConverters';
|
||||
import FileConfigurationManager from './fileConfigurationManager';
|
||||
|
||||
@@ -68,7 +68,7 @@ class TypeScriptHoverProvider implements vscode.HoverProvider {
|
||||
displayParts.push(data.displayString);
|
||||
parts.push(new vscode.MarkdownString().appendCodeblock(displayParts.join(' '), 'typescript'));
|
||||
}
|
||||
const md = markdownDocumentation(data.documentation, data.tags, this.client, resource);
|
||||
const md = documentationToMarkdown(data.documentation, data.tags, this.client, resource);
|
||||
parts.push(md);
|
||||
return parts;
|
||||
}
|
||||
|
||||
@@ -72,19 +72,19 @@ class TypeScriptSignatureHelpProvider implements vscode.SignatureHelpProvider {
|
||||
|
||||
private convertSignature(item: Proto.SignatureHelpItem, baseUri: vscode.Uri) {
|
||||
const signature = new vscode.SignatureInformation(
|
||||
Previewer.plainWithLinks(item.prefixDisplayParts, this.client),
|
||||
Previewer.markdownDocumentation(item.documentation, item.tags.filter(x => x.name !== 'param'), this.client, baseUri));
|
||||
Previewer.asPlainTextWithLinks(item.prefixDisplayParts, this.client),
|
||||
Previewer.documentationToMarkdown(item.documentation, item.tags.filter(x => x.name !== 'param'), this.client, baseUri));
|
||||
|
||||
let textIndex = signature.label.length;
|
||||
const separatorLabel = Previewer.plainWithLinks(item.separatorDisplayParts, this.client);
|
||||
const separatorLabel = Previewer.asPlainTextWithLinks(item.separatorDisplayParts, this.client);
|
||||
for (let i = 0; i < item.parameters.length; ++i) {
|
||||
const parameter = item.parameters[i];
|
||||
const label = Previewer.plainWithLinks(parameter.displayParts, this.client);
|
||||
const label = Previewer.asPlainTextWithLinks(parameter.displayParts, this.client);
|
||||
|
||||
signature.parameters.push(
|
||||
new vscode.ParameterInformation(
|
||||
[textIndex, textIndex + label.length],
|
||||
Previewer.markdownDocumentation(parameter.documentation, [], this.client, baseUri)));
|
||||
Previewer.documentationToMarkdown(parameter.documentation, [], this.client, baseUri)));
|
||||
|
||||
textIndex += label.length;
|
||||
signature.label += label;
|
||||
@@ -95,7 +95,7 @@ class TypeScriptSignatureHelpProvider implements vscode.SignatureHelpProvider {
|
||||
}
|
||||
}
|
||||
|
||||
signature.label += Previewer.plainWithLinks(item.suffixDisplayParts, this.client);
|
||||
signature.label += Previewer.asPlainTextWithLinks(item.suffixDisplayParts, this.client);
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ function getTagBody(tag: Proto.JSDocTagInfo, filePathConverter: IFilePathToResou
|
||||
return (convertLinkTags(tag.text, filePathConverter)).split(/^(\S+)\s*-?\s*/);
|
||||
}
|
||||
|
||||
export function plainWithLinks(
|
||||
export function asPlainTextWithLinks(
|
||||
parts: readonly Proto.SymbolDisplayPart[] | string,
|
||||
filePathConverter: IFilePathToResourceConverter,
|
||||
): string {
|
||||
@@ -212,44 +212,44 @@ function convertLinkTags(
|
||||
return processInlineTags(out.join(''));
|
||||
}
|
||||
|
||||
export function tagsMarkdownPreview(
|
||||
function escapeMarkdownSyntaxTokensForCode(text: string): string {
|
||||
return text.replace(/`/g, '\\$&');
|
||||
}
|
||||
|
||||
export function tagsToMarkdown(
|
||||
tags: readonly Proto.JSDocTagInfo[],
|
||||
filePathConverter: IFilePathToResourceConverter,
|
||||
): string {
|
||||
return tags.map(tag => getTagDocumentation(tag, filePathConverter)).join(' \n\n');
|
||||
}
|
||||
|
||||
export function markdownDocumentation(
|
||||
export function documentationToMarkdown(
|
||||
documentation: readonly Proto.SymbolDisplayPart[] | string,
|
||||
tags: readonly Proto.JSDocTagInfo[],
|
||||
filePathConverter: IFilePathToResourceConverter,
|
||||
baseUri: vscode.Uri | undefined,
|
||||
): vscode.MarkdownString {
|
||||
const out = new vscode.MarkdownString();
|
||||
addMarkdownDocumentation(out, documentation, tags, filePathConverter);
|
||||
appendDocumentationAsMarkdown(out, documentation, tags, filePathConverter);
|
||||
out.baseUri = baseUri;
|
||||
return out;
|
||||
}
|
||||
|
||||
export function addMarkdownDocumentation(
|
||||
export function appendDocumentationAsMarkdown(
|
||||
out: vscode.MarkdownString,
|
||||
documentation: readonly Proto.SymbolDisplayPart[] | string | undefined,
|
||||
tags: readonly Proto.JSDocTagInfo[] | undefined,
|
||||
converter: IFilePathToResourceConverter,
|
||||
): vscode.MarkdownString {
|
||||
if (documentation) {
|
||||
out.appendMarkdown(plainWithLinks(documentation, converter));
|
||||
out.appendMarkdown(asPlainTextWithLinks(documentation, converter));
|
||||
}
|
||||
|
||||
if (tags) {
|
||||
const tagsPreview = tagsMarkdownPreview(tags, converter);
|
||||
const tagsPreview = tagsToMarkdown(tags, converter);
|
||||
if (tagsPreview) {
|
||||
out.appendMarkdown('\n\n' + tagsPreview);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function escapeMarkdownSyntaxTokensForCode(text: string): string {
|
||||
return text.replace(/`/g, '\\$&');
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import * as assert from 'assert';
|
||||
import 'mocha';
|
||||
import { Uri } from 'vscode';
|
||||
import { IFilePathToResourceConverter, markdownDocumentation, plainWithLinks, tagsMarkdownPreview } from '../../languageFeatures/util/textRendering';
|
||||
import { IFilePathToResourceConverter, documentationToMarkdown, asPlainTextWithLinks, tagsToMarkdown } from '../../languageFeatures/util/textRendering';
|
||||
import { SymbolDisplayPart } from '../../tsServer/protocol/protocol';
|
||||
|
||||
const noopToResource: IFilePathToResourceConverter = {
|
||||
@@ -16,7 +16,7 @@ const noopToResource: IFilePathToResourceConverter = {
|
||||
suite('typescript.previewer', () => {
|
||||
test('Should ignore hyphens after a param tag', async () => {
|
||||
assert.strictEqual(
|
||||
tagsMarkdownPreview([
|
||||
tagsToMarkdown([
|
||||
{
|
||||
name: 'param',
|
||||
text: 'a - b'
|
||||
@@ -27,7 +27,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should parse url jsdoc @link', async () => {
|
||||
assert.strictEqual(
|
||||
markdownDocumentation(
|
||||
documentationToMarkdown(
|
||||
'x {@link http://www.example.com/foo} y {@link https://api.jquery.com/bind/#bind-eventType-eventData-handler} z',
|
||||
[],
|
||||
noopToResource, undefined
|
||||
@@ -37,7 +37,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should parse url jsdoc @link with text', async () => {
|
||||
assert.strictEqual(
|
||||
markdownDocumentation(
|
||||
documentationToMarkdown(
|
||||
'x {@link http://www.example.com/foo abc xyz} y {@link http://www.example.com/bar|b a z} z',
|
||||
[],
|
||||
noopToResource, undefined
|
||||
@@ -47,7 +47,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should treat @linkcode jsdocs links as monospace', async () => {
|
||||
assert.strictEqual(
|
||||
markdownDocumentation(
|
||||
documentationToMarkdown(
|
||||
'x {@linkcode http://www.example.com/foo} y {@linkplain http://www.example.com/bar} z',
|
||||
[],
|
||||
noopToResource, undefined
|
||||
@@ -57,7 +57,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should parse url jsdoc @link in param tag', async () => {
|
||||
assert.strictEqual(
|
||||
tagsMarkdownPreview([
|
||||
tagsToMarkdown([
|
||||
{
|
||||
name: 'param',
|
||||
text: 'a x {@link http://www.example.com/foo abc xyz} y {@link http://www.example.com/bar|b a z} z'
|
||||
@@ -68,7 +68,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should ignore unclosed jsdocs @link', async () => {
|
||||
assert.strictEqual(
|
||||
markdownDocumentation(
|
||||
documentationToMarkdown(
|
||||
'x {@link http://www.example.com/foo y {@link http://www.example.com/bar bar} z',
|
||||
[],
|
||||
noopToResource, undefined
|
||||
@@ -78,7 +78,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should support non-ascii characters in parameter name (#90108)', async () => {
|
||||
assert.strictEqual(
|
||||
tagsMarkdownPreview([
|
||||
tagsToMarkdown([
|
||||
{
|
||||
name: 'param',
|
||||
text: 'parámetroConDiacríticos this will not'
|
||||
@@ -89,7 +89,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should render @example blocks as code', () => {
|
||||
assert.strictEqual(
|
||||
tagsMarkdownPreview([
|
||||
tagsToMarkdown([
|
||||
{
|
||||
name: 'example',
|
||||
text: 'code();'
|
||||
@@ -101,7 +101,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should not render @example blocks as code as if they contain a codeblock', () => {
|
||||
assert.strictEqual(
|
||||
tagsMarkdownPreview([
|
||||
tagsToMarkdown([
|
||||
{
|
||||
name: 'example',
|
||||
text: 'Not code\n```\ncode();\n```'
|
||||
@@ -113,7 +113,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should render @example blocks as code if they contain a <caption>', () => {
|
||||
assert.strictEqual(
|
||||
tagsMarkdownPreview([
|
||||
tagsToMarkdown([
|
||||
{
|
||||
name: 'example',
|
||||
text: '<caption>Not code</caption>\ncode();'
|
||||
@@ -125,7 +125,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should not render @example blocks as code if they contain a <caption> and a codeblock', () => {
|
||||
assert.strictEqual(
|
||||
tagsMarkdownPreview([
|
||||
tagsToMarkdown([
|
||||
{
|
||||
name: 'example',
|
||||
text: '<caption>Not code</caption>\n```\ncode();\n```'
|
||||
@@ -137,7 +137,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should render @linkcode symbol name as code', async () => {
|
||||
assert.strictEqual(
|
||||
plainWithLinks([
|
||||
asPlainTextWithLinks([
|
||||
{ "text": "a ", "kind": "text" },
|
||||
{ "text": "{@linkcode ", "kind": "link" },
|
||||
{
|
||||
@@ -157,7 +157,7 @@ suite('typescript.previewer', () => {
|
||||
|
||||
test('Should render @linkcode text as code', async () => {
|
||||
assert.strictEqual(
|
||||
plainWithLinks([
|
||||
asPlainTextWithLinks([
|
||||
{ "text": "a ", "kind": "text" },
|
||||
{ "text": "{@linkcode ", "kind": "link" },
|
||||
{
|
||||
Reference in New Issue
Block a user