From fce6b6161e478a3ac6d10f0e2f09d6143e17fdc6 Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Mon, 7 Sep 2020 22:35:01 +0200 Subject: [PATCH 1/4] Add deprecated diagnostic tag if a symbol is reported as deprecated --- src/languageFeatures.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index 8eb39ec..8338b91 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -330,6 +330,10 @@ export class DiagnosticsAdapter extends Adapter { column: endColumn } = model.getPositionAt(diagStart + diagLength); + const tags: MarkerTag[] = []; + if (diag.reportsUnnecessary) tags.push(MarkerTag.Unnecessary); + if (diag.reportsDeprecated) tags.push(MarkerTag.Deprecated); + return { severity: this._tsDiagnosticCategoryToMarkerSeverity(diag.category), startLineNumber, @@ -338,7 +342,7 @@ export class DiagnosticsAdapter extends Adapter { endColumn, message: flattenDiagnosticMessageText(diag.messageText, '\n'), code: diag.code.toString(), - tags: diag.reportsUnnecessary ? [MarkerTag.Unnecessary] : [], + tags, relatedInformation: this._convertRelatedInformation( model, diag.relatedInformation From a258f3a296e76001ce210d7f8bcdf551762eb7e4 Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Mon, 7 Sep 2020 22:58:28 +0200 Subject: [PATCH 2/4] Add deprecated tag to suggestion if entry is marked as deprecated --- src/languageFeatures.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index 8338b91..d4fe4e5 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -460,6 +460,10 @@ export class SuggestAdapter range = new Range(p1.lineNumber, p1.column, p2.lineNumber, p2.column); } + const tags: languages.CompletionItemTag[] = []; + if (entry.kindModifiers?.indexOf('deprecated') !== -1) + tags.push(languages.CompletionItemTag.Deprecated); + return { uri: resource, position: position, @@ -467,7 +471,8 @@ export class SuggestAdapter label: entry.name, insertText: entry.name, sortText: entry.sortText, - kind: SuggestAdapter.convertKind(entry.kind) + kind: SuggestAdapter.convertKind(entry.kind), + tags }; }); From 5f2d3f73ab37c1cfd7fdb4ef706cbce490ca8e13 Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Mon, 7 Sep 2020 23:49:30 +0200 Subject: [PATCH 3/4] Include tags in documentation string of suggestion items --- src/languageFeatures.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index d4fe4e5..c59d19a 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -508,7 +508,7 @@ export class SuggestAdapter kind: SuggestAdapter.convertKind(details.kind), detail: displayPartsToString(details.displayParts), documentation: { - value: displayPartsToString(details.documentation) + value: SuggestAdapter.createDocumentationString(details) } }; } @@ -545,6 +545,25 @@ export class SuggestAdapter return languages.CompletionItemKind.Property; } + + private static createDocumentationString( + details: ts.CompletionEntryDetails + ): string { + let documentationString = displayPartsToString(details.documentation); + if (details.tags) { + for (const tag of details.tags) { + documentationString += `\n\n*@${tag.name}*`; + if (tag.name === 'param' && tag.text) { + const [paramName, ...rest] = tag.text.split(' '); + documentationString += `\`${paramName}\``; + if (rest.length > 0) documentationString += ` — ${rest.join(' ')}`; + } else if (tag.text) { + documentationString += ` — ${tag.text}`; + } + } + } + return documentationString; + } } export class SignatureHelpAdapter From 85c67d753f5d5a8e355d5cc55a138c263d9f26ad Mon Sep 17 00:00:00 2001 From: Sebastian Pahnke Date: Mon, 7 Sep 2020 23:59:30 +0200 Subject: [PATCH 4/4] Align tag representation in suggestion items and hovers --- src/languageFeatures.ts | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index c59d19a..794c852 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -552,20 +552,25 @@ export class SuggestAdapter let documentationString = displayPartsToString(details.documentation); if (details.tags) { for (const tag of details.tags) { - documentationString += `\n\n*@${tag.name}*`; - if (tag.name === 'param' && tag.text) { - const [paramName, ...rest] = tag.text.split(' '); - documentationString += `\`${paramName}\``; - if (rest.length > 0) documentationString += ` — ${rest.join(' ')}`; - } else if (tag.text) { - documentationString += ` — ${tag.text}`; - } + documentationString += `\n\n${tagToString(tag)}`; } } return documentationString; } } +function tagToString(tag: ts.JSDocTagInfo): string { + let tagLabel = `*@${tag.name}*`; + if (tag.name === 'param' && tag.text) { + const [paramName, ...rest] = tag.text.split(' '); + tagLabel += `\`${paramName}\``; + if (rest.length > 0) tagLabel += ` — ${rest.join(' ')}`; + } else if (tag.text) { + tagLabel += ` — ${tag.text}`; + } + return tagLabel; +} + export class SignatureHelpAdapter extends Adapter implements languages.SignatureHelpProvider { @@ -653,18 +658,7 @@ export class QuickInfoAdapter const documentation = displayPartsToString(info.documentation); const tags = info.tags - ? info.tags - .map((tag) => { - const label = `*@${tag.name}*`; - if (!tag.text) { - return label; - } - return ( - label + - (tag.text.match(/\r\n|\n/g) ? ' \n' + tag.text : ` - ${tag.text}`) - ); - }) - .join(' \n\n') + ? info.tags.map((tag) => tagToString(tag)).join(' \n\n') : ''; const contents = displayPartsToString(info.displayParts); return {