You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+39-2Lines changed: 39 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,6 @@
5
5
- Use `Uri.joinPath()` for constructing file paths to ensure platform-correct path separators (e.g., `Uri.joinPath(venvPath, 'share', 'jupyter', 'kernels')` instead of string concatenation with `/`)
6
6
- Follow established patterns, especially when importing new packages (e.g. instead of importing uuid directly, use the helper `import { generateUuid } from '../platform/common/uuid';`)
7
7
8
-
9
8
## Code conventions
10
9
11
10
- Always run `npx prettier` before committing
@@ -19,7 +18,6 @@
19
18
- Tests run against compiled JavaScript files in `out/` directory
20
19
- Use `assert.deepStrictEqual()` for object comparisons instead of checking individual properties
21
20
22
-
23
21
## Project Structure
24
22
25
23
- VSCode extension for Jupyter notebooks
@@ -40,3 +38,42 @@
40
38
- Whitespace is good for readability, add a blank line after const groups and before return statements
41
39
- Separate third-party and local file imports
42
40
- How the extension works is described in @specs/architecture.md
41
+
42
+
## Best Practices
43
+
44
+
### Resource Cleanup
45
+
46
+
- Always dispose `CancellationTokenSource` - never create inline without storing/disposing
47
+
- Use try/finally to ensure cleanup:
48
+
```typescript
49
+
const cts =newCancellationTokenSource();
50
+
try {
51
+
awaitfn(cts.token);
52
+
} finally {
53
+
cts.dispose();
54
+
}
55
+
```
56
+
57
+
### DRY Principle
58
+
59
+
- Extract duplicate logic into helper methods to prevent drift
60
+
- When similar logic appears in multiple places (e.g., placeholder controller setup, interpreter validation), consolidate it
61
+
62
+
### Magic Numbers
63
+
64
+
- Extract magic numbers (retry counts, delays, timeouts) as named constants near the top of the module
65
+
66
+
### Error Handling
67
+
68
+
- Use per-iteration error handling in loops - wrap each iteration in try/catch so one failure doesn't stop the rest
69
+
- Handle `withProgress` cancellation gracefully - it throws when user cancels, so wrap in try/catch and return appropriate value
70
+
71
+
### State Validation
72
+
73
+
- Verify state after async setup operations - methods can return early without throwing, so check expected state was created
74
+
- Validate cached state before early returns - before returning "already configured", verify the state is still valid (e.g., interpreter paths match, controllers aren't stale)
75
+
76
+
### Cancellation Tokens
77
+
78
+
- Use real cancellation tokens tied to lifecycle events instead of fake/never-cancelled tokens
0 commit comments