vuejs / vetur

Vue tooling for VS Code.
https://vuejs.github.io/vetur/
MIT License
5.75k stars 593 forks source link

Auto indent does not work #1067

Open tsewaiho opened 5 years ago

tsewaiho commented 5 years ago

Info

Problem

Auto indent does not work. I googled about this issue for many times, but I cannot find a solution, can't even find a discussion about this issue.

Reproducible Case

copy
1

result 2

Description

I thought auto indent should work out of the box but it bothered me for long time.

Currently, I am relying on formatOnSave to correct the indentation.

Discovery

  1. Atom does not have this issue. Sublime works a little bit tricky, it's auto indent is run 1 second after paste, but at least it is correct.
  2. If I manually change the language mode from Vue to HTML on VSCode, auto indent works. 3
  3. I guess that auto indent is implement by something like that. But I cannot find one in Vetur source code.
    languages.setLanguageConfiguration('html', {
        indentationRules: {
            increaseIndentPattern: /<(?!\?|(?:area|base|br|col|frame|hr|html|img|input|link|meta|param)\b|[^>]*\/>)([-_\.A-Za-z0-9]+)(?=\s|>)\b[^>]*>(?!.*<\/\1>)|<!--(?!.*-->)|\{[^}"']*$/,
            decreaseIndentPattern: /^\s*(<\/(?!html)[-_\.A-Za-z0-9]+\b[^>]*>|-->|\})/
        },
herrernst commented 5 years ago

It would be nice if auto indent on paste would work out of the box.

simongcc commented 3 years ago

Would like to know if Auto Indent by moving up and down the code belongs to feature requests? When I switch the doc type to HTML, Javascript, CSS/SCSS, the move up and down of the code will be indented automatically. Does it a feature belongs to extension of builtin nature of vscode?

What could we help to implement or enhance Vetur? Many thanks.

yoyo930021 commented 3 years ago

If anyone can help, we welcome any PR. I have briefly researched this issue. The above setting is difficult for us to use in multiple languages in one file.

This link may also be helpful. https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_onTypeFormatting