Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | // src/providers/BladeComponentRenameHandler.ts // Smart rename: when a Blade component .blade.php is renamed, update all <x-tag> usages import * as vscode from 'vscode'; import * as path from 'path'; import type { CacheManager } from '../cache/CacheManager'; // ─── Blade Component Rename Handler ────────────────────────────────────── export class BladeComponentRenameHandler implements vscode.Disposable { private readonly disposables: vscode.Disposable[] = []; constructor( private readonly cache: CacheManager, private readonly workspaceRoot: string ) { this.disposables.push( vscode.workspace.onDidRenameFiles((e) => void this.handleRename(e)) ); } private async handleRename(e: vscode.FileRenameEvent): Promise<void> { for (const { oldUri, newUri } of e.files) { if (!oldUri.fsPath.endsWith('.blade.php')) { continue; } if (!oldUri.fsPath.includes('components')) { continue; } const viewRoot = path.join(this.workspaceRoot, 'resources', 'views', 'components'); if (!oldUri.fsPath.startsWith(viewRoot)) { continue; } const oldName = path.relative(viewRoot, oldUri.fsPath) .replace(/\.blade\.php$/, '') .replace(/[/\\]/g, '.'); const newName = path.relative(viewRoot, newUri.fsPath) .replace(/\.blade\.php$/, '') .replace(/[/\\]/g, '.'); const oldTag = `x-${oldName.replace(/\./g, '-')}`; const newTag = `x-${newName.replace(/\./g, '-')}`; if (oldTag === newTag) { continue; } const bladeFiles = await vscode.workspace.findFiles( new vscode.RelativePattern(this.workspaceRoot, '**/*.blade.php'), '{vendor/**,node_modules/**}' ); const edit = new vscode.WorkspaceEdit(); let count = 0; for (const fileUri of bladeFiles) { const doc = await vscode.workspace.openTextDocument(fileUri); const text = doc.getText(); const escaped = oldTag.replace(/[-]/g, '[\\-]'); const re = new RegExp(`<(${escaped})(\\s|/|>)`, 'g'); let m: RegExpExecArray | null; while ((m = re.exec(text)) !== null) { const start = doc.positionAt(m.index + 1); const end = doc.positionAt(m.index + 1 + oldTag.length); edit.replace(fileUri, new vscode.Range(start, end), newTag); // Also close tag const closeRe = new RegExp(`</(${escaped})>`, 'g'); let cm: RegExpExecArray | null; while ((cm = closeRe.exec(text)) !== null) { const cs = doc.positionAt(cm.index + 2); const ce = doc.positionAt(cm.index + 2 + oldTag.length); edit.replace(fileUri, new vscode.Range(cs, ce), newTag); } count++; } } if (count > 0) { await vscode.workspace.applyEdit(edit); vscode.window.showInformationMessage( `[Maestro] Renamed Blade component: <${oldTag}> → <${newTag}> (${count} updated)` ); } // Also update the cache const index = this.cache.getIndex(); const updatedComponents = new Map(index.bladeComponents); const existing = updatedComponents.get(oldName); if (existing) { updatedComponents.delete(oldName); updatedComponents.set(newName, { ...existing, name: newName, tag: newTag }); this.cache.updateIndex({ bladeComponents: updatedComponents }); } } } dispose(): void { for (const d of this.disposables) { d.dispose(); } } } // ─── toResource() / toResourceCollection() CodeLens ───────────────────── export class ResourceRedirectProvider implements vscode.CodeLensProvider { constructor(private readonly cache: CacheManager) {} provideCodeLenses(document: vscode.TextDocument): vscode.CodeLens[] { if (!document.fileName.endsWith('.php')) { return []; } const text = document.getText(); if (!text.includes('extends Model')) { return []; } const classMatch = /class\s+(\w+)\s+extends/.exec(text); if (!classMatch) { return []; } const className = classMatch[1]; const index = this.cache.getIndex(); const hasResource = Array.from(index.classes.values()).some( (cls) => cls.name === `${className}Resource` ); if (!hasResource) { return []; } const line = (text.slice(0, text.indexOf(classMatch[0])).match(/\n/g) ?? []).length; return [ new vscode.CodeLens(new vscode.Range(line, 0, line, 0), { title: `📦 ${className}Resource::make()`, command: 'laravelMaestro.navigateToResource', arguments: [`${className}Resource`], tooltip: `Navigate to ${className}Resource`, }), ]; } } // ─── Validation rule string intention (add 'max:255', 'unique' etc.) ────── export class ValidationStringIntentionProvider implements vscode.CodeActionProvider { static readonly providedCodeActionKinds = [vscode.CodeActionKind.QuickFix]; provideCodeActions( document: vscode.TextDocument, range: vscode.Range ): vscode.CodeAction[] { const lineText = document.lineAt(range.start.line).text; if (!/'([^']*)'/.test(lineText) || !lineText.includes('=>')) { return []; } // Check if this looks like a validation rules array entry const isRulesContext = /rules\s*\(\s*\)|\$rules\s*=\s*\[/.test( document.getText(new vscode.Range(new vscode.Position(0, 0), range.start)) ); if (!isRulesContext) { return []; } const actions: vscode.CodeAction[] = []; const commonRules = [ 'required', 'nullable', 'string', 'integer', 'boolean', 'array', 'email', 'url', 'max:255', 'min:1', 'unique:table', 'exists:table,id', 'confirmed', 'date', 'numeric', 'alpha', 'alpha_num', 'in:a,b,c', 'not_in:a,b', 'regex:/pattern/', 'between:1,100', 'size:10', 'digits:10', 'mimes:jpg,png', 'image', 'file', 'sometimes', 'prohibited', 'present', 'missing', ]; for (const rule of commonRules) { const action = new vscode.CodeAction(`+ Add '${rule}'`, vscode.CodeActionKind.QuickFix); action.command = { command: 'laravelMaestro.addValidationRule', title: `Add '${rule}'`, arguments: [document, range, rule], }; actions.push(action); } return actions; } } |