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

Commit 289e02b

Browse files
committed
fix: parse qrc files with multiple qresource elements
Fix #290.
1 parent 833248f commit 289e02b

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

python/tests/assets/qrc/rc2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
second

python/tests/assets/qrc/sample.qrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
<file>rc0.txt</file>
44
<file>rc1.txt</file>
55
</qresource>
6+
<qresource prefix="/subdir">
7+
<file>rc2.txt</file>
8+
</qresource>
69
</RCC>

src/rcc/rcc-live-execution.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ async function getResourceFiles({
9393
const content = (await workspace.fs.readFile(qrcUri)).toString()
9494

9595
const parserOptions: X2jOptionsOptional = {
96-
isArray: (name, _jpath, _isLeafNode, _isAttribute) => name === 'file',
96+
isArray: (name, _jpath, _isLeafNode, _isAttribute) =>
97+
name === 'file' || name === 'qresource',
9798
}
9899

99100
const xmlParser = new XMLParser(parserOptions)
@@ -118,8 +119,10 @@ async function getResourceFiles({
118119
)} (${parsed})`,
119120
}
120121

121-
const resourceUris = validationResult.data.RCC.qresource.file.map(filePath =>
122-
URI.file(path.join(path.dirname(qrcUri.fsPath), filePath)),
122+
const resourceUris = validationResult.data.RCC.qresource.flatMap(resource =>
123+
resource.file.map(filePath =>
124+
URI.file(path.join(path.dirname(qrcUri.fsPath), filePath)),
125+
),
123126
)
124127
return { kind: 'Success', value: resourceUris }
125128
}
@@ -134,8 +137,10 @@ type GetResourceFilesResult =
134137

135138
const RccSchema = z.object({
136139
RCC: z.object({
137-
qresource: z.object({
138-
file: z.array(z.string()),
139-
}),
140+
qresource: z.array(
141+
z.object({
142+
file: z.array(z.string()),
143+
}),
144+
),
140145
}),
141146
})

0 commit comments

Comments
 (0)