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

Depend on js-beautify directly #82

Closed
octref opened this issue Mar 6, 2017 · 23 comments
Closed

Depend on js-beautify directly #82

octref opened this issue Mar 6, 2017 · 23 comments

Comments

@octref
Copy link
Member

octref commented Mar 6, 2017

vscode-html-languageservice depends on js-beautify directly. However, it's not aware of scss, less regions. It's also causing problems like #77.

js-beautify actually supports scss and less, so vetur will just depend on it directly.

Overall:

  • html/css/scss/less/js formatting will be supported using js-beautify
  • Have a default setting for each supported languages, but also expose settings passing to js-beautify, for example:
    • "vetur.vue-html.format.config": ".htmlbeautifyrc"
    • "vetur.css.format.config": ".cssbeautifyrc"
    • "vetur.js.format.config": ".jsbeautifyrc"
  • Other languages don't have any reliable formatters yet, so just disable them all
  • If someone is interested in having formatting for a specific language, open a new issue with link to an actively maintained formatter
@octref
Copy link
Member Author

octref commented Mar 6, 2017

Will use https://github.com/mrmlnc/vscode-pugbeautify for jade/pug.

@beeplin
Copy link

beeplin commented Mar 6, 2017

wonderful~! waiting for the new version~~

@octref
Copy link
Member Author

octref commented Mar 6, 2017

Formatters are temporarily disabled until this feature is addressed.

@zema1
Copy link

zema1 commented Mar 9, 2017

Looking forward to the new version..
I really need the formatter..

@zengyiqun
Copy link

I really need the formatter too !~~~~

@sebastianmacias
Copy link

+1

@christianmalek
Copy link

christianmalek commented Mar 13, 2017

@octref Couldn't you just disable the formatter per default and make it accessible per workspace settings? I don't think that the added new lines are such a big problem. Maybe just add it as "experimental" feature.

@rafaberaldo
Copy link

It was working fine for basic setups, wasn't it? Would like to see it enabled back.

@octref
Copy link
Member Author

octref commented Mar 13, 2017

This is top on my list. Give me a day or two to work on it.

@octref
Copy link
Member Author

octref commented Mar 14, 2017

So here is how it goes. Notice html/css/js/scss/less are all formatted, whereas sass/stylus/pug are left alone.

format

Will add initial indentation to the template part and remove the initial indentation on js and make a release.

@octref
Copy link
Member Author

octref commented Mar 14, 2017

Stole these config from https://github.com/victorporof/Sublime-HTMLPrettify

const htmlOptions = {
  brace_style: 'collapse', // [collapse|expand|end-expand|none] Put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line, or attempt to keep them where they are
  end_with_newline: false, // End output with newline
  indent_char: ' ', // Indentation character
  indent_handlebars: false, // e.g. {{#foo}}, {{/foo}}
  indent_inner_html: false, // Indent <head> and <body> sections
  indent_scripts: 'keep', // [keep|separate|normal]
  indent_size: 2, // Indentation size
  max_preserve_newlines: 0, // Maximum number of line breaks to be preserved in one chunk (0 disables)
  preserve_newlines: true, // Whether existing line breaks before elements should be preserved (only works before elements, not inside tags or for text)
  unformatted: ['a', 'span', 'img', 'code', 'pre', 'sub', 'sup', 'em', 'strong', 'b', 'i', 'u', 'strike', 'big', 'small', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'], // List of tags that should not be reformatted
  wrap_line_length: 0 // Lines should wrap at next opportunity after this number of characters (0 disables)
};

const cssOptions = {
  end_with_newline: false, // End output with newline
  indent_char: ' ', // Indentation character
  indent_size: 2, // Indentation size
  newline_between_rules: true, // Add a new line after every css rule
  selector_separator: ' ',
  selector_separator_newline: true // Separate selectors with newline or not (e.g. 'a,\nbr' or 'a, br')
};

These will be used as initial default, let me know what you agree & don't agree with. (Indentation size & char is read from VSCode config).
I'll add capability to specify your own js-beautify config later.

@octref
Copy link
Member Author

octref commented Mar 16, 2017

Check out 0.5.3 and let me know how it works.

Still yet to be done:

  • allow to specify own options
  • pug formatter

@beeplin
Copy link

beeplin commented Mar 16, 2017

pressing shift-alt-f for multiple times will increase the indentation of html <!-- --> comments:
image
became
image
and became
image

@octref
Copy link
Member Author

octref commented Mar 16, 2017

0.5.4 preserves new lines for html, and uses force-aligned to align attributes as @beeplin suggested in #77

Before:
image

After:
image

Seems css/scss/less preserve new lines option is being added this weekend, beautifier/js-beautify#1146

I'll add it once it lands in js-beautify.

@beeplin
Copy link

beeplin commented Mar 16, 2017

v0.5.4 is wonderful :)

@octref
Copy link
Member Author

octref commented Mar 20, 2017

0.5.6 brings CSS preserve_newlines from js-beautify, and is set as default:

format2

@danikane
Copy link

danikane commented Mar 20, 2017

Thanks to @beeplin for submitting the bug, but please, please, please @octref find a way to be able to specify:
"html.format.wrapAttributes": "auto"
as you mentioned previously in this thread (allow to specify own options).
Thank you for your work!

@octref
Copy link
Member Author

octref commented Mar 21, 2017

@danikane Will do soon.

@octref
Copy link
Member Author

octref commented Apr 17, 2017

@danikane This is already in master so closing. Also auto is set as default but people can set wrap_attributes to force-aligned if they want. Will be available in 0.6.

@octref octref closed this as completed Apr 17, 2017
@danikane
Copy link

Many thanks!

@x8x
Copy link

x8x commented Nov 9, 2017

@octref Any news on status of pugbeautify integration?

@octref
Copy link
Member Author

octref commented Nov 9, 2017

@x8x I forgot that. You can track #527.

@x8x
Copy link

x8x commented Nov 9, 2017

@octref Amazing! Thx! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants