Skip to content

Commit a32bb2f

Browse files
authored
Merge pull request #186 from rajbos/copilot/detect-sym-in-file-viewer
Detect #sym references and fix diagnostics logging
2 parents eb231af + db3e695 commit a32bb2f

18 files changed

Lines changed: 3095 additions & 1373 deletions

File tree

.github/copilot-instructions.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,49 @@ The entire extension's logic is contained within the `CopilotTokenTracker` class
3838

3939
## Logging Best Practices
4040

41-
**CRITICAL**: Do NOT add debug logging statements like `log('[DEBUG] message')` for troubleshooting during development. This approach has been found to interfere with the output channel and can hide existing log messages from appearing.
41+
**CRITICAL**: Do NOT add debug logging statements like `this.log('[DEBUG] message')` or `console.log('[DEBUG] ...')` for troubleshooting during development. This approach has been found to flood the output channel and cause messages to disappear.
4242

43-
- **Use Existing Logs**: The extension already has comprehensive logging throughout. Review existing log statements to understand what's being tracked.
44-
- **Minimal Logging**: Only add logging if absolutely necessary for a new feature. Keep messages concise and informative.
45-
- **Remove Debug Logs**: Any temporary debug logging added during development MUST be removed before committing code.
46-
- **Log Methods**: Use the appropriate method for the severity:
43+
### Why DEBUG Logs Are Problematic
44+
45+
**Extension Host Flooding**: When DEBUG log statements are added to frequently-called methods in `extension.ts` (e.g., cache lookups, file processing loops, webview message handlers), they can generate hundreds of log entries per operation. VS Code's OutputChannel has a buffer limit, and excessive logging causes older messages to be pushed out and lost. This was observed when:
46+
- Cache hit/miss logging was added to session file processing
47+
- JSONL content reference counting was logged for each file
48+
- Webview message handlers logged every incoming message with full JSON payloads
49+
- Session data was logged with repository counts on each webview update
50+
51+
**Symptom**: After operations like clearing the cache, expected log messages would disappear from the Output panel because they were pushed out of the buffer by DEBUG logs.
52+
53+
### Extension vs Webview Logging
54+
55+
These are two completely separate logging systems:
56+
57+
| Context | Method | Destination | Visibility |
58+
|---------|--------|-------------|------------|
59+
| Extension (`src/extension.ts`) | `this.log()`, `this.warn()`, `this.error()` | VS Code Output Channel | Output panel → "Copilot Token Tracker" |
60+
| Webview (`src/webview/*/main.ts`) | `console.log()` | Browser DevTools | Help → Toggle Developer Tools in webview |
61+
62+
- Clearing the output channel (`outputChannel.clear()`) does NOT affect webview console logs
63+
- Webview console.log statements do NOT appear in the Output panel
64+
- DEBUG prefixes in webviews were removed to maintain consistency with extension guidelines
65+
66+
### Best Practices
67+
68+
- **Use Existing Logs**: The extension already has comprehensive logging. Review existing log statements before adding new ones.
69+
- **Minimal Logging**: Only add logging if absolutely necessary for a new feature. Keep messages concise.
70+
- **Remove Debug Logs**: Any temporary debug logging added during development MUST be removed before committing.
71+
- **Log Methods**: Use appropriate severity:
4772
- `log(message)` - Standard informational messages
4873
- `warn(message)` - Warnings or recoverable errors
4974
- `error(message)` - Critical errors
50-
- **No Debug Prefixes**: Avoid prefixing messages with `[DEBUG]` or similar markers. The log output is already timestamped and categorized.
75+
- **No Debug Prefixes**: Avoid `[DEBUG]` markers. The log output is already timestamped.
76+
- **Avoid High-Frequency Logging**: Never log inside loops that process many items (files, sessions, cache entries).
77+
78+
### Debugging Without Logs
5179

52-
If you need to troubleshoot execution flow, prefer using VS Code's debugger with breakpoints rather than adding log statements.
80+
Prefer VS Code's debugger with breakpoints rather than adding log statements:
81+
1. Press `F5` to launch Extension Development Host
82+
2. Set breakpoints in `src/extension.ts`
83+
3. Use the Debug Console to inspect variables
5384

5485
## Key Files & Conventions
5586

.stylelintrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": ["stylelint-config-standard"],
3+
"rules": {
4+
"selector-class-pattern": null,
5+
"custom-property-pattern": null,
6+
"no-descending-specificity": null,
7+
"color-function-notation": null,
8+
"alpha-value-notation": null
9+
}
10+
}

esbuild.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ async function main() {
5959
external: ['vscode'],
6060
logLevel: 'silent',
6161
plugins: [esbuildProblemMatcherPlugin],
62+
loader: { '.css': 'text' },
6263
});
6364

6465
if (watch) {

0 commit comments

Comments
 (0)