import * as vscode from 'vscode' import { tc } from '../helpers/TsComplier' import { utils } from '../utils' export class SubviewHover { public async getHover(word: string, completion: vscode.CompletionItem[]) { for (const item of completion) { const label = item.label if (label === word) { const title = item.documentation?.toString() || '' const detail = await this.getHoverDetail(label) const el = `<${label}>` const docz = '[组件实现文档](https://nightingales.yuque.com/n_tech/winged/gsbxxv)' const mdStr = new vscode.MarkdownString() mdStr.appendCodeblock(el, 'html') mdStr.appendCodeblock(title) mdStr.appendCodeblock(detail?.highLight || '', 'typescript') mdStr.appendCodeblock(detail?.normal || '') mdStr.appendMarkdown(docz) return new vscode.Hover(mdStr) } } return null } private async getHoverDetail(compName: string) { const desps = await tc.getAllDesp(compName) if (desps) { const propsType = desps.propsType || '' const eventsType = desps.evensType || '' const d1 = utils.marshalIndent(propsType, 'PropsType ') const d2 = 'vMethods:' + JSON.stringify(desps.vMethods?.map((e) => e.name)) const d3 = utils.marshalIndent(eventsType, 'EventsType') return { highLight: `${d1}\n${d3}`, normal: d2, } } } }