import * as vscode from 'vscode' import { tc } from '../helpers/TsComplier' import { Dict } from '../type' import { utils } from '../utils' export class SubviewAttrHover { public async getHover(word: string, compName: string): Promise { const propsDesp = await tc.getPropsDespByCompName(compName) if (propsDesp) { const must = propsDesp[word] if (must) { return this.getHoverMessage(word, must, 'property') } const choosable = propsDesp[`${word}?`] if (choosable) { return this.getHoverMessage(`${word}?`, choosable, 'property') } } const eventsDesp = await tc.getEventsTypeDespByCompName(compName) if (eventsDesp) { const must = eventsDesp[word] if (must) { return this.getHoverMessage(word, must, 'event') } const choosable = eventsDesp[`${word}?`] if (choosable) { return this.getHoverMessage(`${word}?`, choosable, 'event') } } return null } private getHoverMessage(name: string, desp: Dict | string, type?: 'property' | 'event') { const mdStr = new vscode.MarkdownString() const prefix = `(${type})` const details = utils.marshalIndent(desp) mdStr.appendCodeblock(`${prefix} ${name} : ${details}`, 'typescript') return new vscode.Hover(mdStr) } }