Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ This VS Code extension provides support for creating and editing XML documents,
* [Minify XML](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Commands.md#minify-xml-document)
* [Generate XML from Grammar](https://github.com/redhat-developer/vscode-xml/blob/main/docs/GenerateXMLFromGrammar.md#generate-xml-from-grammar)
* [Generate Schema from XML](https://github.com/redhat-developer/vscode-xml/blob/main/docs/BindingWithGrammar.md#binding-with-new-grammar)
* *[Code Lens](https://github.com/redhat-developer/vscode-xml/blob/main/docs/CodeLens.md) when `xml.codeLens.enabled` is enabled*
* *[Inlay Hints](https://github.com/redhat-developer/vscode-xml/blob/main/docs/InlayHint.md) when `xml.inlayHint.enabled` is enabled*

See the [changelog](CHANGELOG.md) for the latest release.

Expand Down Expand Up @@ -100,6 +102,7 @@ The following settings are supported:
* `xml.autoCloseTags.enabled` : Enable/disable autoclosing of XML tags. Default is `true`.
**IMPORTANT**: The following settings must be turned of for this to work: `editor.autoClosingTags`, `editor.autoClosingBrackets`.
* [`xml.codeLens.enabled`](https://github.com/redhat-developer/vscode-xml/blob/main/docs/CodeLens.md): Enable/disable XML CodeLens. Default is `false`.
* [`xml.inlayHint.enabled`](https://github.com/redhat-developer/vscode-xml/blob/main/docs/InlayHint.md): Enable/disable XML Inlay Hints (default values, attribute types, element types). Default is `false`.
* [`xml.preferences.showSchemaDocumentationType`](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Preferences.md#documentation-type): Specifies the source of the XML schema documentation displayed on hover and completion. Default is `all`.
* [`xml.validation.enabled`](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Validation.md): Enable/disable all validation. Default is `true`.
* [`xml.validation.namespaces.enabled`](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Validation.md#xmlvalidationsnamespacesenabled): Enable/disable namespaces validation. Default is `always`. Ignored if [`xml.validation.enabled`](https://github.com/redhat-developer/vscode-xml/blob/main/docs/Validation.md) is set to `false`.
Expand Down
123 changes: 123 additions & 0 deletions docs/InlayHint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@

## Inlay Hint

Inlay hints display grammar-derived information directly in the editor to help you understand the structure of your XML documents without having to look at the schema.

To enable inlay hints, set `xml.inlayHint.enabled` to `true` (default is `false`).

There are three kinds of inlay hints, each controlled by its own setting:

| Setting | Default | Description |
|---------|---------|-------------|
| `xml.inlayHint.enabled` | `false` | Enable/disable XML inlay hints |
| `xml.inlayHint.showDefaultValue` | `true` | Show default attribute values from the grammar |
| `xml.inlayHint.showAttributeType` | `true` | Show attribute types (e.g., `: xs:integer`) |
| `xml.inlayHint.showElementType` | `true` | Show element types (e.g., `: xs:boolean`) |

Types equal to `xs:string` are automatically filtered out as they are too common to be informative.

### Default attribute values

When an XML file is bound to a grammar (XSD, DTD) that defines `default` or `fixed` attribute values, inlay hints show these values next to the element's start tag for attributes that are not explicitly set.

For example, given the following XSD (`form.xsd`):

```xml
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="form">
<xs:complexType>
<xs:sequence>
<xs:element name="input" type="inputType" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="lang" type="xs:string" default="en" />
<xs:attribute name="method" type="xs:string" default="GET" />
<xs:attribute name="maxRetries" type="xs:int" />
<xs:attribute name="debug" type="xs:boolean" default="false" />
</xs:complexType>
</xs:element>
<xs:complexType name="inputType">
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="type" type="xs:string" default="text" />
<xs:attribute name="maxLength" type="xs:integer" />
<xs:attribute name="required" type="xs:boolean" default="false" />
</xs:complexType>
</xs:schema>
```

And the following XML (`form.xml`):

```xml
<?xml version="1.0" encoding="UTF-8"?>
<form
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="form.xsd"
maxRetries="3">
<input name="username" />
<input name="email" maxLength="255" required="true" />
</form>
```

Inlay hints for default attribute values will appear:

- On `<form>`: `lang="en"`, `method="GET"`, `debug="false"`
- On `<input name="username" />`: `type="text"`, `required="false"`
- On `<input name="email" ...>`: `type="text"` (but not `required` since it is explicitly set)

![XSD default attribute value inlay hints](./images/InlayHint/InlayHintDefaultValueXSD.png)

Default attribute values defined in DTD `ATTLIST` declarations are also shown.

Given the following DTD (`note.dtd`):

```dtd
<!ELEMENT note (#PCDATA)>
<!ATTLIST note
status CDATA "draft"
priority CDATA "normal">
```

And the following XML (`note.xml`):

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>Remember to review the inlay hint PR.</note>
```

Inlay hints `status="draft"` and `priority="normal"` will appear after the `note` tag name.

![DTD default attribute value inlay hints](./images/InlayHint/InlayHintDefaultValueDTD.png)

### Attribute types

When enabled, attribute type hints show the XSD type of each attribute after the attribute name (before the `=` sign).

Using the same `form.xsd` and `form.xml` above, the following attribute type hints are shown:

- `maxRetries` → `: xs:int`
- `maxLength` → `: xs:integer`
- `required` → `: xs:boolean`
- `lang`, `method`, `name`, `type` → no type hint (`xs:string` is filtered out)

![Attribute type inlay hints](./images/InlayHint/InlayHintAttributeType.png)

### Element types

When enabled, element type hints show the XSD type of each element after the element tag name.

Using the same `form.xsd` and `form.xml` above, the following element type hints are shown:

- `<input>` → `: inputType`
- `<form>` → no type hint (anonymous complex type, no named type)

![Element type inlay hints](./images/InlayHint/InlayHintElementType.png)
Comment thread
angelozerr marked this conversation as resolved.

Elements with anonymous (inline) complex types do not show a type hint, since they have no named type.

### Settings

- `xml.inlayHint.enabled`: Enable/disable XML inlay hints. Default is `false`.
- `xml.inlayHint.showDefaultValue`: Show default attribute values from grammar. Default is `true`.
- `xml.inlayHint.showAttributeType`: Show attribute types. Default is `true`.
- `xml.inlayHint.showElementType`: Show element types. Default is `true`.
4 changes: 4 additions & 0 deletions docs/Preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ See the [Formatting page](Formatting.md#formatting).

Use `xml.codeLens.enabled` in order to enable or disable code lens. Please see [the Code Lens page](CodeLens.md#code-lens) for more information.

## Inlay Hint

Use `xml.inlayHint.enabled` to enable inlay hints (default is `false`). Once enabled, use `xml.inlayHint.showDefaultValue`, `xml.inlayHint.showAttributeType`, and `xml.inlayHint.showElementType` to control individual inlay hint features. Please see [the Inlay Hint page](InlayHint.md#inlay-hint) for more information.

## Tag Auto Closing

The closing tags for elements should automatically be added when typing `>` to complete an opening tag.
Expand Down
Binary file added docs/images/InlayHint/InlayHintAttributeType.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/InlayHint/InlayHintElementType.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,26 @@
"default": false,
"markdownDescription": "Enable/disable XML CodeLens. Default is `false`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22CodeLens%22%2C%22section%22%3A%22Code%20Lens%22%7D%5D) for information about CodeLens features"
},
"xml.inlayHint.enabled": {
"type": "boolean",
"default": false,
"markdownDescription": "Enable/disable XML inlay hints. Default is `false`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22InlayHint%22%2C%22section%22%3A%22Inlay%20Hint%22%7D%5D) for more information."
},
"xml.inlayHint.showDefaultValue": {
"type": "boolean",
"default": true,
"markdownDescription": "Show default attribute values defined by the grammar (XSD, DTD) as inlay hints. Default is `true`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22InlayHint%22%2C%22section%22%3A%22Inlay%20Hint%22%7D%5D) for more information."
},
"xml.inlayHint.showAttributeType": {
"type": "boolean",
"default": true,
"markdownDescription": "Show the type of XML attributes (e.g., `: xs:integer`) as inlay hints after the attribute name. Types equal to `xs:string` are filtered out. Default is `true`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22InlayHint%22%2C%22section%22%3A%22Inlay%20Hint%22%7D%5D) for more information."
},
"xml.inlayHint.showElementType": {
"type": "boolean",
"default": true,
"markdownDescription": "Show the type of XML elements (e.g., `: xs:integer`) as inlay hints before the closing `>` of the start tag. Types equal to `xs:string` are filtered out. Default is `true`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22InlayHint%22%2C%22section%22%3A%22Inlay%20Hint%22%7D%5D) for more information."
},
"xml.semanticTokens.enabled": {
"type": "boolean",
"default": true,
Expand Down
Loading