JuliaEditorSupport / julia-vim

Vim support for Julia.
http://julialang.org/
Other
752 stars 94 forks source link

`ij` text object incorrect for multi-line signatures and single-line blocks #286

Open nick4f42 opened 2 years ago

nick4f42 commented 2 years ago

The ij text object includes some of a function signature if it spans multiple lines:

julia-vim-ij

It doesn't select anything if the entire block is on one line, like this:

if foo println(2) end
carlobaldassi commented 2 years ago

I have just pushed a fix for the issue in the first example. Unfortunately, fixing the one-line blocks and other cases is very, very hard. That's because that basically requires a full-fledged julia code parser. Examples of things that still create problems after the fix:

  1. Lines that continue due to a dangling operator, e.g.
    if x + y ==
       z + k
        println("yes")
    end
  2. Code that comes in the same line after the block header, e.g.
    if x == z + k println("yes")
        return
    end

In order to deal with those correctly, we'd need a parser that can tell when an expression is completed. Doing it with brackets is not too hard, but when the tokens that determine the parsing are in the middle (like for binary operators) and there is whitespace dependency (e.g. a [3] is not the same as a[3] in this context) then things become very complicated to implement in vim script. It might be doable by leveraging syntax highlighting (as we do with brackets) but that would likely make the syntax highlighting even more horribly slow than it is already.

nick4f42 commented 2 years ago

Thanks for the quick fix! For completeness, I'll give another example I found that still doesn't work:

  1. When the where statement of a function is on a different line, it's included in ij
    function f(
        x::T
    ) where T
    return T
    end