Skip to content

Improved auto-indent breaks Allman style indent #29390

Closed

Description

@Gama11
  • VSCode Version: Code - Insiders 1.14.0-insider (779a7df, 2017-06-23T05:59:57.891Z)
  • OS Version: Windows_NT ia32 10.0.15063

While working on adding support for the improved auto-indent mentioned here to the Haxe extension, I noticed it doesn't work well with Allman bracket style ({ in new line). This is the behavior for both TS and JS:

The expected behavior would be to un-indent again when the { is typed, take Sublime for example:

The Reindent lines command also produces incorrect indentation for lines that are already typed:

Activity

  1. rebornix commented on Jun 26, 2017

    @rebornix
    Contributor

    Jens Fischer (@Gama11) We added indentNextLinePattern: /^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$)/ which means anyline matches such rule will only indent next line. Then we can support below case in JavaScript

    if (true)
      if (true)
        if (true)
          console.log('a')
    
    console.log('b')
    

    If you want to have Allman bracket style support in an extension, you may want to remove this case from indentNextLinePattern rule.

  2. rebornix commented on Jun 26, 2017

    @rebornix
    Contributor

    The reindent one is a bug.

  3. added
    *question
    under-discussion
    on Jun 26, 2017
  4. Gama11 commented on Jun 26, 2017

    @Gama11
    ContributorAuthor

    Peng Lyu (@rebornix) It seems it should be possible to support both. You'd have to remove the indent from indentNextLinePattern again when a { is typed in a new line, like Sublime does in the .gif I included. IntelliJ also handles this well:

  5. rebornix commented on Jun 26, 2017

    @rebornix
    Contributor

    Jens Fischer (@Gama11) I reconsidered it, it's a valid feature request :) Thanks for all the info.

  6. added
    feature-request
    and removed
    *question
    under-discussion
    on Jun 26, 2017
  7. Gama11 commented on Jun 26, 2017

    @Gama11
    ContributorAuthor

    Peng Lyu (@rebornix) Thanks! This is probably not much of an issue for TS / JS, but for other C-Style languages (Java, C#...), Allman Style is fairly common.

  8. aclarkxyz commented on Jul 13, 2017

    @aclarkxyz

    Please fix: VSCode was a great editor until this bug slipped in; this may seem like a minor thing, but it's really not...

  9. aclarkxyz commented on Jul 13, 2017

    @aclarkxyz

    Quicky fix hack seems to work: (on Mac) edit the file "~/Applications/Visual Studio Code.app//Contents/Resources/app/extensions/typescript/out/typescriptMain.js", comment out these two lines:

                    //increaseIndentPattern: /^.*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/,
                    //indentNextLinePattern: /^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$)/
    

    A semblance of sanity appears to be restored.

  10. 1 remaining item

  11. Gama11 commented on Aug 9, 2017

    @Gama11
    ContributorAuthor

    Peng Lyu (@rebornix) Missing editor-indentation label? :)

  12. davidstlyoui commented on Aug 10, 2017

    @davidstlyoui

    just got 1.15 update... unfortunately this bug is still there...
    The editor is barely usable with this bug! Can we boost priority on this somehow?
    I'll try Alex Clark (@aclarkxyz) hack for now

  13. davidstlyoui commented on Aug 10, 2017

    @davidstlyoui

    Also this issue is wrongly marked as "Feature Request".
    This is a regression bug, not a feature request.

  14. coderas commented on Aug 23, 2017

    @coderas

    definitely a regression bug, I'm am seeing this break formats on paste too. Used to work beautifully.

  15. captainparticles commented on Sep 27, 2017

    @captainparticles

    I'm seeing this bug on cpp files. Same issue as described by op. Any fix inbound, or a workaround in the meantime?

  16. captainparticles commented on Sep 27, 2017

    @captainparticles

    fyi setting increaseIndentPattern and decreaseIndentPattern to "" in language-configuration.json for cpp and setting "editor.autoindent" to true restored the pre-1.14 behavior. This is the desired behavior.

  17. added
    bug
    and removed
    feature-request
    on Dec 1, 2017
  18. rebornix commented on Dec 1, 2017

    @rebornix
    Contributor

    Jens Fischer (@Gama11) for this particular issue, we already removed indentation rules for Allman bracket style, then now pressing enter after ) will not add indentation.

    Feel free to open new issues for other unexpected behaviors, or you can disable the auto-indent by editor.autoIndent as one set of indentation rules won't work for everyone.

  19. Gama11 commented on Dec 1, 2017

    @Gama11
    ContributorAuthor

    So there's no plans for getting auto-indentation on par with Sublime's / IntelliJ's behavior shown in the .gifs? Just removing the feature altogether (for this case) doesn't seem like a great solution...

  20. locked and limited conversation to collaborators on Jan 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugeditor-autoindent

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions