Skip to content

Commit 07433ee

Browse files
committed
multiple support for xml.references"
Signed-off-by: azerr <azerr@redhat.com>
1 parent b338c32 commit 07433ee

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

docs/Features/XMLReferencesFeatures.md

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ XML References support provides the capability to reference a DOM node (attribut
44

55
* `foo/@attr` defines the `attr` attribute node of the `foo` element.
66
* `foo/text()` defines the text node of the `foo` element.
7+
8+
Once you have declared those reference, you will benefit with completion, definition, highlight, validation, rename, find references, and show references count with codelens.
79

810
## Attribute node references (foo/@attr)
911

@@ -49,9 +51,12 @@ After saving this setting, you will get completion, go to definition, and highli
4951

5052
The `xml.references` settings is an array of objects with the following properties:
5153

52-
* `pattern`: matches the files that reference declared with `expressions` applies to. See [glob syntax](https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob) for more information about the pattern syntax.
54+
* `pattern`: matches the files that reference declared with `expressions` applies to. See [glob syntax](https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob) for more information about the pattern syntax.
55+
* `prefix (optional)`: the prefix to use (ex : '#') for from for all expressions.
56+
* `multiple (optional)`: true if the from attribute, text can declare several from references and false otherwise for all expressions.
5357
* `expressions`: array of reference expression:
5458
* `prefix (optional)`: the prefix to use (ex : '#') for from.
59+
* `multiple (optional)`: true if the from attribute, text can declare several from references and false otherwise.
5560
* `from`: the from reference DOM node (attribute, text) declared with XPath (ex: `foo/@attr`, `foo/text()`).
5661
* `to`: the to reference DOM node (attribute, text) declared with XPath (ex: `foo/@attr`, `foo/text()`).
5762

@@ -91,21 +96,50 @@ In this sample, `corresp` attribute in `<anchor corresp="#body-id"></anchor>` re
9196
"xml.references": [
9297
{
9398
"pattern": "**/*.xml",
99+
"prefix": "#",
94100
"expressions": [
95101
{
96-
"prefix": "#",
97102
"from": "@resp",
98103
"to": "persName/@xml:id"
99104
},
100105
{
101-
"prefix": "#",
102106
"from": "@corresp",
103107
"to": "@xml:id"
104108
}
105109
]
106110
}
107111
]
108112
```
113+
## Multiple target
114+
115+
If the `origin` attribute (which matches the `from` reference path) declares multiple targets (which matches the `to` reference path), you can use `multiple`
116+
117+
Given this XML file where `target` attribute defines several targets separated with whitespace (#body-id #p-id):
118+
119+
```xml
120+
<body xml:id="body-id">
121+
<p xml:id="p-id" >Some text here.</p>
122+
<link target="#body-id #p-id"></link>
123+
</body>
124+
```
125+
126+
In this sample, `target` attribute in `<link target="#body-id #p-id"></link>` references the `body-id` and `p-id` (without `#`) declared in `<body xml:id="body-id">` and `<p xml:id="p-id" >`. It means that the `target` attribute value (with `#`) reference `@xml:id` attribute (without `#`). To support that, you can configure settings by using `multiple`:
127+
128+
```json
129+
"xml.references": [
130+
{
131+
"pattern": "**/*.xml",
132+
"prefix": "#",
133+
"multiple": true,
134+
"expressions": [
135+
{
136+
"from": "link/@target",
137+
"to": "@xml:id"
138+
}
139+
]
140+
}
141+
]
142+
```
109143

110144
## Text node references (foo/text())
111145

@@ -150,17 +184,5 @@ In this sample, `servlet-mapping/servlet-name` text in `<servlet-name>comingsoon
150184
XML references have some limitation:
151185

152186
* *references works only for a given XML file*: it is not possible to reference some DOM nodes coming from another XML files. However if the file uses include (like xi:include) the reference will only work in the file which has the include statement, and not in the file being included.
153-
* *multiple target is not supported*: if the `origin` attribute (which matches the `from` reference path) declares multiple targets (which matches the `to` reference path), it will not work.
154-
155-
Given this XML file where `corresp` attribute defines several targets separated with whitespace (#body-id #p-id):
156-
157-
```xml
158-
<body xml:id="body-id">
159-
<p xml:id="p-id" >Some text here.</p>
160-
<anchor corresp="#body-id #p-id"></anchor>
161-
</body>
162-
```
163-
164-
This usecase is not supported today.
165187

166188
If you need those support, please [create an issue](https://github.com/redhat-developer/vscode-xml/issues)

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,14 @@
643643
"type": "string",
644644
"markdownDescription": "matches the files that reference declared with `expressions` applies to.\n\nMore information on the glob syntax: https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob"
645645
},
646+
"prefix": {
647+
"type": "string",
648+
"description": "The prefix to use (ex : '#') for from for all expressions."
649+
},
650+
"multiple": {
651+
"type": "boolean",
652+
"description": "true if the from attribute, text can declare several from references and false otherwise for all expressions."
653+
},
646654
"expressions": {
647655
"type": "array",
648656
"default": [],
@@ -653,6 +661,10 @@
653661
"type": "string",
654662
"description": "The prefix to use (ex : '#') for from."
655663
},
664+
"multiple": {
665+
"type": "boolean",
666+
"description": "true if the from attribute, text can declare several from references and false otherwise."
667+
},
656668
"from": {
657669
"type": "string",
658670
"description": "The from reference DOM node (attribute, text) declared with XPath (ex: foo/@attr, foo/text())."

0 commit comments

Comments
 (0)