import * as vscode from 'vscode' import * as path from 'path' import { fm } from '../helpers/FileManage' export abstract class Definition { /** * 代码跳转 * @param fragments 要跳转的可匹配的正则字符串 */ protected async basicLocation(fragments: string, targetType: 'ts' | 'v' | 'less' | 'html', subviewName?: string) { const filePath = vscode.window.activeTextEditor?.document.fileName if (filePath) { const compName = subviewName ? subviewName : fm.getCompNameByPath(filePath) const compsDir = path.join(fm.getRootPath()!, fm.getDirByFileType(targetType)) const fileType = targetType === 'v' ? '.v.ts' : `.${targetType}` const targetPath = fm.getFilePathByName(fm.getFileName(compName, fileType as '.ts'), compsDir) if (targetPath) { const res = await vscode.workspace.openTextDocument(targetPath) let i = 0 while (i <= res.lineCount) { const lineText = res.lineAt(i) if (!lineText.isEmptyOrWhitespace) { if (lineText.text.match(new RegExp(fragments))) { break } } i++ } if (i >= res.lineCount) { i = 0 } return new vscode.Location(vscode.Uri.file(targetPath), new vscode.Position(i, fragments.length + 2)) } } } /** * * @param args */ public abstract validateContext(...args: any[]): boolean }