jwalton512 / vim-blade

Vim syntax highlighting for Blade templates.
225 stars 37 forks source link

Line outdents when using -> inside Blade tag #58

Closed RyanDwyer closed 7 years ago

RyanDwyer commented 7 years ago

Example file (named test.blade.php):

<div>
    |
</div>

Pipe shows where to position the cursor. In insert mode, type: {{ $foo->

Upon hitting the > key, the line will outdent.

I'm using the latest version of NeoVim and vim-blade on Arch Linux. The ft is indeed blade and I don't think there's anything in my config which could be messing with this.

jwalton512 commented 7 years ago

Hi @RyanDwyer I can't seem to duplicate. My setup is similar, except using macOS (iterm).

Below is what happens for me. gif

RyanDwyer commented 7 years ago

The bug doesn't occur if I press tab in the same insertion as the Blade tag as you did. It should happen if you hit tab, escape, a, then the rest.

Also, I can't replicate the bug in regular vim 8. It seems to be specific to nvim.

I've replicated the bug with a minimal nvim configuration which only loads your plugin, so I'm confident it's nothing I've done.

I noticed that even with a minimal configuration, when I press O on the closing div tag it indents for me automatically. In your gif it looks like you're pressing O and it doesn't indent automatically. Could mine be loading some kind of HTML indent rules file? I'm guessing nvim is detecting ">" as being the ending of a HTML tag and tries to adjust the indent.

My nvim -v shows I'm running nvim 0.1.6 and that files are loaded from /usr/share/nvim. Maybe the issue is in there.

RyanDwyer commented 7 years ago

I've bisected this to the following commit:

commit 4dfe3c8f54f0d90a34164835d63ef0cdbdb18290
Author: Adriaan Zonnenberg <info@adriaan.xyz>
Date:   Tue Jun 21 12:44:25 2016 +0200

    Fix indentation for multiline PHP blocks

    Also added some tests for multiline PHP blocks

If I open indent/blade.vim and remove this line (line 58) it fixes my problem:

\ searchpair('{{', '', '}}', 'bWr') ||

I think it's trying to cater for cases where a Blade tag spans multiple lines and adjusts the indent accordingly, but fails to handle cases where the Blade tag is on the same line.

@adriaanzon Thoughts?

adriaanzon commented 7 years ago

This happens to me too. What's weird is that it only happens in insert mode: when I return to normal mode and press ==, the indentation returns to normal.

After some investigation I saw the problem disappear when I removed these lines. Because of these lines, the indentexpr from PHP doesn't pass when it returns -1. However, -1 is a meaningful value (read :h 'indentexpr').

But we can't simply remove those lines because here, the indentation is added up to the value of PHP's indentexpr. So if we remove those lines and there is a situation where PHP's indent returns -1 and the next line should be increased, you end up with an invalid value: 3 (-1 + 4 = 3), assuming your 'shiftwidth' is set to 4.

Anyway, this file looks like it can use some refactoring, so I will look into it then.