|
1 |
| -import { concatMap, firstValueFrom, switchMap } from 'rxjs' |
| 1 | +import { concatMap, of, switchMap } from 'rxjs' |
2 | 2 | import type { URI } from 'vscode-uri'
|
3 | 3 | import {
|
4 | 4 | getLiveExecutionEnabledFromConfig$,
|
5 | 5 | getLiveExecutionGlobFromConfig$,
|
6 | 6 | } from '../configurations'
|
7 |
| -import type { SupportedTool } from '../types' |
8 | 7 | import { getWatcher$ } from '../watcher'
|
9 | 8 | import { compileUi } from './compile-ui'
|
10 | 9 |
|
11 | 10 | export function registerUicLiveExecution$({
|
12 | 11 | extensionUri,
|
13 | 12 | }: GetUicLiveExecutionArgs) {
|
14 |
| - return getLiveExecutionGlobFromConfig$({ |
| 13 | + const onUiFileUpdated$ = getLiveExecutionGlobFromConfig$({ |
15 | 14 | tool: 'uic',
|
16 | 15 | resource: undefined,
|
17 | 16 | defaultValue: '**/*.ui',
|
18 | 17 | }).pipe(
|
19 |
| - switchMap(glob => getWatcher$(glob)), |
20 |
| - concatMap(uri => onUiFileUpdated({ uri, extensionUri })), |
| 18 | + switchMap(global => getWatcher$(global)), |
| 19 | + concatMap(uri => compileUi({ extensionUri }, uri)), |
21 | 20 | )
|
22 |
| -} |
23 | 21 |
|
24 |
| -type GetUicLiveExecutionArgs = { readonly extensionUri: URI } |
| 22 | + return getLiveExecutionEnabledFromConfig$({ |
| 23 | + tool: 'uic', |
| 24 | + resource: undefined, |
| 25 | + }).pipe( |
| 26 | + switchMap(enabled => { |
| 27 | + if (!enabled) |
| 28 | + return of({ |
| 29 | + kind: 'Success', |
| 30 | + value: 'uic live execution disabled', |
| 31 | + } as const) |
25 | 32 |
|
26 |
| -async function onUiFileUpdated({ uri, extensionUri }: OnUiFileUpdatedArgs) { |
27 |
| - const tool: SupportedTool = 'uic' |
28 |
| - const enabled = await firstValueFrom( |
29 |
| - getLiveExecutionEnabledFromConfig$({ tool, resource: uri }), |
| 33 | + return onUiFileUpdated$ |
| 34 | + }), |
30 | 35 | )
|
31 |
| - |
32 |
| - if (!enabled) |
33 |
| - return { kind: 'Success', value: 'Live execution disabled' } as const |
34 |
| - |
35 |
| - return compileUi({ extensionUri }, uri) |
36 | 36 | }
|
37 | 37 |
|
38 |
| -type OnUiFileUpdatedArgs = { |
39 |
| - readonly extensionUri: URI |
40 |
| - readonly uri: URI |
41 |
| -} |
| 38 | +type GetUicLiveExecutionArgs = { readonly extensionUri: URI } |
0 commit comments