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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | // src/providers/Laravel13AiProvider.ts // Full Laravel 13 AI SDK intelligence — completions, hover, generators, diagnostics import * as vscode from 'vscode'; import * as path from 'path'; import * as fs from 'fs'; import type { CacheManager } from '../cache/CacheManager'; // ─── AI SDK Method Catalog ──────────────────────────────────────────────── const AI_TEXT_METHODS = [ { name: 'generate', sig: '(prompt: string): TextResponse', doc: 'Generate text from a plain prompt. Returns a TextResponse.' }, { name: 'prompt', sig: '(prompt: string): TextResponse', doc: 'Alias for generate() — preferred in agent context.' }, { name: 'using', sig: '(provider: string): static', doc: 'Pin to a specific provider (e.g. "openai", "anthropic", "deepseek").' }, { name: 'withSystemPrompt', sig: '(prompt: string): static', doc: 'Set a system-level instruction.' }, { name: 'withMessages', sig: '(messages: array): static', doc: 'Supply full conversation history.' }, { name: 'withTools', sig: '(tools: array): static', doc: 'Register tool-calling definitions.' }, { name: 'withProviderOptions', sig: '(options: array): static', doc: 'Pass provider-specific options (e.g. reasoning.effort for o3).' }, { name: 'stream', sig: '(prompt: string): StreamResponse', doc: 'Stream text tokens as they are generated.' }, { name: 'maxTokens', sig: '(tokens: int): static', doc: 'Cap the response length.' }, { name: 'temperature', sig: '(temp: float): static', doc: 'Control response randomness (0.0–2.0).' }, { name: 'onChunk', sig: '(callback: Closure): static', doc: 'Handle each streamed chunk individually.' }, ]; const AI_FACADE_CALLS = [ // Text { name: 'Ai::text', sig: '(prompt?: string): TextRequest', doc: 'Start a text generation request.' }, { name: 'Ai::generate', sig: '(prompt: string): TextResponse', doc: 'Shorthand text generation.' }, // Embeddings { name: 'Ai::embed', sig: '(input: string|array): Embedding', doc: 'Generate vector embeddings for semantic search.' }, // Images { name: 'Ai::image', sig: '(prompt: string): ImageResponse', doc: 'Generate an image from a text prompt.' }, // Audio { name: 'Ai::audio', sig: '(): AudioRequest', doc: 'Start an audio synthesis request.' }, // Agents { name: 'Ai::agent', sig: '(agent: string|Agent): AgentRunner', doc: 'Run a named or anonymous agent.' }, // Vector stores { name: 'Ai::vectorStore', sig: '(name: string): VectorStore', doc: 'Access a named vector store.' }, ]; const AI_AUDIO_METHODS = [ { name: 'of', sig: "(text: string): static", doc: 'Set the text to synthesize.' }, { name: 'generate', sig: "(): AudioResponse", doc: 'Synthesize audio from text.' }, { name: 'using', sig: "(provider: string): static", doc: 'Pin provider for this request.' }, { name: 'voice', sig: "(name: string): static", doc: 'Choose a voice name (e.g. "alloy", "nova").' }, { name: 'speed', sig: "(speed: float): static", doc: 'Playback speed (0.25–4.0).' }, { name: 'format', sig: "(format: string): static", doc: 'Output format: "mp3", "wav", "opus".' }, { name: 'asBase64', sig: "(): string", doc: 'Return audio as base64 string.' }, { name: 'asStream', sig: "(): StreamInterface", doc: 'Stream the audio bytes.' }, { name: 'transcribe', sig: "(file: UploadedFile): string", doc: 'Transcribe audio to text (Whisper).' }, ]; const AI_IMAGE_METHODS = [ { name: 'generate', sig: "(): ImageResponse", doc: 'Generate the image.' }, { name: 'using', sig: "(provider: string): static", doc: 'Pin provider (e.g. "openai", "stability").' }, { name: 'size', sig: "(size: string): static", doc: 'Image size: "1024x1024", "1792x1024", etc.' }, { name: 'style', sig: "(style: string): static", doc: '"vivid" or "natural" (OpenAI DALL-E).' }, { name: 'quality', sig: "(quality: string): static", doc: '"standard" or "hd".' }, { name: 'n', sig: "(count: int): static", doc: 'Number of images to generate.' }, { name: 'url', sig: "(): string", doc: 'Get the generated image URL.' }, { name: 'base64', sig: "(): string", doc: 'Get image as base64 string.' }, { name: 'response', sig: "(): array", doc: 'Raw provider response.' }, ]; const AI_VECTOR_METHODS = [ // Query builder extensions (Laravel 13) { name: 'whereVectorSimilarTo', sig: "(column: string, query: string|array, threshold?: float): Builder", doc: 'Filter rows by vector similarity. Uses pgvector cosine distance. Requires embedding column.' }, { name: 'orderByVectorSimilarityTo', sig: "(column: string, query: string|array): Builder", doc: 'Order results by vector similarity (closest first).' }, { name: 'withEmbedding', sig: "(column: string, text: string): Builder", doc: 'Eager-compute embedding for filtering without a separate AI call.' }, { name: 'nearestNeighbors', sig: "(column: string, embedding: array, k: int): Builder", doc: 'k-nearest-neighbour search using approximate index.' }, ]; const AI_PROVIDERS = [ 'openai', 'anthropic', 'deepseek', 'mistral', 'cohere', 'google', 'groq', 'together', 'openrouter', 'azure', 'ollama', 'huggingface', ]; // ─── AI Completion Provider ─────────────────────────────────────────────── export class Laravel13AiCompletionProvider implements vscode.CompletionItemProvider { constructor(_cache: CacheManager) {} provideCompletionItems( document: vscode.TextDocument, position: vscode.Position ): vscode.CompletionItem[] { const lineText = document.lineAt(position).text; const textBefore = lineText.substring(0, position.character); const items: vscode.CompletionItem[] = []; // ── 1. Ai:: facade calls ────────────────────────────────────────── if (/\bAi::\s*\w*$/.test(textBefore)) { for (const m of AI_FACADE_CALLS) { const label = m.name.split('::')[1]; const item = new vscode.CompletionItem(label, vscode.CompletionItemKind.Method); item.detail = m.sig; item.documentation = new vscode.MarkdownString( `**Laravel 13 AI SDK:** \`${m.name}${m.sig}\`\n\n${m.doc}` ); item.insertText = new vscode.SnippetString(`${label}($1)`); items.push(item); } return items; } // ── 2. ->text()-> chain ─────────────────────────────────────────── if (/\bAi::text\(\)\s*->\s*\w*$/.test(textBefore) || /\bAi::generate\b.*->\s*\w*$/.test(textBefore)) { for (const m of AI_TEXT_METHODS) { const item = new vscode.CompletionItem(m.name, vscode.CompletionItemKind.Method); item.detail = m.sig; item.documentation = new vscode.MarkdownString(`**AI Text:** \`${m.name}${m.sig}\`\n\n${m.doc}`); item.insertText = new vscode.SnippetString(`${m.name}($1)`); items.push(item); } return items; } // ── 3. Audio::of()-> or Ai::audio()-> ────────────────────────── if (/(?:Audio|Ai::audio)\s*(?:::of\([^)]*\))?\s*->\s*\w*$/.test(textBefore)) { for (const m of AI_AUDIO_METHODS) { const item = new vscode.CompletionItem(m.name, vscode.CompletionItemKind.Method); item.detail = m.sig; item.documentation = new vscode.MarkdownString(`**AI Audio:** \`${m.name}${m.sig}\`\n\n${m.doc}`); items.push(item); } return items; } // ── 4. Ai::image()-> ───────────────────────────────────────────── if (/Ai::image\s*\([^)]*\)\s*->\s*\w*$/.test(textBefore)) { for (const m of AI_IMAGE_METHODS) { const item = new vscode.CompletionItem(m.name, vscode.CompletionItemKind.Method); item.detail = m.sig; item.documentation = new vscode.MarkdownString(`**AI Image:** \`${m.name}${m.sig}\`\n\n${m.doc}`); items.push(item); } return items; } // ── 5. Vector query builder methods ────────────────────────────── if (/->(?:where|orderBy|with|nearest)\w*$/.test(textBefore)) { for (const m of AI_VECTOR_METHODS) { const item = new vscode.CompletionItem(m.name, vscode.CompletionItemKind.Method); item.detail = m.sig; item.documentation = new vscode.MarkdownString( `### 🔍 Vector Search (Laravel 13)\n\n\`${m.name}${m.sig}\`\n\n${m.doc}` ); item.sortText = `0_${m.name}`; // float to top items.push(item); } return items; } // ── 6. using('provider') ───────────────────────────────────────── if (/->using\s*\(\s*['"][^'"]*$/.test(textBefore)) { for (const p of AI_PROVIDERS) { const item = new vscode.CompletionItem(p, vscode.CompletionItemKind.Value); item.detail = `AI provider: ${p}`; items.push(item); } return items; } // ── 7. Agent::make() context ────────────────────────────────────── if (/\bAgent::make\s*\(\s*\)$/.test(textBefore) || /extends\s+Agent\b/.test(document.getText()) && /->\s*\w*$/.test(textBefore)) { const agentMethods = [ { name: 'prompt', sig: '(message: string): AgentResponse', doc: 'Send a message to this agent.' }, { name: 'withTool', sig: '(tool: Tool): static', doc: 'Register a single tool.' }, { name: 'withTools', sig: '(tools: array): static', doc: 'Register multiple tools at once.' }, { name: 'maxSteps', sig: '(steps: int): static', doc: 'Limit agentic reasoning steps.' }, { name: 'using', sig: '(provider: string): static', doc: 'Pin provider for this agent.' }, { name: 'withMemory', sig: '(memory: Memory): static', doc: 'Attach conversation memory.' }, { name: 'onStep', sig: '(callback: Closure): static', doc: 'Hook into each reasoning step.' }, { name: 'stream', sig: '(message: string): StreamResponse', doc: 'Stream the agent response.' }, { name: 'make', sig: '(): static', doc: 'Create a new agent instance.' }, ]; for (const m of agentMethods) { const item = new vscode.CompletionItem(m.name, vscode.CompletionItemKind.Method); item.detail = m.sig; item.documentation = new vscode.MarkdownString(`**Laravel 13 Agent:** \`${m.name}${m.sig}\`\n\n${m.doc}`); items.push(item); } return items; } return items; } } // ─── AI Hover Provider ──────────────────────────────────────────────────── export class Laravel13AiHoverProvider implements vscode.HoverProvider { provideHover( document: vscode.TextDocument, position: vscode.Position ): vscode.Hover | undefined { const wordRange = document.getWordRangeAtPosition(position, /\b\w+\b/); if (!wordRange) { return undefined; } const word = document.getText(wordRange); const lineText = document.lineAt(position).text; // Check for AI SDK context if (!lineText.includes('Ai::') && !lineText.includes('Agent') && !lineText.includes('Audio') && !lineText.includes('whereVectorSimilarTo')) { return undefined; } const allMethods = [ ...AI_TEXT_METHODS, ...AI_AUDIO_METHODS, ...AI_IMAGE_METHODS, ...AI_VECTOR_METHODS, ]; const found = allMethods.find((m) => m.name === word); if (!found) { return undefined; } const md = new vscode.MarkdownString(); md.isTrusted = true; md.appendMarkdown(`### 🤖 Laravel 13 AI SDK\n\n`); md.appendMarkdown(`\`${found.name}${found.sig}\`\n\n${found.doc}\n\n`); md.appendMarkdown(`*Requires:* \`laravel/ai\` — included in Laravel 13*`); return new vscode.Hover(md, wordRange); } } // ─── AI Agent Generator ─────────────────────────────────────────────────── export class AiAgentGenerator { constructor(private readonly workspaceRoot: string) {} async generate(): Promise<void> { const name = await vscode.window.showInputBox({ prompt: 'Agent class name (e.g. SalesCoach or SupportAgent)', placeHolder: 'SalesCoach', validateInput: (v) => v.trim() ? null : 'Name is required', }); if (!name) { return; } const type = await vscode.window.showQuickPick([ { label: 'Text Agent', value: 'text', description: 'Text generation with tools' }, { label: 'Search Agent', value: 'search', description: 'Semantic search + RAG agent' }, { label: 'Vision Agent', value: 'vision', description: 'Image analysis agent' }, { label: 'Audio Agent', value: 'audio', description: 'Speech + transcription agent' }, ], { placeHolder: 'Agent type' }); if (!type) { return; } const provider = await vscode.window.showQuickPick( AI_PROVIDERS.map((p) => ({ label: p, description: `Use ${p} as default provider` })), { placeHolder: 'Default AI provider (can be overridden per-request)' } ); const content = this.buildAgentStub(name, type.value, provider?.label ?? 'openai'); const filePath = path.join(this.workspaceRoot, 'app', 'Ai', 'Agents', `${name}.php`); const dir = path.dirname(filePath); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } const uri = vscode.Uri.file(filePath); const edit = new vscode.WorkspaceEdit(); edit.createFile(uri, { overwrite: false }); edit.insert(uri, new vscode.Position(0, 0), content); await vscode.workspace.applyEdit(edit); const doc = await vscode.workspace.openTextDocument(uri); await vscode.window.showTextDocument(doc); vscode.window.showInformationMessage(`✅ Created AI Agent: ${name}`); } private buildAgentStub(name: string, type: string, provider: string): string { const baseImport = type === 'search' ? `use Laravel\\Ai\\Agent;\nuse Laravel\\Ai\\Tools\\VectorSearchTool;` : `use Laravel\\Ai\\Agent;`; const tools = type === 'search' ? `\n protected array $tools = [\n VectorSearchTool::class,\n ];\n` : ''; const systemPrompt = { text: `You are a helpful assistant.`, search: `You are a semantic search assistant. Use the provided search tool to find relevant documents before answering.`, vision: `You are a vision assistant. Analyze the provided image and describe what you see.`, audio: `You are a voice assistant. Respond concisely and clearly.`, }[type] ?? 'You are a helpful assistant.'; return `<?php namespace App\\Ai\\Agents; ${baseImport} /** * ${name} — Laravel 13 AI Agent * * Usage: * $response = ${name}::make()->prompt('Your message here'); * echo (string) $response; */ class ${name} extends Agent { /** * The default AI provider for this agent. * * @var string */ protected string $provider = '${provider}'; /** * The system prompt that defines this agent's behavior. * * @var string */ protected string $systemPrompt = '${systemPrompt}'; /** * Maximum number of agentic reasoning steps. * * @var int */ protected int $maxSteps = 10; ${tools} /** * Called before each step. Return false to abort. */ protected function beforeStep(int $step, string $message): bool { return true; } /** * Called after the agent finishes. */ protected function afterComplete(string $response): string { return $response; } } `; } } // ─── AI Tool Generator ──────────────────────────────────────────────────── export class AiToolGenerator { constructor(private readonly workspaceRoot: string) {} async generate(): Promise<void> { const name = await vscode.window.showInputBox({ prompt: 'Tool class name (e.g. SearchProductsTool or GetWeatherTool)', placeHolder: 'SearchProductsTool', validateInput: (v) => v.trim() ? null : 'Name is required', }); if (!name) { return; } const description = await vscode.window.showInputBox({ prompt: 'Tool description (shown to the LLM)', placeHolder: 'Search for products matching a query', validateInput: (v) => v.trim() ? null : 'Description is required', }); if (!description) { return; } const content = `<?php namespace App\\Ai\\Tools; use Laravel\\Ai\\Tool; class ${name} extends Tool { /** * The name the LLM uses to call this tool. * * @var string */ public string $name = '${toSnakeCase(name.replace(/Tool$/, ''))}'; /** * Description shown to the LLM to decide when to call this tool. * * @var string */ public string $description = '${description}'; /** * JSON Schema defining the tool's parameters. * * @var array */ public array $parameters = [ 'type' => 'object', 'properties' => [ 'query' => [ 'type' => 'string', 'description' => 'The search query', ], ], 'required' => ['query'], ]; /** * Execute the tool. Called by the agent when the LLM invokes it. * * @param array \$args Validated arguments from the LLM * @return mixed Result passed back to the LLM */ public function handle(array \$args): mixed { \$query = \$args['query']; // TODO: implement tool logic here return []; } } `; const filePath = path.join(this.workspaceRoot, 'app', 'Ai', 'Tools', `${name}.php`); const dir = path.dirname(filePath); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } const uri = vscode.Uri.file(filePath); const edit = new vscode.WorkspaceEdit(); edit.createFile(uri, { overwrite: false }); edit.insert(uri, new vscode.Position(0, 0), content); await vscode.workspace.applyEdit(edit); const doc = await vscode.workspace.openTextDocument(uri); await vscode.window.showTextDocument(doc); vscode.window.showInformationMessage(`✅ Created AI Tool: ${name}`); } } // ─── JSON:API Resource Generator ───────────────────────────────────────── export class JsonApiResourceGenerator { constructor( private readonly workspaceRoot: string, private readonly cache: CacheManager ) {} async generate(): Promise<void> { const index = this.cache.getIndex(); const models = Array.from(index.models.values()); let modelName: string | undefined; if (models.length > 0) { const picked = await vscode.window.showQuickPick( models.map((m) => ({ label: m.className, description: m.namespace })), { placeHolder: 'Select model for JSON:API resource' } ); modelName = picked?.label; } if (!modelName) { modelName = await vscode.window.showInputBox({ prompt: 'Model class name (e.g. Post)', placeHolder: 'Post', validateInput: (v) => v.trim() ? null : 'Required', }); } if (!modelName) { return; } const model = models.find((m) => m.className === modelName); const modelNs = model?.namespace ?? 'App\\Models'; const attrs = model?.columns .filter((c) => !['id', 'created_at', 'updated_at', 'deleted_at'].includes(c.name) && model.fillable.includes(c.name)) .map((c) => ` '${c.name}' => \$this->${c.name},`) .join('\n') || " // add attributes here"; const rels = model?.relationships .map((r) => ` '${r.name}' => \$this->whenLoaded('${r.name}', fn () => ${r.relatedModel}Resource::make(\$this->${r.name})),`) .join('\n') || ''; const content = `<?php namespace App\\Http\\Resources; use ${modelNs}\\${modelName}; use Illuminate\\Http\\Resources\\JsonApi\\JsonApiResource; use Illuminate\\Http\\Request; /** * ${modelName} JSON:API Resource * * Compliant with the JSON:API specification (jsonapi.org). * Handles resource object serialization, relationship inclusion, * sparse fieldsets, links, and JSON:API-compliant response headers. * * Usage: * return ${modelName}Resource::make(\$model); * return ${modelName}Resource::collection(\$models)->withLinks([...]); */ class ${modelName}Resource extends JsonApiResource { /** * The resource type identifier (JSON:API "type" field). * * @var string */ protected string $type = '${toKebabPlural(modelName)}'; /** * Get the resource attributes. * * @return array<string, mixed> */ public function attributes(Request \$request): array { return [ ${attrs} ]; } /** * Get the resource relationships. * * @return array<string, mixed> */ public function relationships(Request \$request): array { return [ ${rels} ]; } /** * Get the resource links. * * @return array<string, string> */ public function links(Request \$request): array { return [ 'self' => route('${toKebabPlural(modelName)}.show', \$this->id), ]; } /** * Get the resource meta information. * * @return array<string, mixed> */ public function meta(Request \$request): array { return []; } } `; const filePath = path.join( this.workspaceRoot, 'app', 'Http', 'Resources', `${modelName}Resource.php` ); const uri = vscode.Uri.file(filePath); const edit = new vscode.WorkspaceEdit(); edit.createFile(uri, { overwrite: true }); edit.insert(uri, new vscode.Position(0, 0), content); await vscode.workspace.applyEdit(edit); const doc = await vscode.workspace.openTextDocument(uri); await vscode.window.showTextDocument(doc); vscode.window.showInformationMessage(`✅ Created JSON:API Resource: ${modelName}Resource`); } } // ─── Laravel 13 Cache::touch() + Queue::route() completions ────────────── export class Laravel13ApiProvider implements vscode.CompletionItemProvider { constructor(_cache: CacheManager) {} provideCompletionItems( document: vscode.TextDocument, position: vscode.Position ): vscode.CompletionItem[] { const lineText = document.lineAt(position).text; const textBefore = lineText.substring(0, position.character); const items: vscode.CompletionItem[] = []; // ── Cache:: new methods ─────────────────────────────────────────── if (/\bCache::\s*\w*$/.test(textBefore)) { const newCacheMethods = [ { name: 'touch', sig: "(key: string, seconds?: int): bool", doc: "**New in Laravel 13.** Extend a cached item's TTL without fetching or re-storing it. Returns false if key doesn't exist." }, { name: 'touchMany', sig: "(keys: array, seconds?: int): bool", doc: 'Extend TTL for multiple keys atomically.' }, { name: 'getOrPut', sig: "(key: string, value: mixed, ttl?: int): mixed", doc: 'Get a value or store and return a default.' }, ]; for (const m of newCacheMethods) { const item = new vscode.CompletionItem(m.name, vscode.CompletionItemKind.Method); item.detail = m.sig; item.documentation = new vscode.MarkdownString(m.doc); item.insertText = new vscode.SnippetString(`${m.name}($1)`); item.sortText = `0_${m.name}`; items.push(item); } } // ── Queue::route() ──────────────────────────────────────────────── if (/\bQueue::\s*\w*$/.test(textBefore)) { const newQueueMethods = [ { name: 'route', sig: "(jobClass: string, queue: string, connection?: string): void", doc: '**New in Laravel 13.** Define default queue/connection routing rules for a job class. Called in AppServiceProvider::boot().' }, { name: 'after', sig: "(callback: Closure): void", doc: 'Register a callback to run after a job is processed.' }, { name: 'before', sig: "(callback: Closure): void", doc: 'Register a callback to run before a job is processed.' }, { name: 'failing', sig: "(callback: Closure): void", doc: 'Register a callback for failed jobs.' }, { name: 'looping', sig: "(callback: Closure): void", doc: 'Register a callback that runs on each queue loop.' }, { name: 'createPayloadUsing', sig: "(callback: Closure): void", doc: 'Customize the queue payload for all jobs.' }, ]; for (const m of newQueueMethods) { const item = new vscode.CompletionItem(m.name, vscode.CompletionItemKind.Method); item.detail = m.sig; item.documentation = new vscode.MarkdownString(m.doc); item.insertText = new vscode.SnippetString(`${m.name}($1)`); items.push(item); } } // ── JsonApiResource chain methods ───────────────────────────────── if (/(?:JsonApiResource|Resource::(?:make|collection))\s*\([^)]*\)\s*->\s*\w*$/.test(textBefore) || /\$this->(?:whenLoaded|when|merge)\s*\([^)]*\)\s*->\s*\w*$/.test(textBefore)) { const jsonApiMethods = [ { name: 'withLinks', sig: '(links: array): static', doc: 'Append top-level JSON:API links.' }, { name: 'withMeta', sig: '(meta: array): static', doc: 'Append top-level JSON:API meta.' }, { name: 'withIncluded', sig: '(resources: array): static', doc: 'Include compound documents.' }, { name: 'sparseFieldset', sig: '(): static', doc: 'Enable sparse fieldsets from ?fields[type]= query param.' }, { name: 'paginationLinks', sig: '(paginator: Paginator): static', doc: 'Add JSON:API pagination links.' }, ]; for (const m of jsonApiMethods) { const item = new vscode.CompletionItem(m.name, vscode.CompletionItemKind.Method); item.detail = m.sig; item.documentation = new vscode.MarkdownString(`**JSON:API (Laravel 13):** ${m.doc}`); items.push(item); } } return items; } } // ─── Helpers ────────────────────────────────────────────────────────────── function toSnakeCase(str: string): string { return str.replace(/([A-Z])/g, '_$1').toLowerCase().replace(/^_/, ''); } function toKebabPlural(str: string): string { return str .replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '') .replace(/y$/, 'ies').replace(/([^s])$/, '$1s'); } |