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]
|
const detail = details[0]
|
||||||
if (!item.detail && detail.displayParts.length) {
|
if (!item.detail && detail.displayParts.length) {
|
||||||
item.detail = Previewer.plain(detail.displayParts)
|
item.detail = Previewer.plainWithLinks(detail.displayParts)
|
||||||
}
|
}
|
||||||
item.documentation = this.getDocumentation(detail)
|
item.documentation = this.getDocumentation(detail)
|
||||||
const { command, additionalTextEdits } = this.getCodeActions(detail, filepath)
|
const { command, additionalTextEdits } = this.getCodeActions(detail, filepath)
|
||||||
|
@ -354,12 +354,12 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
|
||||||
private getDocumentation(detail: Proto.CompletionEntryDetails): MarkupContent | undefined {
|
private getDocumentation(detail: Proto.CompletionEntryDetails): MarkupContent | undefined {
|
||||||
let documentation = ''
|
let documentation = ''
|
||||||
if (detail.source) {
|
if (detail.source) {
|
||||||
const importPath = `'${Previewer.plain(detail.source)}'`
|
const importPath = `'${Previewer.plainWithLinks(detail.source)}'`
|
||||||
const autoImportLabel = `Auto import from ${importPath}`
|
const autoImportLabel = `Auto import from ${importPath}`
|
||||||
documentation += `${autoImportLabel}\n`
|
documentation += `${autoImportLabel}\n`
|
||||||
}
|
}
|
||||||
let parts = [
|
let parts = [
|
||||||
Previewer.plain(detail.documentation),
|
Previewer.plainWithLinks(detail.documentation),
|
||||||
Previewer.tagsMarkdownPreview(detail.tags)
|
Previewer.tagsMarkdownPreview(detail.tags)
|
||||||
]
|
]
|
||||||
parts = parts.filter(s => s && s.trim() != '')
|
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 { CancellationToken, Hover, MarkedString, Position } from 'vscode-languageserver-protocol'
|
||||||
import * as Proto from '../protocol'
|
import * as Proto from '../protocol'
|
||||||
import { ITypeScriptServiceClient } from '../typescriptService'
|
import { ITypeScriptServiceClient } from '../typescriptService'
|
||||||
import { tagsMarkdownPreview } from '../utils/previewer'
|
import { markdownDocumentation } from '../utils/previewer'
|
||||||
import * as typeConverters from '../utils/typeConverters'
|
import * as typeConverters from '../utils/typeConverters'
|
||||||
|
|
||||||
export default class TypeScriptHoverProvider implements HoverProvider {
|
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
|
private static getContents(data: Proto.QuickInfoResponseBody): MarkedString[] { // tslint:disable-line
|
||||||
const parts = []
|
const parts: MarkedString[] = []
|
||||||
|
|
||||||
if (data.displayString) {
|
if (data.displayString) {
|
||||||
|
// const displayParts: string[] = []
|
||||||
parts.push({ language: 'typescript', value: data.displayString })
|
parts.push({ language: 'typescript', value: data.displayString })
|
||||||
}
|
}
|
||||||
|
const markup = markdownDocumentation(data.documentation, data.tags)
|
||||||
const tags = tagsMarkdownPreview(data.tags)
|
parts.push({
|
||||||
parts.push(data.documentation + (tags ? '\n\n' + tags : ''))
|
language: 'markdown',
|
||||||
|
value: markup.value
|
||||||
|
})
|
||||||
return parts
|
return parts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,13 +60,13 @@ export default class TypeScriptSignatureHelpProvider implements SignatureHelpPro
|
||||||
private convertSignature(item: Proto.SignatureHelpItem): SignatureInformation {
|
private convertSignature(item: Proto.SignatureHelpItem): SignatureInformation {
|
||||||
let parameters = item.parameters.map(p => {
|
let parameters = item.parameters.map(p => {
|
||||||
return {
|
return {
|
||||||
label: Previewer.plain(p.displayParts),
|
label: Previewer.plainWithLinks(p.displayParts),
|
||||||
documentation: Previewer.markdownDocumentation(p.documentation, [])
|
documentation: Previewer.markdownDocumentation(p.documentation, [])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
let label = Previewer.plain(item.prefixDisplayParts)
|
let label = Previewer.plainWithLinks(item.prefixDisplayParts)
|
||||||
label += parameters.map(parameter => parameter.label).join(Previewer.plain(item.separatorDisplayParts))
|
label += parameters.map(parameter => parameter.label).join(Previewer.plainWithLinks(item.separatorDisplayParts))
|
||||||
label += Previewer.plain(item.suffixDisplayParts)
|
label += Previewer.plainWithLinks(item.suffixDisplayParts)
|
||||||
return {
|
return {
|
||||||
label,
|
label,
|
||||||
documentation: Previewer.markdownDocumentation(
|
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}`)
|
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 {
|
export function tagsMarkdownPreview(tags: Proto.JSDocTagInfo[]): string {
|
||||||
return (tags || []).map(getTagDocumentation).join(' \n\n')
|
return (tags || []).map(getTagDocumentation).join(' \n\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function markdownDocumentation(
|
export function markdownDocumentation(
|
||||||
documentation: Proto.SymbolDisplayPart[],
|
documentation: Proto.SymbolDisplayPart[] | string,
|
||||||
tags: Proto.JSDocTagInfo[]
|
tags: Proto.JSDocTagInfo[]
|
||||||
): MarkupContent {
|
): MarkupContent {
|
||||||
let out = plain(documentation)
|
let out = plainWithLinks(documentation)
|
||||||
const tagsPreview = tagsMarkdownPreview(tags)
|
const tagsPreview = tagsMarkdownPreview(tags)
|
||||||
if (tagsPreview) {
|
if (tagsPreview) {
|
||||||
out = out + ('\n\n' + 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
|
* Convert `@link` inline tags to markdown links
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue