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

Odd comment indentation behavior #4

Closed
glacials opened this issue Jul 12, 2017 · 5 comments
Closed

Odd comment indentation behavior #4

glacials opened this issue Jul 12, 2017 · 5 comments
Assignees

Comments

@glacials
Copy link

Hiya, this is a great plugin that's been very helpful! I've run into an indentation quirk recently that doesn't seem intended. Steps to repro:

  1. Set these Vim options:

    set smartindent
    set tabstop=2
    set softtabstop=2
    set shiftwidth=2
    set expandtab
  2. Make a user.graphql file with some contents like

    type User {
      name: String
      email: String
    }
  3. Place your cursor on the first line and press o to insert a new line. You'll see something like this:

    type User {
      <CURSOR>
      name: String
      email: String
    }
  4. Now start a comment by pressing #. I expect to see this:

    type User {
      #<CURSOR>
      name: String
      email: String
    }

    But instead I see this:

    type User {
    #<CURSOR>
      name: String
      email: String
    }

Additionally, when I try to indent the comment line with >>, nothing happens.

It seems Vim wants to force me to use no indentation for all comments, but I don't see any places in the GraphQL spec (or any style guides anywhere) that mention this behavior.

I'm using Neovim 0.2.0 if it helps.

@jparise
Copy link
Owner

jparise commented Jul 13, 2017

I can reproduce this and will look into it soon. Thanks for the bug report!

@jparise jparise self-assigned this Jul 13, 2017
@jparise
Copy link
Owner

jparise commented Jul 13, 2017

This appears to be :smartindent's default behavior:

When typing '#' as the first character in a new line, the indent for
that line is removed, the '#' is put in the first column. The indent
is restored for the next line. If you don't want this, use this
mapping: ":inoremap # X^H#", where ^H is entered with CTRL-V CTRL-H.
When using the ">>" command, lines starting with '#' are not shifted
right.

I'll have to consider whether this is something that should be changed / overridden by this plugin, perhaps by implementing our own indent rules, although I'm also reluctant to make things too complex for this case.

@jparise
Copy link
Owner

jparise commented Jul 30, 2017

I'm still thinking about whether the plugin should set inoremap # X<c-h>#<space> itself for GraphQL buffers (perhaps with a global option to disable the mapping). That would appear to be the expected behavior in all cases, but I also have some misgivings about overriding vim behavior in a filetype-specific plugin.

@jparise
Copy link
Owner

jparise commented Jul 30, 2017

I decided to just implement my own indentation rules that supersede smartindent. It's a pretty simple implementation, and it specifically addresses the comment behavior described by this issue, but please let me know if there are cases I'm not covering correctly.

@glacials
Copy link
Author

Thank you @jparise, will do!

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

No branches or pull requests

2 participants