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

Format XML split attributes with closing tag on new line #435

Closed
ecool opened this issue Mar 9, 2021 · 8 comments · Fixed by eclipse-lemminx/lemminx#1051
Closed

Format XML split attributes with closing tag on new line #435

ecool opened this issue Mar 9, 2021 · 8 comments · Fixed by eclipse-lemminx/lemminx#1051
Assignees
Labels
enhancement New feature or request formatting good first issue Good for newcomers

Comments

@ecool
Copy link

ecool commented Mar 9, 2021

When working in vscode, I like to use the Alt+Up and Alt+Down keybinding for moving stuff around, and allowing for the ending of the tag to be on a new line if the attributes are aligned would be very helpful.

current:

<tag
    attr1=""
    attr2="" />

<tag
    attr1=""
    attr2="" >

proposed:

<tag
    attr1=""
    attr2=""
/>

<tag
    attr1=""
    attr2=""
>

proposed setting:
xml.format.splitAttributesCloseNewLine = true - only use if xml.format.splitAttributes = true.

@datho7561 datho7561 added enhancement New feature or request formatting labels Mar 11, 2021
@angelozerr
Copy link
Contributor

@fbricon what do you think about this format settings?

@datho7561 do you think it can be easy to implement it?

@datho7561
Copy link
Contributor

Its not trivial to implement, since you need to take into account > and />, but it looks fairly straightforward.

@datho7561
Copy link
Contributor

Also, we would need to decide how formatting with just one attribute is handled

@ecool
Copy link
Author

ecool commented Mar 16, 2021

@datho7561 it looks like the current setting for splitAttributes keeps a single attribute on the line with the tag.

<tag attr1="" />

So, current behavior seems to be only split when more than 1 attribute. Not sure if there should be another setting for a single attribute decision but it does counteract the main reason I was looking into having the ending of the tag be on a new line. (The easy movement/duplication of attribute lines with vscode shortcuts)

If following the understanding of making it easier to manage attributes with the shortcuts (including all line operations), I believe there should be a way to have a single attribute being split to a separate line as well.

@datho7561 datho7561 added the good first issue Good for newcomers label Mar 19, 2021
@thet
Copy link

thet commented May 6, 2021

Format suggestion: Indent the closing part the same level the attributes are indented:

<tag
    attr1=""
    attr2=""
    />

<tag
    attr1=""
    attr2=""
    >

This follows the Zope's toolkit ZCML style guide: https://zopetoolkit.readthedocs.io/en/latest/codingstyle/zcml-style.html#opening-tags
And it looks a bit nicer, IMO.

@AlexXuChen
Copy link
Contributor

I'm interested in taking this issue.

@angelozerr
Copy link
Contributor

Before working on this issue, perhaps we should rewrite the XML formatter (see PR eclipse-lemminx/lemminx#1044)

@datho7561 what do you think about that?

@datho7561
Copy link
Contributor

I think the formatter rewrite will take a while. In the mean time, it would be neat to support this feature. It shouldn't require many changes to the existing formatter to implement this feature.

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 good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants