import { Completion } from './Completion' import * as vscode from 'vscode' import { tc } from '../helpers/TsComplier' import { completionRefreshDelay } from '../readConfig' import { utils } from '../utils' export class SubviewMethodCompletion extends Completion { public completionArr: vscode.CompletionItem[] = [] protected triggerRangeMatcher: RegExp = /@method:/ private timerCache: number = 0 public validateContext(document: vscode.TextDocument, position: vscode.Position): boolean { if (document.getWordRangeAtPosition(position, this.triggerRangeMatcher)) { return true } return false } protected getCompletionItem(label: string, desp: string): vscode.CompletionItem { return { label, detail: desp, kind: vscode.CompletionItemKind.Field, insertText: new vscode.SnippetString(`${label}="\${1:bind${utils.camelToPascal(label)}}"`), } } public async getCompletionArr(document: vscode.TextDocument, position: vscode.Position) { const res = tc.validateTagRange(document, position, '@method:') if (res !== undefined && res.type === 'comp') { const now = Date.now() if (now - this.timerCache > completionRefreshDelay) { const methods = await tc.getMethods(res.name) if (methods) { this.completionArr = methods.map((item) => { return this.getCompletionItem(item.name, item.desp) }) this.timerCache = now return this.completionArr } } return this.completionArr } } }