231 lines
5.3 KiB
Markdown
231 lines
5.3 KiB
Markdown
# AI Assistance Features Guide
|
|
|
|
This guide details how AI assistance works in our Laravel platform development workflow, focusing on practical examples and specific use cases.
|
|
|
|
## 1. Code Analysis & Generation
|
|
|
|
### Laravel API Analysis
|
|
```dart
|
|
// Example: Implementing Container's bind method
|
|
// Command: /ai analyze-laravel Container::bind
|
|
|
|
AI will analyze:
|
|
1. Laravel's implementation:
|
|
```php
|
|
public function bind($abstract, $concrete = null, $shared = false)
|
|
{
|
|
$this->dropStaleInstances($abstract);
|
|
if (is_null($concrete)) {
|
|
$concrete = $abstract;
|
|
}
|
|
// ...
|
|
}
|
|
```
|
|
|
|
2. Generate Dart equivalent:
|
|
```dart
|
|
// GENERATED BY AI
|
|
/// Matches Laravel's Container::bind implementation
|
|
/// @see https://laravel.com/docs/container#binding
|
|
void bind<T>(T Function(Container) concrete, {bool shared = false}) {
|
|
dropStaleInstances(T);
|
|
// ...
|
|
}
|
|
```
|
|
|
|
3. Provide compatibility notes:
|
|
```
|
|
API Compatibility Notes:
|
|
- Laravel uses dynamic typing, we use generics
|
|
- Laravel's null concrete defaults to abstract
|
|
- Maintain same binding behavior
|
|
```
|
|
|
|
### Implementation Suggestions
|
|
|
|
```dart
|
|
// Command: /ai suggest-implementation Container::bind
|
|
|
|
AI provides:
|
|
1. Implementation pattern:
|
|
```dart
|
|
void bind<T>(T Function(Container) concrete, {bool shared = false}) {
|
|
// AI suggests pattern based on Laravel's behavior
|
|
_dropStaleInstances(typeOf<T>());
|
|
|
|
final binding = shared
|
|
? (c) => _shared(concrete)
|
|
: concrete;
|
|
|
|
_bindings[typeOf<T>()] = binding;
|
|
}
|
|
```
|
|
|
|
2. Edge cases to handle:
|
|
```dart
|
|
// AI identifies critical scenarios:
|
|
- Rebinding existing types
|
|
- Handling shared vs non-shared
|
|
- Circular dependencies
|
|
```
|
|
|
|
## 2. Test Generation
|
|
|
|
### Laravel Test Analysis
|
|
```dart
|
|
// Command: /ai generate-tests Container::bind
|
|
|
|
AI analyzes Laravel's tests:
|
|
```php
|
|
public function testBindingResolution()
|
|
{
|
|
$container = new Container;
|
|
$container->bind('name', function () { return 'Taylor'; });
|
|
$this->assertEquals('Taylor', $container->make('name'));
|
|
}
|
|
```
|
|
|
|
Generates Dart tests:
|
|
```dart
|
|
@Test('matches Laravel binding resolution')
|
|
void testBindingResolution() {
|
|
final container = Container();
|
|
container.bind<String>((c) => 'Taylor');
|
|
expect(container.make<String>(), equals('Taylor'));
|
|
}
|
|
```
|
|
|
|
### Coverage Analysis
|
|
```dart
|
|
// Command: /ai analyze-test-coverage Container
|
|
|
|
AI provides:
|
|
1. Coverage report comparing Laravel & Dart tests
|
|
2. Missing test scenarios
|
|
3. Additional Dart-specific tests needed
|
|
```
|
|
|
|
## 3. Real-Time Development Assistance
|
|
|
|
### API Compatibility Checking
|
|
```dart
|
|
// While coding, AI actively checks:
|
|
class Container {
|
|
// AI Warning: Laravel's bind allows string abstracts
|
|
void bind<T>(T Function(Container) concrete) { // <-- Compatibility issue
|
|
|
|
}
|
|
}
|
|
|
|
// AI Suggestion:
|
|
Consider supporting both generic and string-based binding:
|
|
```dart
|
|
void bind<T>(T Function(Container) concrete) { ... }
|
|
void bindType(String abstract, Function concrete) { ... }
|
|
```
|
|
|
|
### Pattern Recognition
|
|
```dart
|
|
// AI recognizes Laravel patterns and suggests Dart equivalents
|
|
// Laravel:
|
|
$container->singleton('api', function () { ... });
|
|
|
|
// AI suggests:
|
|
1. Direct equivalent:
|
|
```dart
|
|
container.singleton<ApiService>((c) => ApiService());
|
|
```
|
|
|
|
2. Attribute-based (more Dart-like):
|
|
```dart
|
|
@Singleton()
|
|
class ApiService { ... }
|
|
```
|
|
|
|
## 4. Documentation Generation
|
|
|
|
### API Documentation
|
|
```dart
|
|
// Command: /ai generate-docs Container::bind
|
|
|
|
AI generates:
|
|
```dart
|
|
/// Registers a binding with the container.
|
|
///
|
|
/// Equivalent to Laravel's Container::bind method.
|
|
/// ```php
|
|
/// $container->bind('api', function () { return new ApiService; });
|
|
/// ```
|
|
///
|
|
/// Dart usage:
|
|
/// ```dart
|
|
/// container.bind<ApiService>((c) => ApiService());
|
|
/// ```
|
|
void bind<T>(T Function(Container) concrete, {bool shared = false});
|
|
```
|
|
|
|
### Migration Guides
|
|
```dart
|
|
// Command: /ai generate-migration-guide Container
|
|
|
|
AI generates guides showing:
|
|
1. Laravel to Dart mappings
|
|
2. Common patterns
|
|
3. Best practices
|
|
```
|
|
|
|
## 5. Interactive Development
|
|
|
|
### AI Chat Commands
|
|
```bash
|
|
/ai explain Laravel's Container lifecycle
|
|
/ai compare Laravel vs Dart Container
|
|
/ai suggest refactoring for Container::bind
|
|
/ai review current implementation
|
|
```
|
|
|
|
### Context-Aware Suggestions
|
|
```dart
|
|
// AI maintains context across files
|
|
// When implementing ServiceProvider:
|
|
class ServiceProvider {
|
|
// AI suggests methods based on Laravel's ServiceProvider
|
|
void register() { ... } // <- AI: Required by Laravel
|
|
void boot() { ... } // <- AI: Optional but common
|
|
}
|
|
```
|
|
|
|
## Getting Started
|
|
|
|
1. Install required VS Code extensions:
|
|
- GitHub Copilot
|
|
- Platform AI Assistant
|
|
|
|
2. Configure AI settings:
|
|
```json
|
|
{
|
|
"platform.ai.laravel.version": "10.x",
|
|
"platform.ai.analysis.autoCheck": true,
|
|
"platform.ai.suggestions.enabled": true
|
|
}
|
|
```
|
|
|
|
3. Start using AI commands:
|
|
- Type `/ai` in any Dart file to see available commands
|
|
- Use AI suggestions for Laravel compatibility
|
|
- Let AI help generate tests and documentation
|
|
|
|
## Best Practices
|
|
|
|
1. Always verify AI suggestions against Laravel's documentation
|
|
2. Use AI for initial implementation, then review and refine
|
|
3. Let AI help maintain API compatibility
|
|
4. Use AI-generated tests as a starting point, then add edge cases
|
|
5. Review AI-generated documentation for accuracy
|
|
|
|
## Support
|
|
|
|
For issues or questions about AI assistance:
|
|
1. Check the AI documentation
|
|
2. Use `/ai help` command
|
|
3. Report issues in the platform repository
|