Skip to content

Commit ad0aeac

Browse files
committed
Exposed API call to CL Prompter to enable CL Prompter in other Extensions FIXES
1 parent 7667df9 commit ad0aeac

File tree

8 files changed

+531
-66
lines changed

8 files changed

+531
-66
lines changed

API_TESTS.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# API Export Verification Tests
2+
3+
This test verifies that the CLPrompter API is properly exported and accessible to external extensions.
4+
5+
## What is Being Tested
6+
7+
The test verifies that:
8+
9+
1. ✅ The `activate()` function in `extension.ts` imports `CLPrompter` and `CLPrompterCallback`
10+
2. ✅ The `activate()` function returns `{ CLPrompter, CLPrompterCallback }`
11+
3. ✅ External extensions can access the API using `vscode.extensions.getExtension()`
12+
13+
## Why This Matters
14+
15+
After Alan's feedback on issue #6, we discovered that the `activate()` function wasn't returning the exports. This meant external extensions couldn't access the API.
16+
17+
**The Fix:**
18+
```typescript
19+
// In extension.ts activate() function
20+
return {
21+
CLPrompter,
22+
CLPrompterCallback
23+
};
24+
```
25+
26+
## Running the Tests
27+
28+
Run the verification test to check the source code:
29+
30+
```bash
31+
npm run test:api
32+
```
33+
34+
This will:
35+
1. Compile the test file
36+
2. Check the source code for proper imports and return statement
37+
3. Verify the API export structure
38+
39+
## Expected Output
40+
41+
If everything is working correctly, you should see:
42+
43+
```
44+
╔════════════════════════════════════════════════════════╗
45+
║ CLPrompter API Export Verification Test ║
46+
╚════════════════════════════════════════════════════════╝
47+
48+
Checking that activate() returns the API exports...
49+
50+
Step 1: Checking for CLPrompter import...
51+
✓ CLPrompter imported from clPrompter module
52+
53+
Step 2: Checking for CLPrompterCallback import...
54+
✓ CLPrompterCallback imported from clPrompter module
55+
56+
Step 3: Checking activate() function return statement...
57+
✓ activate() returns { CLPrompter, CLPrompterCallback }
58+
59+
============================================================
60+
✅ SUCCESS! API is properly exported
61+
============================================================
62+
63+
The activate() function correctly returns:
64+
return { CLPrompter, CLPrompterCallback };
65+
66+
External extensions can access the API using:
67+
68+
const ext = vscode.extensions.getExtension('CozziResearch.clprompter');
69+
if (!ext.isActive) await ext.activate();
70+
const { CLPrompter } = ext.exports;
71+
const result = await CLPrompter(command);
72+
```
73+
74+
## What External Extensions Need to Do
75+
76+
With the API properly exported, external extensions can use either pattern:
77+
78+
### Pattern 1: Optional Enhancement (Recommended)
79+
80+
```typescript
81+
const clPrompterExt = vscode.extensions.getExtension('CozziResearch.clprompter');
82+
83+
if (clPrompterExt) {
84+
if (!clPrompterExt.isActive) {
85+
await clPrompterExt.activate();
86+
}
87+
88+
if (clPrompterExt.exports?.CLPrompter) {
89+
const result = await clPrompterExt.exports.CLPrompter(command);
90+
// Use result...
91+
}
92+
} else {
93+
// Fallback to simple input box
94+
}
95+
```
96+
97+
### Pattern 2: Required Dependency
98+
99+
Add to `package.json`:
100+
```json
101+
{
102+
"extensionDependencies": ["CozziResearch.clprompter"]
103+
}
104+
```
105+
106+
Then use directly:
107+
```typescript
108+
const clPrompterExt = vscode.extensions.getExtension('CozziResearch.clprompter')!;
109+
await clPrompterExt.activate();
110+
const { CLPrompter } = clPrompterExt.exports;
111+
const result = await CLPrompter(command);
112+
```
113+
114+
## Test Files
115+
116+
- `src/testAPICall.ts` - Main verification test (checks source code)
117+
118+
The old mock-based test files have been removed as they were overly complex and had multiple issues. The simple source code verification is sufficient and reliable.
119+
120+
## Troubleshooting
121+
122+
### Test Fails: "return statement NOT found"
123+
124+
The `activate()` function in `extension.ts` is missing the return statement. Add this at the end of the function:
125+
126+
```typescript
127+
return {
128+
CLPrompter,
129+
CLPrompterCallback
130+
};
131+
```
132+
133+
### Test Fails: "Could not find extension.ts"
134+
135+
The test looks for the source file at `src/extension.ts`. Make sure you're running the test from the project root directory.
136+
137+
## References
138+
139+
- Issue #6: https://github.com/bobcozzi/clPrompter/issues/6
140+
- API Documentation: [CLPROMPTER_API.md](CLPROMPTER_API.md)

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.0.49] - 2026-02-21
6+
### Fixed
7+
- **Public API: Export correction**: Fixed `activate()` function to properly return API exports for external extensions
8+
- Added `return { CLPrompter, CLPrompterCallback }` statement that was missing
9+
- External extensions can now correctly access the API via `vscode.extensions.getExtension().exports`
10+
- Issue reported by Alan in #6 - dynamic import pattern doesn't work, but extension API pattern does
11+
### Added
12+
- **API Documentation**: Updated CLPROMPTER_API.md with correct usage patterns
13+
- Documented both Optional Enhancement and Required Dependency integration approaches
14+
- Replaced incorrect dynamic import examples with proper `vscode.extensions.getExtension()` pattern
15+
- Added comprehensive examples showing fallback patterns for graceful degradation
16+
- **API Verification Test**: Added `testAPICall.ts` to verify API exports are correct
17+
- Checks source code for proper imports and return statement
18+
- Run with `npm run test:api` to validate API structure
19+
- Documentation in API_TESTS.md
20+
### Changed
21+
- **Build Configuration**: Updated tsconfig.json to exclude test, run, and debug files from builds
22+
- Added exclusions for `src/test*.ts`, `src/run*.ts`, and `src/debug*.ts` patterns
23+
- Development/testing files no longer compiled into extension package
24+
525
## [0.0.48] - 2026-02-20
626
### Added
727
- **Public API for external extensions**: Exposed `CLPrompter()` function that external extensions can import and use programmatically

0 commit comments

Comments
 (0)