Skip to content

Commit c7ed01d

Browse files
angelozerrdatho7561
authored andcommitted
multiple support for xml.references"
Signed-off-by: azerr <[email protected]>
1 parent b338c32 commit c7ed01d

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

docs/Features/XMLReferencesFeatures.md

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ 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:
9+
10+
![XML References with TEI](../images/Features/XMLReferencesWithTEI.gif)
711

812
## Attribute node references (foo/@attr)
913

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

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

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.
56+
* `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.
57+
* `prefix (optional)`: the prefix to use (ex : '#') for from for all the declared reference expressions.
58+
* `multiple (optional)`: true if the from attribute, text can declare several from references and false otherwise for all the declared reference expressions.
5359
* `expressions`: array of reference expression:
5460
* `prefix (optional)`: the prefix to use (ex : '#') for from.
61+
* `multiple (optional)`: true if the from attribute, text can declare several from references and false otherwise.
5562
* `from`: the from reference DOM node (attribute, text) declared with XPath (ex: `foo/@attr`, `foo/text()`).
5663
* `to`: the to reference DOM node (attribute, text) declared with XPath (ex: `foo/@attr`, `foo/text()`).
5764

@@ -91,21 +98,50 @@ In this sample, `corresp` attribute in `<anchor corresp="#body-id"></anchor>` re
9198
"xml.references": [
9299
{
93100
"pattern": "**/*.xml",
101+
"prefix": "#",
94102
"expressions": [
95103
{
96-
"prefix": "#",
97104
"from": "@resp",
98105
"to": "persName/@xml:id"
99106
},
100107
{
101-
"prefix": "#",
102108
"from": "@corresp",
103109
"to": "@xml:id"
104110
}
105111
]
106112
}
107113
]
108114
```
115+
## Multiple target
116+
117+
If the `origin` attribute (which matches the `from` reference path) declares multiple targets (which matches the `to` reference path), you can use `multiple`
118+
119+
Given this XML file where `target` attribute defines several targets separated with whitespace (#body-id #p-id):
120+
121+
```xml
122+
<body xml:id="body-id">
123+
<p xml:id="p-id" >Some text here.</p>
124+
<link target="#body-id #p-id"></link>
125+
</body>
126+
```
127+
128+
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`:
129+
130+
```json
131+
"xml.references": [
132+
{
133+
"pattern": "**/*.xml",
134+
"prefix": "#",
135+
"multiple": true,
136+
"expressions": [
137+
{
138+
"from": "link/@target",
139+
"to": "@xml:id"
140+
}
141+
]
142+
}
143+
]
144+
```
109145

110146
## Text node references (foo/text())
111147

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

152188
* *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.
165189

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

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 the declared reference 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 the declared reference 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)