Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml.format.emptyElements should respect grammar constraint #492

Closed
angelozerr opened this issue Jul 1, 2019 · 2 comments · Fixed by #1305
Closed

xml.format.emptyElements should respect grammar constraint #492

angelozerr opened this issue Jul 1, 2019 · 2 comments · Fixed by #1305
Assignees
Labels
enhancement New feature or request formatting This issue or enhancement is related to formatting support

Comments

@angelozerr
Copy link
Contributor

angelozerr commented Jul 1, 2019

Please read #492 (comment)

XML formatting should give a preferences like xml.format.autoTagClose to auto close the element which is formatted.

In other words, formatting :

<element name="myName"></element>

should format like this:

<element name="myName" />
@angelozerr angelozerr added enhancement New feature or request formatting This issue or enhancement is related to formatting support labels Jul 1, 2019
@fbricon
Copy link
Contributor

fbricon commented Jul 1, 2019

This might be trickier than it seems: it should respect XSD's nillable=false definitions

@angelozerr
Copy link
Contributor Author

This issue is managed by xml.format.emptyElements in old formatter but don't take care of XSD/DTD constraints (it should respect XSD's nillable=false definitions)

@JessicaJHee is supporting xml.format.emptyElements in experimental formatter in #1297 and the experimental formatter can access to grammar information when https://github.com/redhat-developer/vscode-xml/blob/main/docs/Formatting.md#xmlformatgrammarawareformatting i sset to true.

@JessicaJHee once #1297 will be merged, I think it could be interesting to use grammar information like it is done for format element category at https://github.com/eclipse/lemminx/blob/f4d00267bb82221eb3b8d281b616d467940d8d36/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/contentmodel/participants/ContentModelFormatterParticipant.java#L50

The idea is to check if the element to format can be format to empty element according the XSD/DTD constraints by using https://github.com/eclipse/lemminx/blob/f4d00267bb82221eb3b8d281b616d467940d8d36/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/xsd/contentmodel/CMXSDElementDeclaration.java#L461

@angelozerr angelozerr changed the title Auto Tag Close formatting xml.format.emptyElements should respect grammar constraint Sep 21, 2022
@angelozerr angelozerr removed their assignment Sep 21, 2022
@JessicaJHee JessicaJHee self-assigned this Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request formatting This issue or enhancement is related to formatting support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants