lukas-reineke / indent-blankline.nvim

Indent guides for Neovim
MIT License
4.16k stars 102 forks source link

C scope highlight problem with newlines in if statements #766

Closed Danielkonge closed 11 months ago

Danielkonge commented 11 months ago

Problem

Scope highlighting doesn't have the expected behavior with certain formatting styles.

This is the expected behavior:

Screenshot 2023-11-08 at 16 54 42 Screenshot 2023-11-08 at 16 57 07 Screenshot 2023-11-08 at 16 57 23

I think these are also all okay, but I am not sure about the exact scopes here:

Screenshot 2023-11-08 at 16 53 51 Screenshot 2023-11-08 at 16 54 11 Screenshot 2023-11-08 at 16 54 19 Screenshot 2023-11-08 at 16 54 33

This is wrong:

Screenshot 2023-11-08 at 16 54 25

As shown in the first few pictures, this highlighting can be fixed by changing the formatting a bit, but hopefully the code should still work correctly in this case.

Steps to reproduce

nvim --clean -u min-init.lua keeps giving errors when I run it with the minimal config file, so I don't have the minimal config, but I don't think the issue is hard to reproduce.

Make a c file with:

int main(int arg1,
         char **arg2,
         char **arg3
         )
{
  if (arg1 == 4
    && arg2 == arg3) {
    int tmp = 1;
    // comment
  } else {
    int tmp  = 2;
    // comment
  }
}

Move the cursor around different lines and look at the scope highlights.

Expected behavior

Screenshot 2023-11-08 at 16 54 25

In this picture the scope should highlight the second indentation guide to the left of the cursor.

Neovim version (nvim -v)

NVIM v0.10.0-dev-1451+g20dd9f3a2-Homebrew

lukas-reineke commented 11 months ago

Isn't this just a duplicate of #752

Danielkonge commented 11 months ago

I didn't think it was the same problem because the indent guides looked different, but looking at it again I think that is just because of smart_cap_indent. I think you are right that this is a duplicate, so I will close this issue and make a comment in the other issue instead. I think I might have a way to solve this after current_indent is committed (I would use that the calculation loop and drawing loop are different then).