Skip to content

Commit e0f7ea9

Browse files
committed
feat: enhance copilot instructions with performance guidelines and best practices
1 parent 7c4a301 commit e0f7ea9

File tree

1 file changed

+100
-52
lines changed

1 file changed

+100
-52
lines changed

.github/copilot-instructions.md

Lines changed: 100 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Copilot Instructions for Magento Log Viewer Extension
22

3+
## Core Principles
4+
5+
**Maintainability is the highest priority.** Always prefer clean, well-structured code over quick solutions.
6+
7+
**Performance is a feature** - treat it as such in every implementation decision. Every change must consider impact on user experience.
8+
39
## Architecture Overview
410

511
This is a VS Code extension that provides intelligent viewing and management of Magento log files. The extension follows a modular architecture with clear separation of concerns:
@@ -24,14 +30,37 @@ Advanced log entry organization with intelligent grouping:
2430
- **Theme detection**: Identifies "Broken reference" patterns and similar theme-related issues
2531
- **Group management**: Automatic expansion/collapse of grouped entries (see `themeGrouping.test.ts`)
2632

33+
## Critical Performance Guidelines
34+
35+
**Always prioritize end-user performance:**
36+
37+
- **Startup Performance**: Never block VS Code startup - defer heavy operations until needed
38+
- **Memory Efficiency**: Monitor memory usage, implement proper cleanup, avoid memory leaks
39+
- **UI Responsiveness**: Use async/await patterns, throttle UI updates, prevent blocking operations
40+
- **File I/O Optimization**: Cache file reads, use streaming for large files, batch file operations
41+
- **Background Processing**: Move intensive work to background threads when possible
42+
43+
## Code Organization & Maintainability Best Practices
44+
45+
- **Split large functions** - Break complex logic into smaller, testable functions (max 20-30 lines)
46+
- **Create separate files** - When modules exceed 400-500 lines, split into focused files (e.g., `cacheManager.ts`, `cleanupService.ts`)
47+
- **Single responsibility** - Each function/class should have one clear purpose
48+
- **Clear naming** - Use descriptive names that explain intent without comments
49+
- **Testable units** - Write code that can be easily unit tested in isolation
50+
- **Consistent patterns** - Follow established patterns in the codebase
51+
- **Type safety** - Use TypeScript strictly, avoid `any` types
52+
- **Immutable data** - Prefer immutable operations where possible
53+
54+
**Better to have more files with clear responsibilities than fewer files with mixed concerns.**
55+
2756
## Key Architectural Patterns
2857

2958
### Workspace-Scoped Configuration
3059
The extension uses workspace-scoped settings via `vscode.workspace.getConfiguration('magentoLogViewer', workspaceUri)`. All configuration is stored per-workspace, allowing different Magento projects to have independent settings.
3160

3261
### Asynchronous Initialization
3362
```typescript
34-
// Pattern: Delay heavy operations to let VS Code indexing settle
63+
// Best Practice: Delay heavy operations to let VS Code indexing settle
3564
await new Promise(resolve => setTimeout(resolve, 500));
3665
```
3766

@@ -52,31 +81,12 @@ Commands are conditionally shown using VS Code's `when` clauses:
5281
- `magentoLogViewer.autoCleanupEnabled` - Toggles cleanup UI commands
5382
- `magentoLogViewer.periodicCleanupEnabled` - Controls periodic cleanup status
5483

55-
## Critical Development Workflows
56-
57-
### Build & Development
58-
```bash
59-
npm run compile # Webpack build for development
60-
npm run watch # Watch mode during development
61-
npm run package # Production build for publishing
62-
npm run test # Run extension tests
63-
```
64-
65-
### Testing Strategy
66-
Tests are located in `src/test/` with focused test files:
67-
- `extension.test.ts` - Basic extension lifecycle
68-
- `caching.test.ts` - Cache system validation
69-
- `search.test.ts` - Search functionality
70-
- `autoCleanup.test.ts` - Time duration parsing and cleanup logic
71-
- `themeGrouping.test.ts` - Log message grouping and theme detection
72-
- `cacheConfiguration.test.ts`, `logReader.test.ts`, `reportReader.test.ts` - Component-specific tests
73-
- Run tests with `npm run test` or F5 debug launch
74-
75-
### Extension Configuration Flow
76-
1. Extension activates on `onStartupFinished`
77-
2. Checks `isMagentoProject` setting ("Please select" → prompt user)
78-
3. Validates `magentoRoot` path → auto-opens folder picker if invalid
79-
4. Creates providers and activates file system watchers on `var/log` and `var/report`
84+
### Memory Management Best Practices
85+
- **Dispose pattern**: All providers implement `dispose()` with cleanup of disposables array
86+
- **Resource cleanup**: Cache optimization via `optimizeCacheSize()` runs automatically
87+
- **File watcher disposal**: Properly disposed in `deactivate()` function
88+
- **Event listener cleanup**: Always remove listeners in dispose methods
89+
- **Timer cleanup**: Clear intervals/timeouts in cleanup functions
8090

8191
## Project-Specific Conventions
8292

@@ -85,35 +95,17 @@ Tests are located in `src/test/` with focused test files:
8595
- **Report files**: `{magentoRoot}/var/report/` (recursive directory scanning)
8696
- **Icons**: Color-coded by log level (ERROR=red, WARN=orange, DEBUG=yellow, INFO=blue)
8797

