Incorrect indentation of multi-line values in lists #83

Open
garybernhardt opened this Issue May 18, 2012 · 3 comments

Projects

None yet

2 participants

@garybernhardt

As of current master, 4cf6a00, vim-ruby indents this way:

    [1, [2,
         3],
         4]

but I expect it to indent this way:

    [1, [2,
         3],
     4]

It also indents hashes and function calls incorrectly in the same way:

    [1, {2 =>
         3},
           4]
    [1, f(2,
          3),
          4]

The hash case shows slightly different spacing, but these all seem to be linked.

@garybernhardt

This seems to happen when the list is inside a function as well. For example:

    f(
      [1,
       2],
       [3,
        4]
    )

It looks like any list of things inside any other list of things breaks when spanning multiple lines.

@AndrewRadev
Vim-Ruby member

From what I gather, there is currently no code in place that handles closing brackets on the same line as code. Basically, this indents correctly:

foo = [
  1
]
# something

But, as you noticed, this doesn't:

foo = [
  1]
# something

I couldn't find a good way to "extend" the bracket-related logic, so I implemented it separately and put it in the closing-brackets branch. It's very rough and should break for a bunch of edge cases, but it seems to indent all of the given examples correctly. It also fixes issue #81. I'll try to find some time to work on a better solution this weekend.

Incidentally, if you find some cases that don't indent correctly with this solution, please let me know, it would help with testing.

@AndrewRadev
Vim-Ruby member

I'll try to find some time to work on a better solution this weekend.

Well, I couldn't find the time that weekend...

Apologies for taking so long to get around to this (again). The good news is, I solved issue #81. The bad news is that this problem turns out to be quite different.

The solution for the mis-indented line after the closing bracket was to extend the s:FindRightmostOpenBracket function to store hanging closing brackets as it goes through the line and then return those as well. I've renamed it to s:ExtraBrackets. I have an idea how I can change it a bit to make it more compact, but I'll see about that.

The issue with the closing bracket line itself, on the other hand, is an issue of continuations.

[1, [2,
     3],
     4,
     5]

In this case, the problem is not the 5], it's the 4,. That line looks for an MSL upwards and finds [1, [2,. The 3] line does the same and finds that same MSL: [1, 2,. Hence, they are indented the same way... Should've realized that a long time ago, really.

@garybernhardt, to you, the important part is that issue #81 should be solved, but this one is still open. If you find any problems or regressions on #81, consider either writing here or reopening it. I'll try to think of a way to tackle this problem, although I honestly haven't the faintest idea right now. Hopefully, it'll take me less than 5 months to figure something out this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment