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

Incorrect indentation with data declaration #97

Open
centromere opened this issue May 15, 2017 · 15 comments
Open

Incorrect indentation with data declaration #97

centromere opened this issue May 15, 2017 · 15 comments

Comments

@centromere
Copy link

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.

@cdepillabout
Copy link

I'm seeing this behavior too.

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

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

@cdepillabout
Copy link

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.

@raichoo
Copy link
Member

raichoo commented Sep 29, 2017

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

@cdepillabout
Copy link

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.

@raichoo
Copy link
Member

raichoo commented Sep 30, 2017

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.

@cdepillabout
Copy link

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.

@codedmart
Copy link

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

@codedmart
Copy link

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

@cdepillabout
Copy link

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

@codedmart
Copy link

codedmart commented Oct 24, 2017

@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.

@qwfy
Copy link

qwfy commented Jan 11, 2018

@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.

@cdepillabout
Copy link

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
Copy link

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
Copy link

I believe that the offending code is the following:

" { foo :: Int
" >>,
"
" |
" ...
" >>,
if l:line =~ '^\s*,'
if s:isInBlock(s:getHLStack(line('.'), col('.')))
normal! 0
call search(',', 'cW')
let l:n = s:getNesting(s:getHLStack(line('.'), col('.')))
call search('[([{]', 'bW')
let l:cl = line('.')
let l:cc = col('.')
while l:n != s:getNesting(s:getHLStack(l:cl, l:cc)) || s:isSYN('haskellString', l:cl, l:cc) || s:isSYN('haskellChar', l:cl, l:cc)
call search('[([{]', 'bW')
let l:cl = line('.')
let l:cc = col('.')
endwhile
return l:cc - 1
else
let l:s = s:indentGuard(match(l:line, ','), l:prevline)
if l:s > -1
return l:s
end
endif
endif

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

@intercalations
Copy link

Commenting out these lines fixes this for me:

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

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

6 participants