haskell-vim icon indicating copy to clipboard operation
haskell-vim copied to clipboard

Incorrect indentation with data declaration

Open centromere opened this issue 7 years ago • 15 comments

If I start with this file:

screenshot from 2017-05-15 00-00-49

And I hit <Enter>, <Comma>, <Space>, I get this:

screenshot from 2017-05-15 00-01-32

However, I was expecting to get this:

screenshot from 2017-05-15 00-07-17

This does not seem correct. I have confirmed that if I remove the Plug 'neovimhaskell/haskell-vim' line from my .vimrc file, the problem does not exist.

centromere avatar May 15 '17 04:05 centromere

I'm seeing this behavior too.

I git bisected it and it appears to be caused by commit e6937cb8fbb95c.

For the time being, using haskell-vim at commit 27cbc4b758f5 (which is the direct parent of commit e6937cb8fb) appears to mitigate this problem.

cdepillabout avatar Sep 29 '17 14:09 cdepillabout

Hmm, using commit 27cbc4b seems to have some problems of its own.

Also, it looks like @raichoo is collecting bad examples of indentation at #73. The information on this thread can probably be moved to there. Then this thread can be closed.

cdepillabout avatar Sep 29 '17 14:09 cdepillabout

I currently can't reproduce this with recent neovim and my setup (which is pretty minimal in terms of plugins).

raichoo avatar Sep 29 '17 18:09 raichoo

I'm currently using haskell-vim in regular vim, not neovim.

I haven't tested in neovim, but I'm guessing that there is some difference in how either the indentation stuff works, or the results of the vim-provided built-in functions.

cdepillabout avatar Sep 30 '17 02:09 cdepillabout

My usual guess is that some other plugin might be interfering. It sort of became a reflex to think that but it happened to be the case surprisingly often.

raichoo avatar Sep 30 '17 14:09 raichoo

Thanks for the tip! I'll have to try disabling some of my other haskell-related plugins and see if I can determine which one is to blame.

cdepillabout avatar Sep 30 '17 15:09 cdepillabout

@cdepillabout Did you ever pinpoint what it was. I am seeing this behavior in neovim.

codedmart avatar Oct 16 '17 20:10 codedmart

@raichoo Also similar to @centromere if I remove Plug 'neovimhaskell/haskell-vim' then I see the expected indentation.

codedmart avatar Oct 16 '17 20:10 codedmart

@codedmart Sorry, I haven't had time yet to try to pinpoint the reason.

cdepillabout avatar Oct 17 '17 02:10 cdepillabout

@raichoo Any guess as to what would be interfering? With 'neovimhaskell/haskell-vim' I see the indentation issue. Without 'neovimhaskell/haskell-vim' I don't see the issue anymore.

codedmart avatar Oct 24 '17 13:10 codedmart

@codedmart I'm using neovim v0.2.2 and able to get rid of this problem with

autocmd FileType haskell :setlocal nosmartindent

don't know whether or not this will introduce other problems though.

qwfy avatar Jan 11 '18 16:01 qwfy

I've played around with this and it seems like the culprit is probably haskell-vim. I've tried disabling all my other plugins, as well as most of my other vim options, and nothing fixes this.

However, if I disable haskell-vim and just use the normal indentation for vim from Haskell, indentation works correctly. I'm going to look at the haskell-vim source code and try to figure out what is going wrong.

cdepillabout avatar Nov 15 '18 14:11 cdepillabout

I've also now tried neovim, and it seems like the problem doesn't improve.

Just to make sure we're all on the same page, here is a complete description of the problem I am seeing:

  1. Imagine I am writing a data declaration. I start by writing something like the following:

    data Foobar = Foobar
      { foo :: Int
    

    My cursor is right after the t in Int.

  2. Here, I press enter to go to the next line. The cursor is correctly lined up under the open bracket {:

    data Foobar = Foobar
      { foo :: Int
      _
    
  3. From here, I press , to insert a comma, and then space. Right after I press space, haskell-vim changes the indentation to the following:

    data Foobar = Foobar
      { foo :: Int
        , _
    

    You can see that the comma has been indented two spaces when it should not be.

  4. If you manually go in and de-dent the comma, then when you go to the next line it will be indented correctly.

    For example, if I have the following:

    data Foobar = Foobar
      { foo :: Int
      , bar :: Char_
    

    My cursor is right after the r in Char. If I press enter here, the next line will be indented correctly. It will not do an extra indent after pressing ,.

The above problem also happens with any sort of tuple, lists, etc.

cdepillabout avatar Nov 16 '18 03:11 cdepillabout

I believe that the offending code is the following:

https://github.com/neovimhaskell/haskell-vim/blob/b1ac46807835423c4a4dd063df6d5b613d89c731/indent/haskell.vim#L160-L188

My guess is that this somehow plays poorly with autoindent (which I have on).

cdepillabout avatar Nov 16 '18 03:11 cdepillabout

Commenting out these lines fixes this for me:

https://github.com/neovimhaskell/haskell-vim/blob/master/indent/haskell.vim#L182-L186

intercalations avatar Apr 24 '22 12:04 intercalations