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 | // src/providers/PackageProviders.ts // Third-party package intelligence for Laravel Maestro import * as vscode from 'vscode'; import type { CacheManager } from '../cache/CacheManager'; // ─── spatie/laravel-query-builder ───────────────────────────────────────── export class SpatieQueryBuilderProvider implements vscode.CompletionItemProvider { constructor(private readonly cache: CacheManager) {} provideCompletionItems( document: vscode.TextDocument, position: vscode.Position ): vscode.CompletionItem[] { const lineText = document.lineAt(position).text; const textBefore = lineText.substring(0, position.character); // QueryBuilder::for(Model::class)->allowedFilters([|]) const isQueryBuilder = /QueryBuilder::for\s*\(/.test(textBefore) || /->allowedFilters\s*\(\s*\[?[^\]]*$/.test(textBefore) || /->allowedSorts\s*\(\s*\[?[^\]]*$/.test(textBefore) || /->allowedIncludes\s*\(\s*\[?[^\]]*$/.test(textBefore) || /->allowedFields\s*\(\s*\[?[^\]]*$/.test(textBefore); if (!isQueryBuilder) { return []; } const items: vscode.CompletionItem[] = []; const index = this.cache.getIndex(); // Determine which model is being queried const modelMatch = /QueryBuilder::for\s*\(\s*(\w+)::class/.exec( document.getText().substring(0, document.offsetAt(position)) ); const model = modelMatch ? Array.from(index.models.values()).find((m) => m.className === modelMatch[1]) : undefined; if (model) { // Column names for filters/sorts/fields for (const col of model.columns) { const item = new vscode.CompletionItem(`'${col.name}'`, vscode.CompletionItemKind.Field); item.detail = `${col.type} — ${model.tableName}.${col.name}`; items.push(item); } // Relationship names for includes for (const rel of model.relationships) { const item = new vscode.CompletionItem(`'${rel.name}'`, vscode.CompletionItemKind.Reference); item.detail = `${rel.type}(${rel.relatedModel}) — relationship`; items.push(item); } } // AllowedFilter static factory methods const filterMethods = [ { name: 'AllowedFilter::exact', doc: 'Exact match filter' }, { name: 'AllowedFilter::partial', doc: 'LIKE %value% filter' }, { name: 'AllowedFilter::beginsWithStrict', doc: 'Starts with filter' }, { name: 'AllowedFilter::scope', doc: 'Filter using a scope' }, { name: 'AllowedFilter::trashed', doc: 'Filter soft-deleted models' }, { name: 'AllowedFilter::callback', doc: 'Custom filter callback' }, { name: 'AllowedSort::field', doc: 'Sort by field' }, { name: 'AllowedSort::custom', doc: 'Custom sort' }, ]; for (const fm of filterMethods) { const item = new vscode.CompletionItem(fm.name, vscode.CompletionItemKind.Function); item.detail = fm.doc; item.insertText = new vscode.SnippetString(`${fm.name}('$1')`); items.push(item); } return items; } } // ─── spatie/laravel-permission ──────────────────────────────────────────── export class SpatiePermissionProvider implements vscode.CompletionItemProvider { // Well-known permission method triggers private static readonly TRIGGERS = [ 'can', 'cannot', 'hasPermissionTo', 'hasRole', 'givePermissionTo', 'assignRole', 'revokePermissionTo', 'removeRole', 'hasAnyRole', 'hasAllRoles', 'hasAnyPermission', 'hasAllPermissions', 'checkPermissionTo', ]; constructor(private readonly 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 isPermissionCall = SpatiePermissionProvider.TRIGGERS.some( (t) => new RegExp(`\\b${t}\\s*\\(\\s*['"][^'"]*$`).test(textBefore) ); if (!isPermissionCall) { return []; } const index = this.cache.getIndex(); const items: vscode.CompletionItem[] = []; // Extract permission/role names from the index (config or extracted values) for (const [key, cfg] of index.configs) { if (key.includes('permission') || key.includes('role')) { const item = new vscode.CompletionItem(String(cfg.value), vscode.CompletionItemKind.Value); item.detail = `config: ${key}`; items.push(item); } } // Common pattern: permissions defined as constants in app/Enums/Permission.php for (const [, cls] of index.classes) { if (cls.name.toLowerCase().includes('permission') || cls.name.toLowerCase().includes('role')) { for (const c of cls.constants) { if (c.value) { const item = new vscode.CompletionItem(c.value.replace(/['"]/g, ''), vscode.CompletionItemKind.EnumMember); item.detail = `${cls.name}::${c.name}`; items.push(item); } } } } return items; } } // ─── nWidart/laravel-modules ────────────────────────────────────────────── export class LaravelModulesProvider implements vscode.CompletionItemProvider { constructor(private readonly cache: CacheManager) {} provideCompletionItems( document: vscode.TextDocument, position: vscode.Position ): vscode.CompletionItem[] { const lineText = document.lineAt(position).text; const textBefore = lineText.substring(0, position.character); // Module::find(), Module::all(), module_path(), config('modules.paths...') const isModuleContext = /\bModule::\w*\(\s*['"][^'"]*$/.test(textBefore) || /\bmodule_path\s*\(\s*['"][^'"]*$/.test(textBefore); if (!isModuleContext) { return []; } const index = this.cache.getIndex(); const items: vscode.CompletionItem[] = []; // Module names from the index for (const moduleName of index.nwidartModules) { const item = new vscode.CompletionItem(moduleName, vscode.CompletionItemKind.Module); item.detail = 'Laravel Module'; items.push(item); } // Fallback: suggest the Modules:: methods const moduleMethods = [ 'all', 'allEnabled', 'allDisabled', 'find', 'findByAlias', 'enabled', 'disabled', 'count', 'getOrdered', 'boot', 'register', 'enable', 'disable', 'delete', 'has', ]; for (const method of moduleMethods) { const item = new vscode.CompletionItem(`Modules::${method}`, vscode.CompletionItemKind.Method); item.detail = 'nWidart Modules facade'; items.push(item); } return items; } } // ─── Laravel Pennant (Feature Flags) ────────────────────────────────────── export class PennantProvider implements vscode.CompletionItemProvider { constructor(private readonly cache: CacheManager) {} provideCompletionItems( document: vscode.TextDocument, position: vscode.Position ): vscode.CompletionItem[] { const lineText = document.lineAt(position).text; const textBefore = lineText.substring(0, position.character); // Feature::active('|'), Feature::when('|'), @feature('|'), Feature::for()->active('|') const isPennant = /\bFeature::\w+\s*\(\s*['"][^'"]*$/.test(textBefore) || /@feature\s*\(\s*['"][^'"]*$/.test(textBefore); if (!isPennant) { return []; } const index = this.cache.getIndex(); const items: vscode.CompletionItem[] = []; // Feature flags from index for (const flag of index.pennantFeatures) { const item = new vscode.CompletionItem(flag.name, vscode.CompletionItemKind.Value); item.detail = flag.isClassBased ? `Class-based feature: ${flag.className ?? ''}` : 'Inline feature'; item.documentation = new vscode.MarkdownString( `**Laravel Pennant Feature**\n\nDefined in: \`${flag.filePath ?? 'unknown'}\`` ); items.push(item); } // If no features indexed yet, offer Feature class methods if (items.length === 0) { const methods = [ { name: 'Feature::active', sig: "(feature: string): bool" }, { name: 'Feature::inactive', sig: "(feature: string): bool" }, { name: 'Feature::when', sig: "(feature: string, active: Closure, inactive?: Closure): mixed" }, { name: 'Feature::unless', sig: "(feature: string, inactive: Closure, active?: Closure): mixed" }, { name: 'Feature::activate', sig: "(feature: string|array): void" }, { name: 'Feature::deactivate', sig: "(feature: string|array): void" }, { name: 'Feature::purge', sig: "(feature?: string): void" }, { name: 'Feature::for', sig: "(user: mixed): PendingScopedFeatureInteraction" }, { name: 'Feature::define', sig: "(feature: string, resolver: Closure): void" }, ]; for (const m of methods) { const item = new vscode.CompletionItem(m.name, vscode.CompletionItemKind.Method); item.detail = m.sig; items.push(item); } } return items; } } // ─── Laravel Nova ───────────────────────────────────────────────────────── export class NovaProvider 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); // Inside a Nova resource fields(), actions(), filters(), lenses() etc. if (!document.fileName.includes('Nova') && !document.fileName.includes('/nova/')) { return []; } const items: vscode.CompletionItem[] = []; // Nova field types const novaFields = [ 'ID', 'Text', 'Textarea', 'Number', 'Date', 'DateTime', 'Boolean', 'BooleanGroup', 'Select', 'MultiSelect', 'Currency', 'Email', 'File', 'Image', 'Gravatar', 'Heading', 'Hidden', 'KeyValue', 'Markdown', 'Password', 'Place', 'Slug', 'Sparkline', 'Stack', 'Status', 'Tag', 'Trix', 'URL', 'JSON', 'Color', 'Country', 'Phone', 'BelongsTo', 'BelongsToMany', 'HasMany', 'HasOne', 'HasOneThrough', 'HasManyThrough', 'MorphedByMany', 'MorphMany', 'MorphOne', 'MorphTo', 'MorphToMany', ]; for (const field of novaFields) { const item = new vscode.CompletionItem(field, vscode.CompletionItemKind.Class); item.detail = `Nova Field`; item.insertText = new vscode.SnippetString(`${field}::make('$1', '$2')`); item.documentation = new vscode.MarkdownString(`**Laravel Nova Field:** \`${field}\``); items.push(item); } // Nova field modifier methods if (/->/.test(textBefore)) { const modifiers = [ { name: 'sortable', sig: '(): Field' }, { name: 'nullable', sig: '(nullable?: bool): Field' }, { name: 'required', sig: '(required?: bool): Field' }, { name: 'readonly', sig: '(readonly?: bool): Field' }, { name: 'hideFromIndex', sig: '(): Field' }, { name: 'hideFromDetail', sig: '(): Field' }, { name: 'hideWhenCreating', sig: '(): Field' }, { name: 'hideWhenUpdating', sig: '(): Field' }, { name: 'onlyOnIndex', sig: '(): Field' }, { name: 'onlyOnDetail', sig: '(): Field' }, { name: 'onlyOnForms', sig: '(): Field' }, { name: 'exceptOnForms', sig: '(): Field' }, { name: 'rules', sig: '(rules: string|array): Field' }, { name: 'creationRules', sig: '(rules: string|array): Field' }, { name: 'updateRules', sig: '(rules: string|array): Field' }, { name: 'help', sig: '(text: string): Field' }, { name: 'placeholder', sig: '(text: string): Field' }, { name: 'default', sig: '(value: mixed): Field' }, { name: 'displayUsing', sig: '(callback: Closure): Field' }, { name: 'resolveUsing', sig: '(callback: Closure): Field' }, { name: 'fillUsing', sig: '(callback: Closure): Field' }, { name: 'withMeta', sig: '(meta: array): Field' }, { name: 'showOnPreview', sig: '(): Field' }, { name: 'textAlign', sig: "(alignment: 'left'|'center'|'right'): Field" }, { name: 'dependsOn', sig: '(fields: string|array, callback: Closure): Field' }, ]; for (const mod of modifiers) { const item = new vscode.CompletionItem(mod.name, vscode.CompletionItemKind.Method); item.detail = mod.sig; item.sortText = `b_${mod.name}`; items.push(item); } } return items; } } // ─── Laravel Dusk ───────────────────────────────────────────────────────── export class DuskProvider implements vscode.CompletionItemProvider { constructor(_cache: CacheManager) {} provideCompletionItems( document: vscode.TextDocument, position: vscode.Position ): vscode.CompletionItem[] { // Only in test files or Dusk page objects const isTest = document.fileName.includes('/tests/Browser/') || document.fileName.includes('\\tests\\Browser\\'); if (!isTest) { return []; } const lineText = document.lineAt(position).text; const textBefore = lineText.substring(0, position.character); if (!/->\s*\w*$/.test(textBefore)) { return []; } const duskMethods = [ // Navigation { name: 'visit', sig: '(url: string): Browser' }, { name: 'back', sig: '(): Browser' }, { name: 'forward', sig: '(): Browser' }, { name: 'refresh', sig: '(): Browser' }, { name: 'on', sig: '(page: Page): Browser' }, // Interaction { name: 'click', sig: '(selector: string): Browser' }, { name: 'clickAtXPath', sig: '(xpath: string): Browser' }, { name: 'clickAtPoint', sig: '(x: int, y: int): Browser' }, { name: 'rightClick', sig: '(selector: string): Browser' }, { name: 'doubleClick', sig: '(selector: string): Browser' }, { name: 'type', sig: '(field: string, value: string): Browser' }, { name: 'typeSlowly', sig: '(field: string, value: string, delay: int): Browser' }, { name: 'clear', sig: '(field: string): Browser' }, { name: 'append', sig: '(field: string, value: string): Browser' }, { name: 'keys', sig: '(selector: string, ...keys: string): Browser' }, { name: 'select', sig: '(field: string, value: string): Browser' }, { name: 'radio', sig: '(field: string, value: string): Browser' }, { name: 'check', sig: '(field: string): Browser' }, { name: 'uncheck', sig: '(field: string): Browser' }, { name: 'attach', sig: '(field: string, path: string): Browser' }, { name: 'press', sig: '(button: string): Browser' }, { name: 'pressAndWaitFor', sig: '(button: string, seconds: int): Browser' }, { name: 'drag', sig: '(from: string, to: string): Browser' }, { name: 'mouseover', sig: '(selector: string): Browser' }, { name: 'scrollIntoView', sig: '(selector: string): Browser' }, // Assertions { name: 'assertTitle', sig: '(title: string): Browser' }, { name: 'assertTitleContains', sig: '(title: string): Browser' }, { name: 'assertUrlIs', sig: '(url: string): Browser' }, { name: 'assertPathIs', sig: '(path: string): Browser' }, { name: 'assertRouteIs', sig: '(route: string, parameters?: array): Browser' }, { name: 'assertSee', sig: '(text: string): Browser' }, { name: 'assertDontSee', sig: '(text: string): Browser' }, { name: 'assertSeeIn', sig: '(selector: string, text: string): Browser' }, { name: 'assertSeeAnythingIn', sig: '(selector: string): Browser' }, { name: 'assertPresent', sig: '(selector: string): Browser' }, { name: 'assertNotPresent', sig: '(selector: string): Browser' }, { name: 'assertVisible', sig: '(selector: string): Browser' }, { name: 'assertMissing', sig: '(selector: string): Browser' }, { name: 'assertChecked', sig: '(field: string): Browser' }, { name: 'assertNotChecked', sig: '(field: string): Browser' }, { name: 'assertInputValue', sig: '(field: string, value: string): Browser' }, { name: 'assertSelected', sig: '(field: string, value: string): Browser' }, { name: 'assertAuthenticated', sig: '(guard?: string): Browser' }, { name: 'assertGuest', sig: '(guard?: string): Browser' }, { name: 'assertHasElement', sig: '(component: Component): Browser' }, // Waits { name: 'waitFor', sig: '(selector: string, seconds?: int): Browser' }, { name: 'waitForText', sig: '(text: string, seconds?: int): Browser' }, { name: 'waitForTextIn', sig: '(selector: string, text: string): Browser' }, { name: 'waitForLink', sig: '(link: string, seconds?: int): Browser' }, { name: 'waitForLocation', sig: '(path: string, seconds?: int): Browser' }, { name: 'waitForRoute', sig: '(route: string, parameters?: array): Browser' }, { name: 'waitUntilMissing', sig: '(selector: string, seconds?: int): Browser' }, { name: 'pause', sig: '(milliseconds: int): Browser' }, { name: 'whenAvailable', sig: '(selector: string, callback: Closure): Browser' }, // Authentication { name: 'loginAs', sig: '(user: Authenticatable|int, guard?: string): Browser' }, { name: 'logout', sig: '(guard?: string): Browser' }, // Screenshots { name: 'screenshot', sig: '(name: string): Browser' }, { name: 'fit', sig: '(selector: string): Browser' }, { name: 'storeSource', sig: '(name: string): Browser' }, ]; return duskMethods.map((m) => { const item = new vscode.CompletionItem(m.name, vscode.CompletionItemKind.Method); item.detail = m.sig; item.documentation = new vscode.MarkdownString(`**Laravel Dusk:** \`${m.name}${m.sig}\``); return item; }); } } // ─── Log channel completion ─────────────────────────────────────────────── export class LogChannelProvider implements vscode.CompletionItemProvider { constructor(private readonly cache: CacheManager) {} provideCompletionItems( document: vscode.TextDocument, position: vscode.Position ): vscode.CompletionItem[] { const lineText = document.lineAt(position).text; const textBefore = lineText.substring(0, position.character); if (!/(?:Log::channel|Log::stack)\s*\(\s*['"][^'"]*$/.test(textBefore)) { return []; } const index = this.cache.getIndex(); const items: vscode.CompletionItem[] = []; // Channels from config/logging.php for (const [key, cfg] of index.configs) { if (key.startsWith('logging.channels.') && key.split('.').length === 3) { const channelName = key.split('.')[2]; const item = new vscode.CompletionItem(channelName, vscode.CompletionItemKind.Value); item.detail = `Log channel — ${String(cfg.value)}`; items.push(item); } } // Built-in channels for (const ch of ['stack', 'single', 'daily', 'slack', 'papertrail', 'stderr', 'syslog', 'errorlog', 'null', 'emergency']) { if (!items.find((i) => i.label === ch)) { const item = new vscode.CompletionItem(ch, vscode.CompletionItemKind.Value); item.detail = 'Built-in log channel'; items.push(item); } } return items; } } // ─── Timezone completion ────────────────────────────────────────────────── const TIMEZONES = [ 'UTC', 'America/New_York', 'America/Chicago', 'America/Denver', 'America/Los_Angeles', 'America/Phoenix', 'America/Anchorage', 'America/Honolulu', 'America/Toronto', 'America/Vancouver', 'America/Sao_Paulo', 'America/Argentina/Buenos_Aires', 'America/Mexico_City', 'America/Bogota', 'America/Lima', 'Europe/London', 'Europe/Paris', 'Europe/Berlin', 'Europe/Rome', 'Europe/Madrid', 'Europe/Amsterdam', 'Europe/Brussels', 'Europe/Vienna', 'Europe/Warsaw', 'Europe/Prague', 'Europe/Budapest', 'Europe/Bucharest', 'Europe/Athens', 'Europe/Helsinki', 'Europe/Stockholm', 'Europe/Oslo', 'Europe/Copenhagen', 'Europe/Zurich', 'Europe/Lisbon', 'Europe/Dublin', 'Europe/Moscow', 'Asia/Tokyo', 'Asia/Shanghai', 'Asia/Hong_Kong', 'Asia/Singapore', 'Asia/Seoul', 'Asia/Kolkata', 'Asia/Dubai', 'Asia/Karachi', 'Asia/Dhaka', 'Asia/Jakarta', 'Asia/Bangkok', 'Asia/Manila', 'Asia/Taipei', 'Asia/Almaty', 'Asia/Tashkent', 'Asia/Yekaterinburg', 'Asia/Novosibirsk', 'Australia/Sydney', 'Australia/Melbourne', 'Australia/Brisbane', 'Australia/Adelaide', 'Australia/Perth', 'Pacific/Auckland', 'Pacific/Auckland', 'Pacific/Fiji', 'Pacific/Honolulu', 'Africa/Cairo', 'Africa/Johannesburg', 'Africa/Lagos', 'Africa/Nairobi', ]; export class TimezoneProvider implements vscode.CompletionItemProvider { provideCompletionItems( document: vscode.TextDocument, position: vscode.Position ): vscode.CompletionItem[] { const lineText = document.lineAt(position).text; const textBefore = lineText.substring(0, position.character); if (!/(?:timezone|tz)\s*['"\s]*[=:>]\s*['"][^'"]*$/.test(textBefore) && !/config\s*\(\s*['"]app\.timezone['"]/i.test(textBefore) && !/->timezone\s*\(\s*['"][^'"]*$/.test(textBefore)) { return []; } return TIMEZONES.map((tz) => { const item = new vscode.CompletionItem(tz, vscode.CompletionItemKind.Value); item.detail = 'Timezone'; return item; }); } } |