Commit 8793d0b
committed
Fix event handler type and Promise handling in query-server-client
This commit fixes incorrect type signatures and Promise handling for
query server event handlers that were causing ESLint errors.
Problem:
The queryServerStartListeners were typed to return 'void', but actual
usage in the codebase shows they can be async functions returning
'Promise<void>'. This mismatch caused two issues:
1. Type mismatch: The onStart() method in query-runner.ts accepts
callbacks typed as '(progress) => Promise<void>', but the listener
registration was typed as '(progress) => void'
2. ESLint error at line 163: When calling Promise.all() on the array
of handler results, ESLint detected that handlers might return void
instead of Promise, triggering '@typescript-eslint/await-thenable':
'Unexpected iterable of non-Promise values passed to promise
aggregator'
Solution:
1. Update type signatures to allow both synchronous (void) and
asynchronous (Promise<void>) handlers:
- Changed listener array type from '() => void' to
'() => void | Promise<void>'
- Updated onDidStartQueryServer parameter type to match
2. Wrap handler invocations in Promise.resolve() to ensure they always
return a Promise, regardless of whether the handler is sync or async:
- Changed: handler(progress)
- To: Promise.resolve(handler(progress))
This makes Promise.all() safe to use with mixed sync/async handlers
while maintaining backward compatibility with existing code.
File modified:
- extensions/ql-vscode/src/query-server/query-server-client.ts1 parent b6a6d27 commit 8793d0b
1 file changed
+5
-3
lines changedLines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
164 | 166 | | |
165 | 167 | | |
166 | 168 | | |
| |||
0 commit comments