Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #67 from spahnke/deprecated-api
Browse files Browse the repository at this point in the history
Adopt "deprecated" API
  • Loading branch information
alexdima authored Sep 8, 2020
2 parents 8dcc86c + 8cff40c commit 926a105
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions src/languageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -456,14 +460,19 @@ 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,
range: range,
label: entry.name,
insertText: entry.name,
sortText: entry.sortText,
kind: SuggestAdapter.convertKind(entry.kind)
kind: SuggestAdapter.convertKind(entry.kind),
tags
};
});

Expand Down Expand Up @@ -499,7 +508,7 @@ export class SuggestAdapter
kind: SuggestAdapter.convertKind(details.kind),
detail: displayPartsToString(details.displayParts),
documentation: {
value: displayPartsToString(details.documentation)
value: SuggestAdapter.createDocumentationString(details)
}
};
}
Expand Down Expand Up @@ -536,6 +545,30 @@ 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${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
Expand Down Expand Up @@ -625,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 {
Expand Down

0 comments on commit 926a105

Please sign in to comment.