88-
### TreeItem Structure
89-
```typescript
90-
// Pattern: LogItem extends vscode.TreeItem with command integration
91-
new LogItem(label, collapsibleState, {
92-
command: 'magento-log-viewer.openFile',
93-
arguments: [filePath, lineNumber]
94-
})
95-
```
96-
9798
### Search Implementation
9899
- Real-time filtering via `quickPick.onDidChangeValue`
99100
- Supports regex patterns when `searchUseRegex` is enabled
100101
- Case sensitivity controlled by `searchCaseSensitive` setting
101102
- Search state managed through context variables for UI updates
102103

103-
### Error Handling Pattern
104-
```typescript
105-
// Pattern: User-friendly error messages with actionable buttons
106-
vscode.window.showErrorMessage('Error message', 'Action Button').then(selection => {
107-
if (selection === 'Action Button') {
108-
// Provide immediate solution
109-
}
110-
});
111-
```
112-
113-
### Memory Management
114-
- Dispose pattern: All providers implement `dispose()` with cleanup of disposables array
115-
- Cache optimization: `optimizeCacheSize()` runs automatically to prevent memory leaks
116-
- File watchers: Properly disposed in `deactivate()` function
104+
### Extension Configuration Flow
105+
1. Extension activates on `onStartupFinished`
106+
2. Checks `isMagentoProject` setting ("Please select" → prompt user)
107+
3. Validates `magentoRoot` path → auto-opens folder picker if invalid
108+
4. Creates providers and activates file system watchers on `var/log` and `var/report`
117109

118110
## Integration Points
119111

@@ -129,12 +121,41 @@ vscode.window.showErrorMessage('Error message', 'Action Button').then(selection
129121
- **Node.js fs**: Synchronous and async file operations
130122
- **VS Code Test Framework**: `@vscode/test-cli` for extension testing
131123

132-
## Performance Considerations
124+
### Performance Best Practices
133125

134126
- **Lazy loading**: Heavy operations delayed until user interaction
135-
- **Throttled badge updates**: Maximum one badge update per second
136-
- **Smart caching**: File content cached with automatic memory limits
127+
- **Throttled updates**: Maximum one badge update per second to prevent UI blocking
128+
- **Smart caching**: File content cached with automatic memory limits and LRU eviction
137129
- **Async file operations**: Uses `fs.promises` for non-blocking I/O where possible
130+
- **Batch operations**: Group multiple file operations together
131+
- **Stream processing**: Use streams for large files (>50MB) to prevent memory exhaustion
132+
- **Debounced events**: File watcher events are debounced to prevent excessive refreshes
133+
134+
## Critical Development Workflows
135+
136+
### Build & Development
137+
```bash
138+
npm run compile # Webpack build for development
139+
npm run watch # Watch mode during development
140+
npm run package # Production build for publishing
141+
npm run test # Run extension tests
142+
```
143+
144+
### Testing Best Practices
145+
Tests are located in `src/test/` with focused, single-responsibility test files:
146+
- `extension.test.ts` - Basic extension lifecycle
147+
- `caching.test.ts` - Cache system validation
148+
- `search.test.ts` - Search functionality
149+
- `autoCleanup.test.ts` - Time duration parsing and cleanup logic
150+
- `themeGrouping.test.ts` - Log message grouping and theme detection
151+
- `cacheConfiguration.test.ts`, `logReader.test.ts`, `reportReader.test.ts` - Component-specific tests
152+
153+
**Test Organization Best Practices:**
154+
- One test file per major component/feature
155+
- Use descriptive test names that explain the expected behavior
156+
- Mock external dependencies (file system, VS Code API)
157+
- Test edge cases and error conditions
158+
- Run tests with `npm run test` or F5 debug launch
138159

139160
## Release Documentation
140161

@@ -146,3 +167,30 @@ After implementing new features or fixes, update [CHANGELOG.md](../CHANGELOG.md)
146167
- Example: "Added automatic cleanup of old log files" instead of "Implemented autoCleanupOldLogFiles() function"
147168

148169
When modifying this extension, prioritize user experience with immediate feedback, maintain the caching system integrity, and ensure proper disposal of resources to prevent memory leaks.
170+
171+
## Code Organization & Maintainability Best Practices
172+
173+
**Maintainability is the highest priority.** Always prefer clean, well-structured code over quick solutions:
174+
175+
- **Split large functions** - Break complex logic into smaller, testable functions (max 20-30 lines)
176+
- **Create separate files** - When modules exceed 400-500 lines, split into focused files (e.g., `cacheManager.ts`, `cleanupService.ts`)
177+
- **Single responsibility** - Each function/class should have one clear purpose
178+
- **Clear naming** - Use descriptive names that explain intent without comments
179+
- **Testable units** - Write code that can be easily unit tested in isolation
180+
- **Consistent patterns** - Follow established patterns in the codebase
181+
- **Type safety** - Use TypeScript strictly, avoid `any` types
182+
- **Immutable data** - Prefer immutable operations where possible
183+
184+
**Better to have more files with clear responsibilities than fewer files with mixed concerns.**
185+
186+
## Critical Performance Guidelines
187+
188+
**Always prioritize end-user performance.** Every change must consider impact on user experience:
189+
190+
- **Startup Performance**: Never block VS Code startup - defer heavy operations until needed
191+
- **Memory Efficiency**: Monitor memory usage, implement proper cleanup, avoid memory leaks
192+
- **UI Responsiveness**: Use async/await patterns, throttle UI updates, prevent blocking operations
193+
- **File I/O Optimization**: Cache file reads, use streaming for large files, batch file operations
194+
- **Background Processing**: Move intensive work to background threads when possible
195+
196+
**Performance is a feature - treat it as such in every implementation decision.**

0 commit comments

Comments
 (0)