parent
d10bab9072
commit
b8430bd4bb
4 changed files with 23 additions and 20 deletions
|
@ -251,7 +251,7 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
|||
}
|
||||
const detail = details[0]
|
||||
if (!item.detail && detail.displayParts.length) {
|
||||
item.detail = Previewer.plain(detail.displayParts)
|
||||
item.detail = Previewer.plainWithLinks(detail.displayParts)
|
||||
}
|
||||
item.documentation = this.getDocumentation(detail)
|
||||
const { command, additionalTextEdits } = this.getCodeActions(detail, filepath)
|
||||
|
@ -354,12 +354,12 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
|||
private getDocumentation(detail: Proto.CompletionEntryDetails): MarkupContent | undefined {
|
||||
let documentation = ''
|
||||
if (detail.source) {
|
||||
const importPath = `'${Previewer.plain(detail.source)}'`
|
||||
const importPath = `'${Previewer.plainWithLinks(detail.source)}'`
|
||||
const autoImportLabel = `Auto import from ${importPath}`
|
||||
documentation += `${autoImportLabel}\n`
|
||||
}
|
||||
let parts = [
|
||||
Previewer.plain(detail.documentation),
|
||||
Previewer.plainWithLinks(detail.documentation),
|
||||
Previewer.tagsMarkdownPreview(detail.tags)
|
||||
]
|
||||
parts = parts.filter(s => s && s.trim() != '')
|
||||
|
|
|
@ -7,7 +7,7 @@ import { HoverProvider } from 'coc.nvim'
|
|||
import { CancellationToken, Hover, MarkedString, Position } from 'vscode-languageserver-protocol'
|
||||
import * as Proto from '../protocol'
|
||||
import { ITypeScriptServiceClient } from '../typescriptService'
|
||||
import { tagsMarkdownPreview } from '../utils/previewer'
|
||||
import { markdownDocumentation } from '../utils/previewer'
|
||||
import * as typeConverters from '../utils/typeConverters'
|
||||
|
||||
export default class TypeScriptHoverProvider implements HoverProvider {
|
||||
|
@ -42,14 +42,16 @@ export default class TypeScriptHoverProvider implements HoverProvider {
|
|||
}
|
||||
|
||||
private static getContents(data: Proto.QuickInfoResponseBody): MarkedString[] { // tslint:disable-line
|
||||
const parts = []
|
||||
|
||||
const parts: MarkedString[] = []
|
||||
if (data.displayString) {
|
||||
// const displayParts: string[] = []
|
||||
parts.push({ language: 'typescript', value: data.displayString })
|
||||
}
|
||||
|
||||
const tags = tagsMarkdownPreview(data.tags)
|
||||
parts.push(data.documentation + (tags ? '\n\n' + tags : ''))
|
||||
const markup = markdownDocumentation(data.documentation, data.tags)
|
||||
parts.push({
|
||||
language: 'markdown',
|
||||
value: markup.value
|
||||
})
|
||||
return parts
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,13 +60,13 @@ export default class TypeScriptSignatureHelpProvider implements SignatureHelpPro
|
|||
private convertSignature(item: Proto.SignatureHelpItem): SignatureInformation {
|
||||
let parameters = item.parameters.map(p => {
|
||||
return {
|
||||
label: Previewer.plain(p.displayParts),
|
||||
label: Previewer.plainWithLinks(p.displayParts),
|
||||
documentation: Previewer.markdownDocumentation(p.documentation, [])
|
||||
}
|
||||
})
|
||||
let label = Previewer.plain(item.prefixDisplayParts)
|
||||
label += parameters.map(parameter => parameter.label).join(Previewer.plain(item.separatorDisplayParts))
|
||||
label += Previewer.plain(item.suffixDisplayParts)
|
||||
let label = Previewer.plainWithLinks(item.prefixDisplayParts)
|
||||
label += parameters.map(parameter => parameter.label).join(Previewer.plainWithLinks(item.separatorDisplayParts))
|
||||
label += Previewer.plainWithLinks(item.suffixDisplayParts)
|
||||
return {
|
||||
label,
|
||||
documentation: Previewer.markdownDocumentation(
|
||||
|
|
|
@ -94,20 +94,15 @@ function getTagDocumentation(tag: Proto.JSDocTagInfo): string | undefined {
|
|||
return label + (text.match(/\r\n|\n/g) ? ' \n' + text : ` — ${text}`)
|
||||
}
|
||||
|
||||
export function plain(parts: Proto.SymbolDisplayPart[]): string {
|
||||
if (!parts || !parts.length) return ''
|
||||
return parts.map(part => part.text).join('')
|
||||
}
|
||||
|
||||
export function tagsMarkdownPreview(tags: Proto.JSDocTagInfo[]): string {
|
||||
return (tags || []).map(getTagDocumentation).join(' \n\n')
|
||||
}
|
||||
|
||||
export function markdownDocumentation(
|
||||
documentation: Proto.SymbolDisplayPart[],
|
||||
documentation: Proto.SymbolDisplayPart[] | string,
|
||||
tags: Proto.JSDocTagInfo[]
|
||||
): MarkupContent {
|
||||
let out = plain(documentation)
|
||||
let out = plainWithLinks(documentation)
|
||||
const tagsPreview = tagsMarkdownPreview(tags)
|
||||
if (tagsPreview) {
|
||||
out = out + ('\n\n' + tagsPreview)
|
||||
|
@ -118,6 +113,12 @@ export function markdownDocumentation(
|
|||
}
|
||||
}
|
||||
|
||||
export function plainWithLinks(
|
||||
parts: readonly Proto.SymbolDisplayPart[] | string,
|
||||
): string {
|
||||
return processInlineTags(convertLinkTags(parts))
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert `@link` inline tags to markdown links
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue