Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 90ac3f0

Browse files
committed
feat!: allow users to set glob pattern for live execution
BREAKING CHANGE: replace config rcc|uic.liveExecution with rcc|uic.liveExecution.enabled Fix #278
1 parent 1098731 commit 90ac3f0

File tree

4 files changed

+87
-25
lines changed

4 files changed

+87
-25
lines changed

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,18 @@
238238
"markdownDescription": "The options passed to Qt `qmlls` executable. See [here](https://github.com/seanwu1105/vscode-qt-for-python#predefined-variables) for a detailed list of predefined variables.",
239239
"scope": "window"
240240
},
241-
"qtForPython.rcc.liveExecution": {
241+
"qtForPython.rcc.liveExecution.enabled": {
242242
"type": "boolean",
243243
"default": true,
244244
"markdownDescription": "Enable live execution of Qt `rcc` executable. This will automatically compile the resource file when it is saved.",
245245
"scope": "resource"
246246
},
247+
"qtForPython.rcc.liveExecution.glob": {
248+
"type": "string",
249+
"default": "**/*.qrc",
250+
"markdownDescription": "The glob pattern used to match the resource files to be compiled. See [here](https://code.visualstudio.com/api/references/vscode-api#GlobPattern) for a detailed list of glob patterns.",
251+
"scope": "resource"
252+
},
247253
"qtForPython.rcc.path": {
248254
"type": "string",
249255
"default": "",
@@ -262,11 +268,17 @@
262268
"markdownDescription": "The options passed to Qt `rcc` executable. See [here](https://github.com/seanwu1105/vscode-qt-for-python#predefined-variables) for a detailed list of predefined variables.",
263269
"scope": "resource"
264270
},
265-
"qtForPython.uic.liveExecution": {
271+
"qtForPython.uic.liveExecution.enabled": {
266272
"type": "boolean",
267273
"default": true,
268274
"markdownDescription": "Automatically recompile Qt UI files when any `*.ui` file has changed or created."
269275
},
276+
"qtForPython.uic.liveExecution.glob": {
277+
"type": "string",
278+
"default": "**/*.ui",
279+
"markdownDescription": "The glob pattern used to match the UI files to be compiled. See [here](https://code.visualstudio.com/api/references/vscode-api#GlobPattern) for a detailed list of glob patterns.",
280+
"scope": "resource"
281+
},
270282
"qtForPython.uic.path": {
271283
"type": "string",
272284
"default": "",

src/configurations.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,46 @@ type GetEnabledFromConfigArgs = {
6969

7070
type SupportedSwitchableTool = Extract<SupportedTool, 'qmlls'>
7171

72+
export function getLiveExecutionEnabledFromConfig$({
73+
tool,
74+
resource,
75+
}: GetLiveExecutionEnabledFromConfigArgs) {
76+
return getConfiguration$<boolean>({
77+
section: `${EXTENSION_NAMESPACE}.${tool}.liveExecution`,
78+
key: 'enabled',
79+
defaultValue: DEFAULT_LIVE_EXECUTION_ENABLED,
80+
resource,
81+
})
82+
}
83+
84+
const DEFAULT_LIVE_EXECUTION_ENABLED = true
85+
86+
type GetLiveExecutionEnabledFromConfigArgs = {
87+
readonly tool: SupportedLiveExecutionTool
88+
readonly resource: URI | undefined
89+
}
90+
91+
export function getLiveExecutionGlobFromConfig$({
92+
tool,
93+
resource,
94+
defaultValue,
95+
}: GetLiveExecutionGlobFromConfigArgs) {
96+
return getConfiguration$<string>({
97+
section: `${EXTENSION_NAMESPACE}.${tool}.liveExecution`,
98+
key: 'glob',
99+
defaultValue,
100+
resource,
101+
})
102+
}
103+
104+
type GetLiveExecutionGlobFromConfigArgs = {
105+
readonly tool: SupportedLiveExecutionTool
106+
readonly resource: URI | undefined
107+
readonly defaultValue: string
108+
}
109+
110+
type SupportedLiveExecutionTool = Extract<SupportedTool, 'uic' | 'rcc'>
111+
72112
export function getConfiguration$<T>({
73113
section,
74114
key,

src/rcc/rcc-live-execution.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,36 @@ import {
1010
mergeMap,
1111
of,
1212
startWith,
13+
switchMap,
1314
} from 'rxjs'
1415
import { RelativePattern, workspace } from 'vscode'
1516
import { URI } from 'vscode-uri'
1617
import { z } from 'zod'
17-
import { getConfiguration$ } from '../configurations'
18-
import { EXTENSION_NAMESPACE } from '../constants'
18+
import {
19+
getLiveExecutionEnabledFromConfig$,
20+
getLiveExecutionGlobFromConfig$,
21+
} from '../configurations'
1922
import type { ErrorResult, SuccessResult } from '../types'
2023
import { getWatcher$ } from '../watcher'
2124
import { compileResource } from './compile-resource'
2225

2326
export function registerRccLiveExecution$({
2427
extensionUri,
2528
}: RegisterRccLiveExecutionArgs) {
26-
const qrcFiles$ = defer(async () =>
27-
workspace.findFiles('**/*.qrc', '**/site-packages/**'),
28-
).pipe(concatMap(uris => from(uris)))
29+
const glob$ = getLiveExecutionGlobFromConfig$({
30+
tool: 'rcc',
31+
resource: undefined,
32+
defaultValue: '**/*.qrc',
33+
})
34+
35+
const qrcFiles$ = glob$.pipe(
36+
concatMap(glob => workspace.findFiles(glob, '**/site-packages/**')),
37+
concatMap(uris => from(uris)),
38+
)
39+
40+
const watcher$ = glob$.pipe(switchMap(glob => getWatcher$(glob)))
2941

30-
return merge(qrcFiles$, getWatcher$('**/*.qrc')).pipe(
42+
return merge(qrcFiles$, watcher$).pipe(
3143
mergeMap(qrcUri =>
3244
registerResourcesLiveExecution$({ extensionUri, qrcUri }),
3345
),
@@ -52,10 +64,8 @@ function registerResourcesLiveExecution$({
5264
startWith(undefined), // Trigger compilation on resource file changes
5365
concatMap(() =>
5466
firstValueFrom(
55-
getConfiguration$({
56-
section: `${EXTENSION_NAMESPACE}.rcc`,
57-
key: 'liveExecution',
58-
defaultValue: true,
67+
getLiveExecutionEnabledFromConfig$({
68+
tool: 'rcc',
5969
resource: qrcUri,
6070
}),
6171
),

src/uic/uic-live-execution.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
import { concatMap, firstValueFrom } from 'rxjs'
1+
import { concatMap, firstValueFrom, switchMap } from 'rxjs'
22
import type { URI } from 'vscode-uri'
3-
import { getConfiguration$ } from '../configurations'
4-
import { EXTENSION_NAMESPACE } from '../constants'
3+
import {
4+
getLiveExecutionEnabledFromConfig$,
5+
getLiveExecutionGlobFromConfig$,
6+
} from '../configurations'
57
import type { SupportedTool } from '../types'
68
import { getWatcher$ } from '../watcher'
79
import { compileUi } from './compile-ui'
810

911
export function registerUicLiveExecution$({
1012
extensionUri,
1113
}: GetUicLiveExecutionArgs) {
12-
return getWatcher$('**/*.ui').pipe(
14+
return getLiveExecutionGlobFromConfig$({
15+
tool: 'uic',
16+
resource: undefined,
17+
defaultValue: '**/*.ui',
18+
}).pipe(
19+
switchMap(glob => getWatcher$(glob)),
1320
concatMap(uri => onUiFileUpdated({ uri, extensionUri })),
1421
)
1522
}
1623

17-
type GetUicLiveExecutionArgs = {
18-
readonly extensionUri: URI
19-
}
24+
type GetUicLiveExecutionArgs = { readonly extensionUri: URI }
2025

2126
async function onUiFileUpdated({ uri, extensionUri }: OnUiFileUpdatedArgs) {
2227
const tool: SupportedTool = 'uic'
2328
const enabled = await firstValueFrom(
24-
getConfiguration$({
25-
section: `${EXTENSION_NAMESPACE}.${tool}`,
26-
key: 'liveExecution',
27-
defaultValue: true,
28-
resource: uri,
29-
}),
29+
getLiveExecutionEnabledFromConfig$({ tool, resource: uri }),
3030
)
3131

3232
if (!enabled)

0 commit comments

Comments
 (0)